teleren/devto huggingface dataset:
Typeclass(Interface) is Kernel Concept of Haskell Functor, Monad These Weird
Tags: haskell, typeclass
Published: 2019-01-26 09:35:53

---
title: Typeclass(Interface) is Kernel Concept of Haskell Functor, Monad These Weird
published: true
description: 
tags: haskell, typeclass
---

In short, typeclass is just like interface, so it's not so hard to understand.

Let's see some code about Maybe functor, functor has a special map function:

```haskell
class Functor Maybe where
    fmap :: (a -> b) -> Maybe a -> Maybe b

instance Functor Maybe where
    fmap func (Just x) = Just (func x)
    fmap func Nothing  = Nothing

```

Functor is a typeclass.
Applicative Functor extends Functor.
Monad extends Applicative.

```haskell
class Applicative m => Monad m where
    return :: a -> m a
    (>>=) :: m a -> (a -> m b) -> m b
```

And another one Monoid is a math concept. It's a typeclass too.

They are all typeclasses.

# ref

![](http://blog.leichunfeng.com/images/recap.png)
[Functor、Applicative 和 Monad(Chinese)](http://blog.leichunfeng.com/blog/2015/11/08/functor-applicative-and-monad/)

[Learn You a Haskell for Great Good!](http://learnyouahaskell.com/)

{% link https://dev.to/nestedsoftware/book-notes-learn-you-a-haskell-for-great-good-2cnp %}
Software Design Through TDD
Tags: tdd
Published: 2019-01-26 05:06:41

---
title: Software Design Through TDD
published: true
description: 
tags: tdd
---

In my last post Beyond Static Typing, I dropped a bomb shell at the end and invented the ideology Design by Runs at Compile Time. But I didn't really dive into my proceived issues with TDD.

There is a [laundry list af benefits](https://apiumhub.com/tech-blog-barcelona/advantages-of-test-driven-development/). But that list doesn't even mention that it helps in making testable code. Did you know that if you want to write tests which validates logic without dependency you build a design different than if you just integrate directly?

Now this does not sound like a bad thing. Especially when coupled all those documenting tests which allow you to understand the desired behavior and throw out the code, rewriting it based on the tests alone. Not that anyone expects that to happen or be useful.

To remove dependency can require layers of abstraction, also a good thing. Abstraction can lead to boilerplate and worse obfuscation. [TDD is about design] (https://blog.jbrains.ca/permalink/tdd-isnt-about-testing-revisited), but it doesn't force or check for good design.

Consider the ideal, you'd define a scenario, given some situation and you are in a state when a request comes in then you would specify the desired outcome. The compiler would figure out how to get those elements to line up and build your program. This is the logic paradigm or machine learning. As programmers we don't get to write code at this level because we write the code to let others work at this level.

This means we have to balance the abstractions we use to expand code reuse (for bug fix and prevention) while maintaining enough info about what the computer is doing in order to find and fix bugs.

This is where TDD puts test readability above code readability incorrectly. Unit tests will help confidence that a refractor won't break behavior but it won't tell you where a bug is when you need to track one down, reading the code, possibly with the help of debuggers, will.

I'm not going claim anyone will be able to write universally readable code across all domains for every situation. But obfuscation of process to achieve testability is detrimental to code verification. I'm reading your code to find those edge cases and inconsistencies you missed, make it easy on me and your future self.

If you want to have well designed code, it falls on you to determine your audience, your domain, and so many more factors about the specific feature you're implementing amongst the existing code base.
My trip to Kazan, Russia
Tags: travel, cybersecurity, reflection
Published: 2019-01-26 03:50:58

---
title: My trip to Kazan, Russia
published: true
tags: ["travel", "cybersecurity", "reflection"]
---

![Banner](https://thepracticaldev.s3.amazonaws.com/i/0k60iu3l4k8elf0kjikj.jpg)

Just over a month ago, I travelled to Kazan, Russia, to take part in the DigitalSkills 2018 competition. Here are some of my reflections: [https://ravernkoh.me/posts/digital-skills-kazan-2018/](https://ravernkoh.me/posts/digital-skills-kazan-2018/).
How to spy a process 
Tags: strace, lsof, gdb, debugging
Published: 2019-01-26 01:44:33

---
title: How to spy a process 
published: true
description: How to spy a process
tags: strace, lsof, gdb, debugging
---

Have you ever stuck with a program running for a long time or wondering what the process is doing? No worries! You are not alone, same thing happen me a lot.

Most recently I have to spy on a long running php process to figure out why/where its taking so much time.
 
Here is my approach to spy any process in linux environment.

Find out the process ID by running a [ps](https://linux.die.net/man/1/ps) command and [grep](https://linux.die.net/man/1/grep) for specific program. In my case it was a php program so I type following:
 
```
$ ps aux | grep "some_program.php"
```

Then [strace](https://linux.die.net/man/1/strace) the process. You need root access.

```
$ strace -p PID
```

Don't worry if it dumps a lot in the standard output. It trace all the system calls (`read`,`write`,`open`,`close`,`poll`,`recvfrom` etc) that the process is doing. Look for any interesting pattern.

To see which files are opened by the process you can try [lsof](https://linux.die.net/man/8/lsof) command. This helps me to figure out which file paths are used by the program.
  
```
$ lsof -p PID
```

To further debug the process try [gdb](https://linux.die.net/man/1/gdb).
First, attach the program with gdb.
 
```
$ gdb -p PID
```

Now you are in gdb shell. type cont and wait for a while. and then hit ctrl + c to stop it.
```
> cont
```

It will stop and return back to gdb shell. Now type `bt` it will dump the backtrace. I can see some php library function calls.

```
> bt
```

These few commands helps me a lot to deep dive into a process and figure out whats going on. This is specially helpful when you don't know much about the underlying codebase.


To learn more about strace check out following two articles.

* [strace zine](https://jvns.ca/blog/2015/04/14/strace-zine/) by Julia Evans
* [What is php doing](https://derickrethans.nl/what-is-php-doing.html) by Derick Rethans
Day 25: Swift macOS password manager for people who hate the cloud
Tags: macos, swift, passwordmanager, cloud
Published: 2019-01-26 00:19:05

---
title: Day 25: Swift macOS password manager for people who hate the cloud
published: true
description: Follow along as I make a 100% cloudless and 100% native password manager for macOS. That's 200% raw password managing power.
tags: macos, swift, password manager, cloud
series: Making a swift MacOS password manager for people who hate the cloud
cover_image: https://thepracticaldev.s3.amazonaws.com/i/q6r73zbfbm3mpfs98bu5.jpg
---

[<- For Day 24 go here](https://dev.to/swlkr/day-24-swift-macos-password-manager-for-people-who-hate-the-cloud-29gi)

📅 01/25/2019
🚀 [5 days until launch](https://www.producthunt.com/upcoming/all-your-passwords)
🔥 24 day streak
💰 $0.99 price (going to put in app store which only allows .99 values *sigh*)
🤑 $0 revenue
📈 0 customers
⌚️ 38 hours spent
💻 102 files changed, 249709 insertions(+), 549 deletions(-)
🏁 Today's goal: **Attempt to set up a landing page, make view screen not suck and add cmd+b, cmd+c keyboard shortcuts for copying the login and the password**

**10:39 AM**
It's really coming down to it. I'm definitely not as proud of how it's going so far, but I set a deadline and I'm not about to miss it this time. I adjusted the price accordingly. I mean would I pay $5 for this thing? No way. Would I pay a $1? That's more like it. I'll increase the price as I add more features to it post-launch. I'll also try to keep this daily thing going post-launch as well so we can all experience a quiet launch and how to get customers the hard and boring way, twitter DMs, replies, quora answers, setapp, blog posts, those kinds of things.

Also for the sake of time, I think I may just put this thing in the app store because otherwise I'd have to handle license keys or something, that sounds like it will take a lot more time that I don't have.

**1:13 PM**
Got the keyboard shortcuts working, Cmd+C copies the password after selecting the tableview row and Cmd+B copies the email if there is one or the username if there's one of those instead!

**5:17 PM**
Reached out to both (that's right, there's only 2) product hunt "ship" subscribers to see if they would want to beta test before the launch or just wanted free copies of the thing. No response yet, but you know, these things take time. Only two of the three goals completed today, but I count that as a win!

I'll be back tomorrow with more riveting product development action. I may even try to stream or record a screencast or something, you never know.
Giving Go another chance: refactoring
Tags: go, timetracking, cli
Published: 2019-01-26 00:08:01

---
title: Giving Go another chance: refactoring
published: true
description: I'm writing a simple time tracking tool and rediscovering Go at the same time.
tags: go, time tracking, cli
series: Making a time tracking tool in Go
---

In this session I wanted to add another command. I imagined I'd have to factor out some common code and put it elsewhere. So I started by duplicating a file and trying to build it. And then I had another Go WTF moment. Apparently I cannot have a variable or function with the same name in different files. That I didn't expect to run into. I guess it's kinda like in C, only there that would be a link error. But any intuition I had so far built up for this language just evaporated at this point.

I started googling around and found out that all the files in a package could be essentially treated as one single file. There's no such thing as a variable or a function local to a file. Can have many `init`s though. Anything starting with a capital letter is public and exported from the package (not file). Identifiers starting with a lowercase letter are private or hidden and are not exposed to the users of the package.

I normally refactor all the time. I move code around. I add, delete and re-add functions all the time. I rename everything constantly until I'm happy with the result. Go in general doesn't prevent this style of developing, but it makes it a bit harder by not allowing to have any unused variables or imports. The imports are easily fixed the `goimports` or `goreturns` formatting tools. The local variables have to be removed by hand. This slows down the progress for me quite a bit. I'd rather have the compiler show me a warning instead. I'd get stuff to work first and then I'd clean up the warning. Go doesn't forgive or forget.

As a result of this session I have all shared code extracted and tucked away in a separate file. I have two commands now: `in` and `out`. Things are cleaned up and are ready to be made into a great app.

Next time I start coding something more serious. Enough with the baby stuff, I'm a senior developer after all.

---

Google searches that went into getting this to work:

- go private function
- go function local to a file

---

Time spent: 35 minutes
Total time spent: 7:10 hours
Notes on TypeScript: Accessing Non Exported Component Prop Types
Tags: react, typescript, types
Published: 2019-01-25 23:01:16

---
title: Notes on TypeScript: Accessing Non Exported Component Prop Types
published: true
description: Notes on Accessing Non Exported Component Prop Types
tags: react, typescript, types
series: Notes on TypeScript
---


### Problem Definition

Sometimes we need to access some component prop types, but they have not been exported.
Then there are also cases where we would rather avoid having to export any additional types, to reduce complexity. What can developers consuming a component with non exported types do, to access these types when needed? There are different ways to achieve this with __TypeScript__, so let's see how the problem can be solved.

### Low Level Approach

One way too access non exported types is to write your own type extraction helper:

```js
type componentProps<T> = T extends
  | React.ComponentType<infer Props>
  | React.Component<infer Props>
  ? Props
  : never;
```

Let's breakdown the helper to gain a better understanding of how TypeScript can infer React component props.

`React.ComponentType` is an alias for a class or a function component and by using `infer P` we let TypeScript infer any `Props` for the `ComponentType` or a `React.Component` itself.

We then either return the inferred `Props` or `never`.
The `never` type is used to represent any value that never occurs, i.e. a function that throws an error.

By using the the `componentProps` helper, we can now access the component props.

```js
type User = {
  id: number;
  name: string;
  title: string;
  location: string;
};

const User = (props: User) => {
  return (
    <div>
      {/* ... */}
    </div>
  )
};

type ActionPropTypes = React.ComponentProps<typeof User>;

const UserWrapper = (props: ActionPropTypes) => {
  return (
    <div>
      <div>{props.name}</div>
      <User {...props} />
    </div>
  );
};

```

### Modern Approach

Interestingly we can also use the `React.ComponentProps` from React types now.
The above example could be rewritten to:

```js
type ActionPropTypes = React.ComponentProps<typeof User>;
```

### More Information

[React-TypeScript-Cheatsheet: Basic](https://github.com/sw-yx/react-typescript-cheatsheet#the-types-i-need-werent-exported)

[React-TypeScript-Cheatsheet: Advanced](https://github.com/sw-yx/react-typescript-cheatsheet/blob/master/ADVANCED.md#extracting-prop-types-of-a-component)

[Answer on Stackoverflow](https://stackoverflow.com/questions/43230765/typescript-react-access-component-property-types/50136346#50136346)



If you have any questions or feedback please leave a comment here or connect via Twitter: [A. Sharif](https://twitter.com/sharifsbeat)
Feedback on Portfolio
Tags: portfolio, feedback, help, opensource
Published: 2019-01-25 22:52:10

Hi, this year I'm trying to move from my years of working as a sysadmin over to being a web developer. I was told a portfolio/website was a good idea and so I made one.

If you have a moment can you have a look at it, https://link2twenty.github.io/, and let me know what you think and what I should change.

The source is here.

{% github https://github.com/Link2Twenty/Link2Twenty.github.io %}

Thank you.
Gem debug_helper Adds Support for Method
Tags: ruby, debugging
Published: 2019-01-25 22:42:28

---
title: Gem debug_helper Adds Support for Method
published: true
description: 
tags: #ruby #debugging
---
In Ruby gem [debug_helper](https://rubygems.org/gems/debug_helper), I have added support for class <code>Method</code>.

The documentation is at GitHub project [debug_helper](https://github.com/BurdetteLamar/debug_helper#debug-helper).
Letter to Myself Ten Years Ago
Tags: discuss, motivation, help, tips
Published: 2019-01-25 21:42:33

---
title: Letter to Myself Ten Years Ago
published: true
cover_image: https://thepracticaldev.s3.amazonaws.com/i/2euyw5dzlvsnqfgivn9n.jpg
description: Inspired by the viral 10-year challenge on social media, when people show the world what they looked like 10 years ago, I decided not to share my photos of that time.
tags: discuss, motivation, help, tips
---

Inspired by the viral 10-year challenge on social media, when people show the world what they looked like 10 years ago, I decided not to share my photos of that time.

**Why?**

Because there was nothing to be proud of. Just an overweight teenager from a small town in Ukraine, with a fixed mindset and no goals in life.

With lots of complexes, fear to make mistakes and to be judged by others. 

**And...**

With big dreams and huge ambitions to change her life at that moment.

Looking back at myself in the past, I created a list of hints which I would give her 10 years ago.

**So that!**

I want to share with you, my readers. Perhaps, this list would be helpful for you to avoid the mistakes I did.

## You are an individual

You have your opinions, your own interests, and your personality.
It doesn't matter what others think about you and what they say is better for you. You are unique. Don't compare yourself to others.

Prove yourself to yourself—not others. And follow your dreams.

## Read books

Now you have time for that and a lot of time. It will bring many benefits for you like increases verbal and writing skills, will help to articulate your thoughts and will enhance the most essential ability: problem-solving skills through training the brain to think in sequence and to link cause.

## Loneliness is priceless

Enjoy it, because in a while, in adult life you will not have that amount of time to know yourself better.

## Take care of yourself

Every day for a happier mind and body.

Your body and mind are the most valuable assets. To get through each day and succeed in life both need to be kept in good shape. You want to enjoy life and focus on goals instead of your illness.

## Avoid toxic people

This is a kind of people who might resent your progress and achievements and judge you for any reason. Perhaps, they think you will be no longer in their life if you improve yourself too much.

Just stay confident and own your own faults and the things that make you shine. Cut toxic people from your life.

## Conclusion

Despite all, I cannot say that I was a bad person or regret about lots of things, in general, I have done or haven't. It's life, and it's normal to screw up and learn from own failures. 

I always keep in mind that everything could be changed apart from death. Take your destiny into your own hands and build your life from scratch.

What would you tell yourself 10 years ago? What advice would you give to yourself in the past? Do you have any regrets about anything?

I am so curious to read your story and know what is changed from that moment.

---

_Photo by Mikito Tateisi on Unsplash_
Managing UI state in location query
Tags: react, state, query, redux
Published: 2019-01-25 21:03:41

---
title: Managing UI state in location query
published: true
description: 
tags: #react #state #query #redux
---
I think every frontend developer had to store somewhere value of open dialog, selected tab etc.
For example, you have a simple requirement to open some small settings modal when a user clicks a button:
<img src="https://thepracticaldev.s3.amazonaws.com/i/aau09ny9p3ulg1rbgi79.png" >

If you use React, then you are lucky, you've got component state:
```js
openDialog = () => this.setState({ dialogOpen: true });
```
But then designer wants this dialog to open from few random components like here:
<img src="https://thepracticaldev.s3.amazonaws.com/i/xbux1hw8onpayqmqpb9j.png" >

These two dropdowns are different components with different state and in one of them, we have our `SettingsDialog` component. So what should we do now?
Add `SettingsDialog` to the second dropdown, same openDialog state key, and handlers? Or we can go further and put handlers and state key to a HOC to reuse this functionality? If we use redux we can also create UI reducer or use it if we have. UI reducer is just a messy object with different key-value pairs that are used and changed from across the whole application in random places. Here is the most primitive implementation (however complete enough):
```js
const ui = (state, action) => {
  if (action.type === "ui/set") {
    return { ...state, [action.key]: action.value };
  }
  return state;
};
```

Though, we can improve this. Not everyone uses redux even. We can keep the state of open dialog in the URL like "http://my.app?openDialog=true".
If a user refreshes the page, he still would see the dialog open. It is especially essential when we keep the state of selected tab like:
<img src="https://thepracticaldev.s3.amazonaws.com/i/wn84nj12ecnbc20yv1x8.png" >

But the best use case is probably of storing state in query is table filters and sort column. As a result, user would be able to share the same state he has.

So be flexible, keep state not only in your React components and redux.
Grails Views - Rendering Empty Lists
Tags: grails, groovy
Published: 2020-05-20 11:57:43

---
title: Grails Views - Rendering Empty Lists
published: true
date: 2019-01-25 20:54:23 UTC
tags: 
  - grails
  - groovy
canonical_url: 
---

Do you have a controller action that looks like this?

```groovy
def index() {
  respond myService.listItems()
}

```

Does that controller show a view like this?

```groovy
model {
  List<Item> itemList
}

json g.render(itemList)

```

This may appear to work fine when itemList is populated, but you may notice that the API is broken when the index method is run when there are no items in the list:

```bash
$ curl http://localhost:8080/api/items
[
   null
]

```

What? This is supposed to render `[]` because we’re responding with an empty list. What happened?

Let’s look at this from the documentation found here: [http://views.grails.org/latest/](http://views.grails.org/latest/)

> If the collection is empty, emptyCollection will be used as the default model name. This is due to not being able to inspect the first object’s type.

So the itemList field on our model is null because the auto model-binding computes to emptyCollection. There are technical reasons for this. The fastest way to fix this is to change how we call respond:

```groovy
def index() {
  respond([itemList: myService.listItems()])
}

```

This forces the itemList in the model to be bound manually, whether it is empty or not.
GitMessenger
Published: 2019-01-25 20:32:15

---
title: GitMessenger
published: true
---
Hey developers i have created a chat app with nodejs , socket.io, passportjs , Firebase , expressjs and getbootstrap where github users can chat with each other and share codes,images and much more.
Here is link https://gitmessenger.herokuapp.com/ 
{% github singhbhavneet/GitMessenger %}
The Importance of Selective Learning 
Tags: learning, programming, career, devtips
Published: 2019-01-25 20:11:34

---
title: The Importance of Selective Learning 
published: true
description: some thoughts on learning and why is it important to be selective about what you learn.
tags: learning, programming, career, devtips
cover_image: https://ak0.picdn.net/shutterstock/videos/6098450/thumb/1.jpg
---

We are very lucky to live in a time in which new technologies emerge every day to help us build all sort of stuff and make our lives easier. There's always this awesome tool or language that you want to learn and use because it introduces a new way of thinking or a different paradigm.

And with today's access to information and learning resources, and if you know how to do your google search, you will find a plethora of resources to help you learn that tool or language and a plethora of many more things to learn. _It can get overwhelming_.


Learning is a skill in itself and those of us who are able to learn fast are blessed, but it's also important to remember that it's not a race. Learn at your own pace; as long as you're learning, you should take all the time you need. But before you embark on this journey of learning, you should take a moment to consider if you really need to invest all this time to learn this and/or that tool. Because _you can learn anything but you can't learn everything_; that's why you should be especially **selective** about what you learn.

There will always be temptations to start using this new language because of how awesome and revolutionary it is or how it will replace this other language, however, this doesn't mean that you should drop everything and start investing time to learn it. Take a step back and thoroughly think if you actually need to learn it. 


Being selective about what you learn is how you distinguish yourself from others. _It is essentially about what you know well not how much you know_. 


and remember to never stop learning!

_this post was also published on [medium](https://medium.com/@amrrbakry/the-importance-of-selective-learning-a0ec3b358ed8)_