teleren/devto huggingface dataset:
MobX Tips: New Api named flow (confusing name...)
Tags: mobnx, typescript, javascript
Published: 2018-06-14 06:57:57

---
title: MobX Tips: New Api named flow (confusing name...)
published: true
description: 
tags: mobnx, typescript, javascript
---

# 3.x

In MobX 3.x, Writing async actions is a little verbose.

```js
import { observable, runInAction } from 'mobx'
import { someApi } from '../api'

class SomeStore {
    @observable someState = ''

    async someAction() {
        const res = await someApi.fetch()
        runInAction(() => {
            this.someState = res.data
        })
    }
}
```

# 4.x

MobX 4.x has a new API named `flow`, which is really confusing. Every time I google `mobx flow`, Facebook's static typing tool shows up.

```js
import { observable, flow } from 'mobx'
import { someApi } from '../api'

class SomeStore {
    @observable someState = ''

    someAction = flow(function * () {
        this.someState = yield someApi.fetch()
    })
}
```

Ohnestly I don't know what is happening above, but the code become shorter and cooler with generator function and class property.

If we use using MobX's flow + TypeScript with strict mode, try bind this to the class in generator function, like this:


```typescript
    public someAction = flow(function * (this: SomeStore) {
        this.someState = yield someApi.fetch()
    })
```

(I spend one hour to find this solution)


# Promise

If we consider error handling, Promise become simpler:

```js
import { observable, action } from 'mobx'
import { someApi } from '../api'

class SomeStore {
    @observable someState = ''
    @observable error = null

    someAction() {
        someApi.fetch().then(
            action(res => this.someState = res.data),
            action(err => this.err = err),
        )
    }
}
```
DockerCon Day 2
Tags: docker, containers, security, kubernetes
Published: 2018-06-14 04:56:01

---
title: DockerCon Day 2
published: true
description: a writeup of all the things I learned today at DockerCon
tags: docker, containers, security, kubernetes
cover_image: https://thepracticaldev.s3.amazonaws.com/i/8lbqbc07cq5owu768aau.jpg
---

I've written up a summary of all the things I learned today at #DockerCon, and it was big so I broke it into 5 parts (so it loads fast). You can start off here - It's a detailed read but I tried to keep it concise and focused. 


https://vault.osninja.net/dockercon-day-2-part-1/
How to get rid of the junior mentality
Tags: junior, carreer, growth
Published: 2018-06-14 00:55:05

---
title: How to get rid of the junior mentality
published: true
description: 
tags: Junior, carreer, growth, 
---

Hello there!

### Who are you?

I've been working as a developer for around 1 year professionally, i'm currently studying CS and always loved the idea of making things work as i wantby writing code. My current stack at work is mostly JS (Angular 2+, Node), and have worked with C# (.Net).

As a young developer being in the industry since so early, i've been really curious about how we developers define ourselves by 'Ranks', when do you become a senior developer? how do you do it? what you should do/know?, I still don't have answers to those questions, but i realized there's a key factor that influences every developer carreer, no matter how much time and experience they have...

### Mentality

When I was just starting, i had to fight with the overwhelming ammount of things that seemed necessary to learn in order to call myself even a developer, let alone working as one. This takes us to the first point:

## Don't be afraid of what you don't know

Nobody knows everything, and this is specially true in programming. No matter how many years of experience or how many languages a developer claims to know, what really matters is how do he/she approaches learning new things. And this is an attitude that will open you a huge ammount of opportunities. Don't be afraid of spending hours on a problem that might seem the simplest of them all, just because you don't know how does x thing work, as long as they are spent researching and actively working on understanding it. In the end, you might have learned more than what you were first looking for. It's also important to have in mind that ...

## Things may take time

As every other discipline, being proficient as a developer will take time, understanding some things will take time, and making things work will take time, but you should always loow forward to complete what you're doing, because stress and fatigue may come, but will always pays off in the long run. You will be a better developer, and may be able to complete any similar task in a better faster and cleaner way sometime in the future.

## Ask what needs to be asked!

And I can't stress this enough. Asking other developers when you're new into programming is one of the best and most enriching things you can do, because most of the time people will be eager to help you and you may learn a whole lot of things in a way it's really hard to reproduce any other way. Most experienced developers also make questions all the time. Not knowing something doesn't make you less of a developer.

#### What else would you add to this list? when did you stopped feeling as a junior?Leave it in the comments!
___
Pablo Marcano
Full Stack developer Working @ [Kaizen Softworks](https://kzsoftworks.com) in Montevideo, Uruguay
Narcissistic number
Tags: challenge, javascript, python, etc
Published: 2018-06-13 23:42:11

---
title: Narcissistic number
published: true
tags: challenge, javascript, python, etc
---

A Narcissistic Number is a number that is the sum of its own digits, each one raised to the power of the number of digits.

Example: 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153

To practice! :D
What is `map` in a Java Stream
Tags: java, functional, java8
Published: 2018-06-13 23:35:50

---
title: What is `map` in a Java Stream
published: true
description: Working with streams often requires 'mapping' of objects. What is mapping, and why do people do it with streams?
canonical_url: https://www.gunnargissel.com/map-in-java-stream.html
tags: java, functional, fp, java8
cover_image: https://thepracticaldev.s3.amazonaws.com/i/rxu7unjfnzoutafucx6q.png
---

_[Originally published at www.gunnargissel.com](https://www.gunnargissel.com/map-in-java-stream.html)_

Mapping is how to convert one type of object to another with a stream.  Say you have a set of `Fruit` and you want to show people what is in your set.  It would be helpful to have a list of fruit names to do so.

    fruitList.stream().map(fruit::getName).collect(Collectors.toList);

That's pretty simple; you can imagine how to do that in real life with a basket of fruit.  

Pick up a piece of fruit, write its name down.  Pick up another piece of fruit, write its name down, etc.

Mapping also lets you you can't easily simulate in real life.  Say you have a Fruit set and you want Oranges, instead of Apples (I think this is closer to transmutation than swapping, but it's a metaphor, ymmv).

You can do that, with Java:

    fruitList.stream().map(fruit -> {
        if( fruit instanceof Apple){
            return new Orange();
        }
        return  fruit;
    }).collect(Collectors.toSet);

__If you liked this article, [sign up for my mailing list to get monthly updates on interesting programming articles](https://www.gunnargissel.com/pages/email-signup-1.html)__
Code consistency vs using new features
Tags: discuss, development
Published: 2018-06-13 22:43:31

---
title: Code consistency vs using new features
tags: discuss, development
published: true 
---

So, lets say you added a new feature to an existing Java project, and when adding unit test you see that other similar tests are using null checks:
```java
if(value != null){
    assertEquals("Value should be 10", 10, value);
}
```
But you know about Optionals so your test could look like:
```java
Optional.ofNullable(value).ifPresent(value ->
    assertEquals("Value should be 10", 10, value)
);


```
Another example could be type annotations in Python

Which is more important to you? Keep the code consistent but not using new features or use new features even if code will end up looking inconsistent?

_Only considering that using or not using new features is not a decision based on performance, security or any other concern_

My initial approach would be keep it consistent but add a low priority task to refactor code if/when necessary, but curious to find out what others think.
Lazy Questions
Tags: discuss, communication
Published: 2018-06-13 21:33:58

---
title: Lazy Questions
published: true
description: Are dumb questions real? I don't think so. I do think many questions people say are "dumb" are actually lazy.
tags: discuss, communication
cover_image: https://thepracticaldev.s3.amazonaws.com/i/12ozzb9hi4kc7hcm2d6h.JPG
---

I don't think there are dumb questions. I do think there are lazy questions. I classify a lazy question as a question where the answer is googleable or is documented in a well-known location. If you're a programmer asking me about the implementation of a function and you have no reason not to read it and understand it yourself, I expect you to go read the code, not ask me how it works.

How do you feel when people ask you questions that are googleable or might require a bit of code or documentation reading?
Customizing Firefox Quantum’s about:config
Tags: firefox
Published: 2018-06-14 02:04:34

---
title: Customizing Firefox Quantum’s about:config
published: true
tags: firefox
canonical_url: https://medium.com/@johnphamous/customizing-firefox-quantums-about-config-8cbc6950bca4
---

Firefox’s about:config is where you can access Firefox’s advanced configurations. Everything from animations to memory usage to experimental features can be found here and configured. These changes can improve your browser experience and increase performance. You can access these configurations by typing about:config in your address bar and pressing enter.

![](https://cdn-images-1.medium.com/max/1024/1*kya6EFAUkfQDprrYctAViQ.png)<figcaption>Firefox’s Configuration Editor</figcaption>

The first column shows the name of the configuration. The second column tells you whether the current value is Firefox’s default or not. The third column specifies what type of values that configuration reads. Lastly, the fourth column is where you can view and modify the configuration values.

To change a value, double click on the row of the configuration you want to change. **Be careful with which configurations you change as it may result in your browser misbehaving.**

Below are a few configurations for you to consider.

### 1. Cosmetic Animations

Do you like those pretty animations? Animations use a considerable amount of RAM. If you have an older machine, every byte of RAM counts for smooth usage. Consider turning off Firefox’s cosmetic animations.

toolkit.cosmeticAnimations.enabled: false

### 2. Spell Checking for all Text Fields

Firefox defaults to spell checking only text area inputs. By modifying this configuration, you can tell Firefox to spell check all types of text inputs.

layout.spellcheckDefault: 2

### 3. Zoom Limits

Ever have those awkward moments when you zoom in or out too much on a page? By default, you can zoom in up to 300% and zoom out down to 30%. You can actually change these limits. Units are in percentages.

zoom.maxPercent: 150

zoon.minPercent: 70

### 4. View Page Source in your Text Editor

Firefox’s Developer Tools is one of the best ways to view and debug code. If you prefer using your own text editor or IDE, you can tell Firefox to open the source code in those programs.

view\_source.editor.external: true

view\_source.editor.path: /usr/bin/vim # path to your editor/IDE

### 5. Offline Cache

Firefox’s cache stores data for web apps that support offline mode. If you’re working on an inconsistent network connection or commute, increasing the offline cache allows the browser to store more data to support offline mode. The cache size is specified in kilobytes.

browser.cache.offline.capacity: 1024000 # This is about 1GB for the cache

These are 5 configurations I change every time I reinstall Firefox. At the time of writing this, there are over 600 different configurations you can change! Documentation on all of them is actually pretty slim. Check out [Mozilla’s official docs](https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Preference_reference) and [mozillaZine’s wiki](http://kb.mozillazine.org/About:config_entries).
Fixing a Rails Migration Snafu
Tags: ruby, rails
Published: 2018-06-13 20:21:04

---
title: Fixing a Rails Migration Snafu
published: true
description: Messing up a database migration in production, even in the distant past, is not the end of the world.
tags: ruby, rails
cover_image: https://thepracticaldev.s3.amazonaws.com/i/16a5ue7xv05z6fu0fk84.jpg
---

I had been working on a huge new feature for a Rails app with existing customers for about two months. This new feature had about 10 new database migrations, including rolling back and editing the last migration that had been pushed to production and renaming those tables. That was a mistake. If, two months later, I had remembered to rollback the most recent migration in production before performing the new migrations, all would have been well.

Alas, I did not. Obviously, any programming change that requires you remember to do something 2 months from now is bad, especially if you have no system to remind yourself before deploying. When I did push the feature to production, my new migrations ran fine and two days laters I started getting errors about how a database table doesn't exist when my code assumes it does. It didn't take me long to realize that it was the migration about 10 migration files back that was the source of the error where I had rolled back in development and renamed the tables, but I had not rolled back in production.

Worse, I had a bunch of data live in production now, that depended on tables created in migrations after the problem migration file. I was not okay losing that data, but the only solution to my problem that I knew about required it. Basically, I was familiar with the basics of migrations through the [Rails ActiveRecord migrations guide](http://edgeguides.rubyonrails.org/active_record_migrations.html). I thought I'd have to push the old version of that migration file to production, rollback 10 migrations (losing all my new data), push the new version of the migration file and run db:migrate one more time.

Thankfully, in my desperate googling for a solution, I ran into [this question and answer](https://stackoverflow.com/questions/753919/run-a-single-migration-file), which suggested a path forward. When I realized you could run a single migration up or down with the version option, it became clear. I had to push the old version of that migration to production and then run:
```
rails db:migrate:down VERSION=20180506181554
```
Then push the new version of that migration and run:
```
rails db:migrate:up VERSION=20180506181554
```
The version, by the way, is just the timestamp in the filename rails generates automatically if you are using `rails generate migration`. Knowing how to reverse and rerun a specific migration file is a huge relief. Its comforting to know getting migrations out of sync in production doesn't necessarily have to blow everything up, but has the potential to be dealt with as an isolated problem. Thanks Rails!
c9x edit 
Tags: editor, x11, macosx
Published: 2018-06-13 19:55:01

---
title: c9x edit 
published: true
description: quick notes on using c9x edit on a mac
tags: editor, x11, macosx
---


In order to compile [c9x edit](http://c9x.me/edit/) on a Mac, you will have to do the following:

```
export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig
make
./obj/edit
```

this will launch the `ed` window using X11 (XQuartz).
Python functional closure scopes without global or nonlocal
Tags: python, global, functions, nonlocal
Published: 2018-06-13 19:53:36

--- 
title:  Python functional closure scopes without global or nonlocal
published: true
description: 
tags: python, global, functions, nonlocal
---

A typical decorator in python or any nested closured functions is usually referring to the state from one or more variable scope above.


```python

def wrapper():

    counter = 0

    def incr():
        counter += 1
        return counter
    return incr

fn = wrapper()
print(fn())


# Traceback (most recent call last):
#   File "sample.py", line 51, in <module>
#     print(fn())
#   File "sample.py", line 46, in incr
#     return counter
# NameError: name 'counter' is not defined


```

Like in this example with counter variable. The code will fail to execute because `counter` is not visible within `incr` function scope.



The typical fix is usually either to declare counter as nonlocal or even global . 

```python


def wrapper():

    counter = 0

    def incr():
        nonlocal counter
        counter += 1
        return counter
    return incr


fn = wrapper()
print(fn())

# >> 1

```


This works as expected but is the other way achieve the same?



```python


def wrapper():
    v = dict(counter=0)

    def incr():
        v['counter'] += 1
        return v['counter']
    return incr


fn = wrapper()
print(fn())

# > 1

```


As the first trick we can use mutable object like dict to declare and modify the state without nonlocal keyword. Why does it work? Comparing to previous example `counter += 1` this is actually syntactic sugar for `counter = counter + 1` and python interpret usually has no clue how to resolve to which scope reassign this new counter variable. However if it just mutation by object reference there is no such ambiguity



Another trick derives from the previous example but I found it more readable and concise.



```python

def wrapper():
    class Vars:
        counter = 0

    def incr():
        Vars.counter += 1
        return Vars.counter
    return incr


fn = wrapper()
print(fn())
# >> 1

```

[Original post](https://medium.com/@msoedov/python-3-functional-closure-scopes-without-global-nonlocal-5630b172f764)
Project Euler #2 - Even Fibonacci numbers
Tags: projecteuler, challenge
Published: 2018-06-13 18:13:12

---
title: Project Euler #2 - Even Fibonacci numbers
published: true
description: Solving problem #2 from Project Euler, even Fibonacci numbers
tags: projecteuler, challenge
series: Project Euler
---

I had a blast reading through the many creative and varied approaches to solving Problem #1.  There's something very fun and enlightening about seeing the same problem solved in different ways:

{% link https://dev.to/peter/project-euler-1---multiples-of-3-and-5-515d %}

Not sure if this will become a regular thing, but I wanted to keep this rolling and present **[Problem #2](https://projecteuler.net/problem=2)**.  Again, this is from the wonderful [Project Euler](https://projecteuler.net).

>Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
>
>1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
>
>By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

Look forward to seeing solutions in your language of choice!
React Native: Write code depending on the plateforms
Tags: reactnative, react, ios, android
Published: 2018-06-13 17:19:40

---
title: React Native: Write code depending on the plateforms
published: true
description: Because some code doesn't concern ios or android...
tags: react-native, react, ios, android
cover_image: https://thepracticaldev.s3.amazonaws.com/i/sqlvqf3rve2tv8z2yoke.png
---

## Introduction

React Native allows you to write code for the iOS and Android platforms using the Javascript and React syntaxes. With this logic, you will want to re-use as much code as possible for both platforms. However, at one point, you will have to write code for a specific platform. In this article, we will see how React native makes this possible.

## The *Platform* module

First way to do this, the *Platform* module. You can import it like this:

`import {Platform} from 'react-native'`

Using this, we can now know which platform we are on with the `Platform.OS`.

```javascript
<Text>{Platform.OS == 'ios' ? 'Hello IOS' : 'Hello Android'}</Text>
```

*Platform.OS* will return 'ios' or 'android'. You can also use the select method:

```javascript
<Text style={{
    color: 'blue',
    ...Platform.select({
        ios: {
            backgroundColor: 'red'
        },
        android: {
            backgroundColor: 'green'
        }
    })
}}>
    Hello World
</Text>
```

Our text will be blue on both platforms,but the background color will be red on iOS devices and green on Android.

The *select* method returns any value. You can give it whatever is valid with React:

```javascript
const MyComponent = Platform.select({
    ios: () => <Text>Hello iOS</Text>,
    android: () => <Text>Hello Android</Text>
})

<MyComponent />
```

### Get specific version

You can use *Platform.Version* to detect the iOS or Android version you are currently running on.

```javascript
// On Android
const version = Platform.Version // 25 = 'Nougat'

// On iOS
const version = Platform.Version // 11.2.2
```

## Using platform specific extensions

At one point, the Platform module may not be enough to write what you need and you might have to create entirely different components for iOS and Android. React Native is able to detect *.ios* or *.android* file extensions and load the correct component.

You can have files like this:
```

TopBar.ios.js
TopBar.android.js

```

And import them like this:

```javascript
import Topbar from './TopBar'
```

React Native will know which component to take thanks to the file extensions.

Have fun!!!
Surviving the Doldrums - What To Do When Your Job Is Slow
Tags: discuss, question, query, survey
Published: 2018-06-13 17:18:22

---
title: Surviving the Doldrums - What To Do When Your Job Is Slow
published: true
description: Sometimes you're busy; sometimes you're not. What can you do in the down times to prepare for the crunch times?
tags: discussion, question, query, survey
---

## What do you do when you have down time at work? 

My list includes

- **Reading**: I learned most of what I know about code from reading books/articles/blogs/etc. I try to sharpen my skills when I have the moment
- **Enki**: Reading is great, but it can be boring. Enki (a code skills app) makes it fun to learn new skills
- **Enterprise Exploration**: I am always learning about new products and services that are offered by my company outside of the products that I work on. It helps me understand the broader ecosystem of my company and our industry.

#### _What about you?_
Choose Your Own Framework: The Curse of JavaScript Fatigue
Tags: humor, funny, javascript
Published: 2018-06-13 17:13:03

---
title: Choose Your Own Framework: The Curse of JavaScript Fatigue
published: true
description: How will your project die?
tags: humor, funny, JavaScript
---

How will your project die? Choose from 2,147,483,647 possible endings!

![How will your project die?](https://thepracticaldev.s3.amazonaws.com/i/erqmsi1gk3ybbm8vu4ad.jpg)
Vue.js and AWS Lambda: Developing Production-Ready Apps (Part 1)
Tags: vue, javascript, lambda, aws
Published: 2018-06-13 15:16:08

---
title: Vue.js and AWS Lambda: Developing Production-Ready Apps (Part 1)
published: true
description: In this series, you will learn how to develop production-ready applications with Vue.js and AWS Lambda.
tags: #vuejs #javascript #lambda #aws
canonical_url: https://auth0.com/blog/vue-js-and-lambda-developing-production-ready-apps-part-1/
---

In this series, you will use modern technologies like Vue.js, AWS Lambda, Express, MongoDB, and Auth0 to create a production-ready application that acts like a micro-blog engine. The first part of the series (this one) will focus on the setup of the Vue.js client that users will interact with and on the definition of the Express backend app.

[Read more ☁️🚀](https://auth0.com/blog/vue-js-and-lambda-developing-production-ready-apps-part-1?utm_source=dev&utm_medium=sc&utm_campaign=vuejs_lambda)

![Vue.js and AWS Lambda: Developing Production-Ready Apps (Part 1)](https://thepracticaldev.s3.amazonaws.com/i/6ryqqqwugy6kmshy7mbo.png)