teleren/devto huggingface dataset:
★ 📺 How to avoid large function signatures by using pending objects
Tags: laravel, php, mailcoach
Published: 2020-01-02 23:47:08

---
title: ★ 📺 How to avoid large function signatures by using pending objects
published: true
date: 2019-12-30 15:39:07 UTC
tags: laravel, php, mailcoach
canonical_url: https://freek.dev/1545-how-to-avoid-large-function-signatures-by-using-pending-objects
---

In this video I demonstrate how to you can create a fluent API by using pending objects. We'll take a look at how subscribers can be created in Mailcoach. As a bonus I explain how jobs are dispatched using a pending object in Laravel.

{% vimeo 381539561 %}

This video is part of the [Mailcoach video course](https://mailcoach.app) which will be released early next year. In the video course I'll explain how we built Mailcoach and give tips on how to write well structured and clean code. Subscribe at [the Mailcoach site](https://mailcoach.app) to get notified when it is released.
Thank you!
Tags: motivation, codenewbie, wecoded
Published: 2019-12-30 15:21:55

Good day Folks.
This sounds more like a Thanksgiving post, but since I grew up without Thanksgiving, I have always liked to give my Thanks in the end of the year.

So much happen on the 364 (or is it 365?) days of the year.

We do things, we meet people (in my case mostly online), we evolve like a Pokemon (unless you are THAT Pikachu. Don't be that Pikachu)

![Dratini and its evolutions, Dragonair and Dragonite](https://thepracticaldev.s3.amazonaws.com/i/6nqlao907169cpo653ki.jpg)

Anyways. 

My point being is, there are LOTS of thanks to be giving  friends.
And I would like to start saying Thank You to you... Well, You of course. You are reading. Add a +1 thanks for each of my Posts you read. Thank you soo much! You make me blush >.<

I would like to say thanks to the entire Dev.to team for keeping this great platform for us, where I feel safe to write even as a codenewbie.

Thanks to the #DEVcommunity, all the helpful posts and comments and the people are just great.

Thank you to the twitter tech community that is always teaching me new things and helping me to stay motivated.

I have lots of goals for 2020 as you may know:
{% post https://dev.to/pachicodes/what-are-your-goals-for-2020-here-are-mine-47j6 %}


And I am sure that with your motivations I can do it, or at least most of of it.

Next year I will come back with more technical posts and stuff, but let just me end this year with Gratitude!


I wish you a fun NYE and that your 2020 is as awesome as me lol

See you next year friend,

love,
P.
Resolve to know what you can control
Tags: mindfulness, career, management, design
Published: 2019-12-30 15:19:59

> Ambition means tying your well-being to what other people say or do. Self-indulgence means tying it to the things that happen to you. Sanity means tying it to your own actions. — Marcus Aurelius

How concerned are you with the sound of your job title? I care. To me, a good job title can act like a key that, in a speaker’s or writer’s bio, at a networking event, on twitter, wherever, can unlock clout. But how much of the job title - let alone you being hired in the first place - is really in your control?

What, if anything, did you treat yourself to over the holidays? How much of your sense of well-being is tied to the roof over your head, the number of shows you binged, or what’s in the fridge? How much of any of that is in your control?

The end of the year is wrapped-up in self-evaluation and resolution, and what I would encourage us to carry in to the new year is appreciation for how little is actually within our sphere of control. We can control our actions - but circumstance, opportunity, luck: the greater part of the mix that are our careers? - we can only control how we act or react.

What sense is there in tying our happiness to a lottery? Consider, instead, resolving to
* be less reactive
* think first
* and memento mori 💀

for a Happy New Year.

Craft virtuously,
Michael Schofield

Please take a second to ❤ this post. Or, if you’re design philosophy is your kind of thing, [subscribe to Stoic Designer](https://stoic.substack.com).

Remember that design is not art, but a practice.
django-simple-task: An asynchronous Django 3 task runner
Tags: django, asgi, python
Published: 2019-12-30 15:02:33

---
title: django-simple-task: An asynchronous Django 3 task runner
published: true
canonical_url: https://shenli.dev/2019/12/30/django-simple-task.html
description: An asynchronous Django 3 task runner that does not require other services and separate worker processes
tags: django, ASGI, python
---

django-simple-task runs background tasks in Django 3 without requiring other services and worker processes. It runs them in the same event loop as your ASGI application. It is not resilient as a proper task runner such as Celery, but works for some simple tasks and has less overall overheads.

You can run background tasks like this in a django view and it would just work.

```python
from django_simple_task import defer

def task1():
	time.sleep(1)
	print("task1 done")

async def task2():
	await asyncio.sleep(1)
	print("task2 done")

def view(requests):
	defer(task1)
	defer(task2)
	return HttpResponse(b"My View")
```

Here’s an overview of how it works:

1. On application start, a queue is created and a number of workers start to listen to the queue
2. When defer is called, a task(function or coroutine function) is added to the queue
3. When a worker gets a task, it runs it or delegates it to a threadpool
4. On application shutdown, it waits for tasks to finish before exiting ASGI server

------

[View on PyPI](https://pypi.org/project/django-simple-task/) 

[View on GitHub](https://github.com/ericls/django-simple-task)

[Read the docs](https://django-simple-task.readthedocs.io/)
Use _ to get the last evaluated value - Python Tips
Tags: python
Published: 2019-12-30 14:57:24

In Python's interpreter, we can use _ to get the last evaluated value. This could be useful if you don't want to re-type the last evaluated value.

```
$ python3
Python 3.7.3 (default, Oct  7 2019, 12:56:13) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 + 2
3
>>> _
3
>>> 4 + _
7
>>>
```
Redux middleware
Tags: react, thunk, javascript, frontend
Published: 2019-12-30 14:49:14

---
title: Redux middleware
published: true
description: How to insert functionality between action creator and reducer in React
tags: react, thunk, javascript, frontend
cover_image: https://ferrariwebdevelopment.s3.us-east-2.amazonaws.com/assets/20191104-redux-middleware.jpeg
---

## How to insert functionality between action creator and reducer in React

Redux middleware allows us to insert some functionality in the action creator before an action is dispatched to the reducer.
This lets us do some extra operations like perform an `API` call and have the action creator dispatch different actions depending on the result of the call.

As you know, an `API` call can either succeed or resolve into an error and, depending on how the `API` call resolves, our application can take different paths to handle the situation.

In order to apply middleware we use a Redux method called `applyMiddleware` that is imported from Redux in `index.js`, along with the `Provider` and the reducer. In this example, we call the reducer `rootReducer`.

```js
// index.js

import { createStore, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import rootReducer from './reducers';

const store = createStore(rootReducer, applyMiddleware);

ReactDOM.render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById('root')
);
```

As you can see from the example, we pass `applyMiddleware` as the second argument to the `createStore` function.

`applyMiddleware` is the function that lets us work with middleware, but to actually do something with it we need to pass it the actual middleware we want.
We call such a function a `thunk` and we pass it to `applyMiddleware` like this:

```js
const store = createStore(rootReducer, applyMiddleware(thunk));
```

A `thunk` is a function that receives `dispatch` as an argument and calls it asynchronously. Since we want to call an `API` inside our middleware, `thunk` lets us dispatch different actions depending on the result of the `API` call.

We could pass multiple middleware functions to `applyMiddleware` and they will be called one by one in a sequence.
Before using `thunk` we need to install `redux-thunk` and import it into our file as `thunk`:

```js
// Install redux-thunk:

npm i redux-thunk
```
```js
// Import thunk into index.js

import thunk from 'redux-thunk';
```

This will send all the dispatches of our actions through `thunk`.
Now React is going to apply the `thunk` middleware and execute whatever is in `thunk` in between the action creators and the reducers.

To see how this works in practice, we are going to build a simple application that accesses the NASA `API` and fetches the *NASA Photo of the Day*.

---

*I write daily about web development. If you like this article, feel free to share it with your friends and colleagues.*

*You can receive articles like this in your inbox by [subscribing to my newsletter](https://cesare.substack.com).*
Decorators In Python
Published: 2019-12-30 14:43:56

Decorators is a **way to modify functions dynamically** by passing them as arguments to other functions. They are defined by **@** followed by func-name.

> @func-name

In some cases , we will be needing some steps to be executed before and after some functions. This case can be handled in two ways. 

1. Duplicating code in every functions.
2. Dynamically modifying functions.

Step 2 is the decorator. 

We need to understand that functions are the **first class objects**. They can be passed by reference, passed by arguments, return from another function, define inside another function.

Inorder to understand better , we shall cook omelete. 

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/7b5igcxshwjvj2dlg7dj.png)



**Ingridients:** Egg (Main Function), Salt,Pepper,Vegetables(Arguments).

Take a tawa, break an egg (functionality) ; add some (arguments) salt, pepper, vegetables (if needed). Cook for 2 mins. Omelete is ready. 

Now we have created the omelete . Likewise, we can make some veggies stuff, potato mash and other functionalities. For all these we may include bread to make it a complete dish (Bread Omelete, Sandwich, etc...). 


```python
def bread(omelete):
    def inner():
        print("Bread + ",end="")
        omelete()
        print("Bread ",end="")
    return inner
    
@bread
def omelete():
    print("Omelete + ",end="")

omelete()
```

Result ,
```bash
(base) syed@syed:~/Documents/Decorators$ python dec.py 
Bread + Omelete + Bread 
```


Here, bread is a common thing that is been included in all dishes mentioned above. 


```
Bread = Decorator
Omelete = Function
```

Decorators (Breads) are used to remove the duplicate code in the code base.


If you like this, leave a like , comment and make a share .
🧪 Install and Configure GitLab instance on Ubuntu 18.04
Tags: gitlab, installation, ubuntu
Published: 2019-12-30 14:23:46

**Step 1:**

*Installing the dependencies*

`sudo apt update`

`sudo apt install ca-certificates curl openssh-server postfix`

**Step 2:**

*Installing GitLab instance*

`cd /tmp`

`curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh`

`sudo apt install gitlab-ce`

**Step 3:**

*Adjusting the firewall rules*

`sudo ufw status`

*Output:*

```bash
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)
```

`sudo ufw allow http`

`sudo ufw allow https`

`sudo ufw allow OpenSSH`

`sudo ufw status`

*Output:*

```bash
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
80/tcp                     ALLOW       Anywhere                  
443/tcp                    ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
80/tcp (v6)                ALLOW       Anywhere (v6)             
443/tcp (v6)               ALLOW       Anywhere (v6)
```

**Step 4:**

*Editing the GitLab configuration file*

```bash
sudo nano /etc/gitlab/gitlab.rb
```

**/etc/gitlab/gitlab.rb**

```ruby
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
external_url 'https://opendevops.dev'
```

```ruby
letsencrypt['contact_emails'] = ['opantazos@gmail.com']
```

```bash
sudo gitlab-ctl reconfigure
```

**Step 5:**

*Launch the GitLab instance*

https://opendevops.dev
Daily Challenge #149 - Fun with Lamps
Tags: challenge
Published: 2019-12-30 14:17:59

---
title: Daily Challenge #149 - Fun with Lamps
published: true
series: Daily Challenge
description: How many lamps must be changed to make them alternate?
tags: challenge
---
###Setup
A number (*n*) of lamps are placed in a line, some are switched on and some are off. Write a function that will return the smallest number of lamps that need to be switched on or off so that the line of lamps alternate. 

You are given an array of 0s and 1s as input. 1 means on, 0 means off. Return the minimum number of switches needed. 

###Example
For `a = [1, 0, 0, 1, 1, 1, 0]`, the result should be `3`.
`1 0 0 1 1 1 0 --> 0 1 0 1 0 1 0`

###Tests
<pre>
lamps([1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1])

lamps( [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])

lamps([1, 0, 1])

lamps([1, 0, 1, 0])

lamps([0, 1, 0, 1, 0])

lamps([1, 0, 1, 0, 0, 1, 0, 1])

lamps([1,0,0,1,1,0,0,0,0,1,0])
</pre>

Good luck, have fun!

***
_This [challenge](https://www.codewars.com/kata/58a3c1f12f949e21b300005c) comes from *myjinxin2015* on CodeWars. Thank you to [CodeWars](<https://codewars.com/>), who has licensed redistribution of this challenge under the [2-Clause BSD License](<https://opensource.org/licenses/BSD-2-Clause>)!_

_Want to propose a challenge idea for a future post?  Email **yo+challenge@dev.to** with your suggestions!_
Code Fast in 2020
Tags: productivity, 2020
Published: 2019-12-30 12:03:06

Now is the perfect time to break bad coding habits. Didn't bother to memorise your editor's shortcuts? Perhaps you have to look at the keyboard to type? All of these little things add up, impeding our state of flow and ultimately, our speed.

There is a good chance you have fewer professional demands on you during the holiday season. This means you can optimise for long term productivity  at the expense of the short term. 

Yes it will be frustrating to clean up your productivity hygiene. Touch typing symbols and numbers will be slow and tedious at first. Learning a vastly different editor such as Emacs or Vim will be tricky. However by the time you hit work again you will be flying.

I am becoming proficient in [Spacemacs](https://www.spacemacs.org/) which is Vim inside of Emacs. The best tool I know for committing commands an shortcuts to memory is [Anki](https://apps.ankiweb.net/). Think of Anki as intelligent flashcards. I construct my own deck of cards starting with the most frequently used keyboard bindings.

I am also becoming a better typist at [Typing Club] (https://www.typingclub.com/). Another site  is [typing.io](https://typing.io/). There you can find typing practice tailored to coders.

There is a confusing array of opinions on the internet about what really impacts your productivity. My advice is to ignore the noise and trust your own judgement. You know what is holding you back and the holiday period is the perfect time to put those little demons to bed.
HacktOverFest
Tags: hacktoberfest, stickers, opensource, macos
Published: 2019-12-30 14:13:03

---
title: HacktOverFest
published: true
description: Final look
tags: hacktoberfest, stickers, opensource, macOS
---

![Macbook with stickers](https://thepracticaldev.s3.amazonaws.com/i/5ajanuxr6ddf49uysy6p.jpeg)
My Top 9 Achievements in 2019 
Tags: discuss, motivation, womenintech
Published: 2019-12-30 13:52:54

---
title: My Top 9 Achievements in 2019 
published: true
description: A new day on the calendar 🗓 isn’t going to bring you joy, success, flat abs or your dream life. It’s up to you to create that for yourself, no matter what day is it.
tags: discuss, motivation, womenintech, firstyearincode
---

A new day on the calendar 🗓 isn’t going to bring you joy, success, flat abs or your dream life.

It’s up to you to create that for yourself, no matter what day is it.


![My Top 9 Achievements in 2019](https://thepracticaldev.s3.amazonaws.com/i/0hdmqipae0d6hr6ghsin.jpg)


However, I am thankful for 2019 for so many reasons:


- Reading around 30 books 📚

- Creating my [newsletter](https://www.ilonacodes.com/networking-cheat-sheet/) 📨 with more than 1600 readers

- Co-founding [Foundsiders](foundsiders.com) and becoming a full-time 👩‍💻 Product Maker 

- Building and launching my first ever software product 📊 [FelloWage](fellowage.io)

- Giving talks at 5 conferences

- Riding a segway for the first time

- Getting settlement permit in Germany 🇩🇪

- Co-authoring the [“Your First Year in Code”](https://www.producthunt.com/posts/your-first-year-in-code) book 📖

- Learning how to teach myself anything 🙆‍♀️

**What are you thankful for in 2019? 🙂**
How to create React Native/Expo npm packages
Tags: npm, reactnative, expo
Published: 2019-12-30 04:00:38

---
title: How to create React Native/Expo npm packages
published: true
description:
tags: npm, react native, expo
---

Developing npm modules that work with Expo is different from the traditional flow that you can use with a regular 'ol React project. Usually in a React project, you could create a module inside a folder on your computer, then run `yarn link` inside it and proceed to link it inside your testing playground. 

Expo is powered by React Native, which uses a bundler to bundle your app's dependencies. This prevents `yarn link` from working as usual.

To develop a package, there are two different strategies depending on what you need to do. You might need to create the contents of the package, or you might need to verify it works as an import in real project.

## Creating the contents of the package

Create a testing app with `expo init`. Inside it, create a folder named **your-package-name**, with in an **index.tsx** file inside. The file structure should look like:

```
testing-app/
  your-package-name/
    index.tsx
    ...
  App.tsx
  ...
```

Inside **App.tsx**, you can now `import Foo from './your-package-name'`, and develop it just like a regular component --that's because this is the exact same as creating a regular component. By doing this, you get the awesome dev-experience/fast-reload of Expo.

## Testing the package as a dependency

When the package is in a spot that is complete, you are ready to test it as an import into a real project. We're going to do this without publishing it to npm or using a tool like `yalc`. 

In another spot on your computer, create a folder named after your package: **your-package-name**. Inside it, copy over all the files that make up your package. Then, run `expo init example` to create an **example** folder inside your package folder, like this:

```
your-package-name
  example/
    ...[expo app here]
  index.tsx
  ...

```

To install the package in the **example** Expo app you just made, `cd` into the parent **your-package-name** directory, and run `npm pack`. 

This will package up your module into a **.tgz** file. When you run the command, the last line of output will tell you the file name that it just saved (it should look like: **your-package-name-version.tgz**). Copy it, then `cd` back into the **example** folder and run `yarn add [your-copied-name].tgz` and your package will be installed as a dependency. Inside the Example, you can now import it with `import Foo from 'your-package-name'`.

Now you can create an example that will test your package within an app, and if you commit it to GitHub, others can also see a working example of your package too.

Once your package is in a good spot, follow with your `npm publish` flow.

To see an example of an Expo compatible project with an **example** folder, check out my [`react-native-fade` package](https://github.com/jonsamp/react-native-fade).

Happy package-ing!
Released a CLI "create-awesome-package" to bootstrap your JS/TS package 🚀 📦 (with video demo)
Tags: javascript, webdev, npm, node
Published: 2019-12-30 13:44:04

This CLI helps to create the package with JS/TS, build system(Webpack/Parcel) and necessary stuff 🔥

It's like create-react-app but for building packages 📦

It’s a manual process to arrange all your boilerplate code, Webpack or other build systems to transpile to ES5, etc. and then build your desired package.

- Mainly a bundler like Webpack or Parcel
- Babel to transpire the code

To fix that, I have published a CLI tool, which will help us to do those things, and you will be ready to do your actual code right away.

The name of the CLI is <b>create-awesome-package</b>

create-awesome-package helps to create the package with the build system and necessary stuff.

You just write your own code 🔥

You can find this on 👉 [NPMJS https://www.npmjs.com/package/create-awesome-package](https://www.npmjs.com/package/create-awesome-package)

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/e3sibo1iyfmw6rdby33c.gif)


<h3>How to install</h3>

```
npm i -g create-awesome-package
```

<h3>How to use</h3>

Go to your root of the package you want to build.

Then, Just run

```
create-awesome-package [package-name]
```

OR also you can use npx

```
npx create-awesome-package [package-name]
```
( if you don't want to globally install it)

and you are done! :clap:

<b>Jest</b> Testing is integrated with it.
Just run-
```
npm run test
```
If you want to build the package into one single file with ES5 transpilation, Just run-
```
npm run build
```
You can watch the video on YouTube to see the COMPLETE DEMO of how to use it 👋

{% youtube dykr3BHlGck %}

I am working on a few more features for it. I will release those soon.

Cheers!
:wave:

Also posted here [https://shahjada.me/2019/12/28/create-awesome-package-released-a-cli-to-bootstrap-your-awesome-package/](https://shahjada.me/2019/12/28/create-awesome-package-released-a-cli-to-bootstrap-your-awesome-package/)

As I am trying to contribute contents on the Web, you can buy me a coffee for my hours spent on all of these ❤️😊🌸
<a href="https://www.buymeacoffee.com/destromas" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>

*Inspired from create-react-app*