teleren/devto huggingface dataset:
Asyncio in Python 3.7
Tags: python, asyncio
Published: 2019-07-05 03:33:51

---
title: Asyncio in Python 3.7
published: true
tags: python, asyncio
canonical_url: https://tryexceptpass.org/article/asyncio-in-37/
cover_image: https://tryexceptpass.org/images/async-3.7.jpg
---

The release of Python 3.7 introduced a number of changes into the async world. There are a lot of quality-of-life improvements, some affect compatibility across versions and some are new features to help manage concurrency better. This article will go over the changes, their implications and the things you’ll want to watch out for if you’re a maintainer. Some may even affect you even if you don’t use asyncio.

[Read on ...](https://tryexceptpass.org/article/asyncio-in-37/)
Plain text pages in Lucky
Tags: crystal, lucky
Published: 2018-07-20 20:51:03

---
title: Plain text pages in Lucky
published: true
description: Plain text pages in Lucky and some dynamic text pages
tags: crystal, lucky
---

Sometimes you may need to render a page that's not a webpage with HTML, but more just plain text. One example would be a [robots.txt](http://www.robotstxt.org/robotstxt.html). Now, what you may be thinking right now is "why not just make a static text file, and throw that in your public directory?". Well, you'd be right, but then I wouldn't have a reason to write this post 😛. Another reason (which I'll show you) is for some dynamic content.
 
First we will make a new action in `src/actions/static_pages/robots.cr`

```ruby
class StaticPages::Robots < BrowserAction
  get "/robots.txt" do
    text <<-TEXT
    User-Agent: *
    TEXT
  end
end
```

That's it! Boot your server up, and check out your localhost:3000/robots.txt and check out the content type is set to `text/plain` like it should be. 

With [Lucky](https://luckyframework.org/), there's a helper method called `text`. This is a replacement to a `redirect` or `render` for your action which means you only call it once. It's not chainable, so if you have a lot of text to render, you can break it out in to methods, and then do something like `text my_formatted_output`.

Now, I did mention that you may want to go with this route if you're doing something dynamic. Let's say you have a [multi-tenant app](https://en.wikipedia.org/wiki/Multitenancy) where multiple domains point to your single app. Having one robots.txt file in your public directory might not work. Each domain might have different requirements.

```ruby
class StaticPages::Robots < BrowserAction
  get "/robots.txt" do
    text <<-TEXT
    Sitemap: https://#{current_site.host}/sitemap.xml
    User-Agent: *
    TEXT
  end
end
```

See? It's useful, now go and use it!
Reflection in Go: create a stack[T]
Tags: go, reflection
Published: 2018-07-21 16:57:40

---
title: Reflection in Go: create a stack[T]
published: true
tags: golang,reflection
canonical_url: https://dannypsnl.github.io//golang/reflection/2018/07/22/reflection-in-go-create-a-stack-t.html
---

Do you know what can Go’s package `reflect` do?

Whatever you had to use it or not. Understanding it is not a bad thing.

A well-known thing is Go don’t have generic, I’m not going to tell you we have generic, I’m going to tell you some basic trick to have the result like generic.

Real world example: [elz-lang/collection/stack](https://github.com/elz-lang/elz/blob/master/collection/stack/stack.go)

Elz is a language I’m developing, but that’s not the point. Point is this collection/stack using the trick I’m going to talk about.

Take a look on the type `Stack`

```go
type Stack struct {
	stack []interface{}
	limitT *reflect.Type
}
```

`limitT` is a `*reflect.Type`, the reason that it’s a pointer to `reflect.Type` rather than `reflect.Type` is because we may do not spec it.

We add the `Stack<T>` by invoking `WithT`.

```go
func (s *Stack) WithT(v interface{}) *Stack {
	t := reflect.TypeOf(v).Elem()
	s.limitT = &t
	return s
}
```

Why is `reflect.TypeOf(v).Elem()`? Because we can’t really get an instance that type is an interface! Instead of that, we can get a type is a pointer to an interface!

We have a common idiom is using `(*SomeInterface)(nil)` to get the pointer to interface instance.

Now we know that user code can be

```go
type AST interface {
    Gen() llvm.Value
}

// main
s := stack.New().WithT((*AST)(nil))
```

After we do that, a user can’t push a value do not implement `AST`.

So, how we do that? We do a check at `Push`

```go
func (s *Stack) Push(element interface{}) {
	if s.limitT != nil {
		if !reflect.TypeOf(element).Implements(*s.limitT) {
			panic(fmt.Sprintf("element must implement type: %s", *s.limitT))
		}
	}
	s.stack = append(s.stack, element)
}
```

If `limitT` is not `nil`, means we do not limit the type, just keep going on.

But if we limit the type, we check that `element` implements `limitT` or not.

If not, we panic the process.

Now we have a stack can promise to typesafe at runtime.
Automate semantic versioning in git
Tags: tools, git, bash, semanticversioning
Published: 2018-07-22 12:20:30

---
title: Automate semantic versioning in git
published: true
tags: tools, git, bash, semantic-versioning
canonical_url: http://franiglesias.github.io/versiontag/
---

I've just wrote a little command line tool to automate tags for semantic versioning in git.

[You can see and download in the github repository](https://github.com/franiglesias/versiontag), where you'll find full documentation.

**versiontag** looks for the last version tag in your project and updates it.

When you are ready for tagging, you only has to invoke `versiontag` with the version level you want to update. And that's all. It would show you the current version, the new one, and will ask you for confirmation to add and to push it to the remote.

This is an example from the versioning of **versiontag** , in which you can see all steps and details:

```
➜ versiontag git:(master) ./versiontag patch 'Add License'
Current version : v1.0.1
New tag :         v1.0.2
Do you agree? ([y]es or [N]o): y

Executing git tag -a v1.0.2 -m Add License (patch version) ...

Tag v1.0.2 was created in local repository.

Push it:

    git push origin v1.0.2

Delete tag:

    git tag -d v1.0.2

Do you want to push this tag right now? ([y]es or [N]o): y

Executing git push origin v1.0.2 ...

Counting objects: 1, done.
Writing objects: 100% (1/1), 179 bytes | 179.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/franiglesias/versiontag
 * [new tag] v1.0.2 -> v1.0.2

```

Ideas and improvements will be welcome (specially get the last version tag from the remote and discriminate tags that are not version related).

HTH :-)
How to use AWS EBS volume as a swap memory
Tags: aws, swap, ec2, ebs
Published: 2018-07-21 19:35:47

---
title: How to use AWS EBS volume as a swap memory
published: true
description: Use EBS volume as a swap space on EC2 Linux in AWS
tags: aws, swap, ec2, ebs
---

### What is swap space?
Swap space in Linux can be used when a system requires more memory than it has been physically allocated (RAM). When swap space is enabled, Linux systems can swap infrequently used memory pages from physical memory to swap space (either a dedicated partition or a swap file in an existing file system) and free up that space for memory pages that require high-speed access. [[1]]

### Step 1 - Create EBS Volume
Follow steps to create EBS Volume in AWS Console, that we'll use as a swap memory.
1. Go to EC2 Dashboard
2. Select EBS Volumes
3. Create Volume
4. Recommended size of swap volume is 2 times of RAM [[2]]
5. Select availability zone same as your EC2 instance

### Step 2 - Attach EBS Volume to EC2
Select EBS Volume that we just created for swap and your EC2 instance.

### Step 3 - Set EBS Volume as swap space
Run `lsblk` to check new volume, it will appear as `/dev/xvdf` on instance.
```
$ lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  256G  0 disk
└─xvda1 202:1    0  256G  0 part /
xvdf    202:80   0   32G  0 disk
```
Set up the swap area
```
$ sudo mkswap /dev/xvdf
```
Enable swap
```
$ sudo swapon /dev/xvdf
```
Make this swap setting persist by adding following line in `/etc/fstab`
```
$ sudo nano /etc/fstab
/dev/xvdf none swap sw 0 0
```

### Step 4 - Check swap space
```
$ sudo swapon --show
NAME      TYPE      SIZE   USED PRIO
/dev/xvdf partition  32G 279.9M   -1
```

[1]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-store-swap-volumes.html
[2]: https://askubuntu.com/questions/49109/i-have-16gb-ram-do-i-need-32gb-swap
How to set up Emacs to open read-only depending on file location
Tags: emacs
Published: 2018-07-21 16:52:35

---
title: How to set up Emacs to open read-only depending on file location
published: true
description: Based on the file name pattern, open it in read-only mode with Emacs.
tags: emacs
---

In order to prevent accidental editing of a file when opening a library of virtual environments such as virtualenv, if you change the Emacs setting, you can open it automatically in read-only state without executing C-x C-q.

An example of setting targeting pyenv's directory is as follows.

```elisp
(add-hook 'find-file-hook
		  (lambda ()
			(dolist (pattern '("~/.pyenv/versions/.*"
							   ;; add here
							   ))
			  (if (string-match (expand-file-name pattern) buffer-file-name)
				  (read-only-mode)
				))))
```
Learning to think like a programmer.
Tags: discuss
Published: 2018-07-21 16:03:12

---
title: Learning to think like a programmer.
published: true
description: 
tags: discussion
---

I’m looking for a book (video, blog, or online course) for Somebody who just learned their  first language. They know the “words”, but what will help them to write “poetry” - solve problems using computer programming? Ideally, this book will teach them the art of thinking like a programmer. It will teach them techniques to approach a problem, analyze it, come up with a solution, validate and troubleshoot it. Think whiteboard sessions at an interview.

I’m not looking for a book that concentrates  on teaching a specific language like python or c++. Preferably such book assumes minimum computer science knowledge and should heavily use pseudo code, flow charts, diagrams or other ways to generalize concepts, but if it chooses a language to show implementation, that’s OK too. As long as the language is not the main topic.

What was your favorite book, video or lesson to learn thinking in code?
My Software Development Toolkit. What is yours?
Tags: software, coding, development, tools
Published: 2018-07-19 02:58:42

---
title: My Software Development Toolkit. What is yours?
published: true
description: 
tags: software, coding, development, tools
---

Below is the list of my ultimate tool-set on my Mac that I use on a day to day basis as part of software development.

**RoboMongo/Robo 3T**
If you happen to use Mongo database in your application, RoboMongo is a GUI tool that you need. It is very handy to query database and maintain connection to different environments.

**AWS Workspace**
If you use a Mac or Linux machine but for some project you need Windows for C#, MS-SQL related application, AWS Workspace is the tool you need to add into your kit. AWS charges you for the amount of time machine is running in Amazon cloud and auto stops after certain time you configure i.e. you don't get charged unless you are using it. 

**Microsoft Remote Desktop**
If you want to RDP to windows server running in the cloud this is your tool. Very neat and easy to understand UI.

**TunnelBlick**
VPN client

**Viscosity**
VPN client

**Docker**
Running containers of different applications.

**Zsh**
A very powerful interactive Unix-Shell.

**Hyper**
Beautiful piece of software written in Javascript. You can configure it to use any theme you want and impress your co-workers :)

**Dashlane**
Password manager

**Slack**
Communication with team

**Microsoft OneNote**
Taking notes. I like it more because it syncs with One-Drive.

**Visual Studio Code**
For Python and JS. Tip: Don't forget to install MagicPython extension in VS code.I also use docker plugin from VS marketplace to manage containers.

**Android Studio**
If you are working on Android apps this is a no brainer.

**Franz**
During the day I quite frequently check Slack, Hangouts, Skype, Gmail. I keep them all integrated under Franz so it's easy to manage.

**file.io**
To share files securely. One of my co-worker introduced this to me and I totally love it since then. It generates one time click link for you which you can pass along to share.


That is my list. Please share yours.


Cheers. Happy Coding.
Snippets for Vanilla JS Coding
Tags: javascript, dom
Published: 2018-07-21 10:49:58

---
title: Snippets for Vanilla JS Coding
published: true
description: 
tags: javascript, dom
---

When coding in VanillaJS, I usually create shortcuts for `document.querySelector` and `document.querySelectorAll`. I also like to declare `D` as a shortcut to `document`:


```js
const D = document
const $ = D.querySelector.bind(D)
const $$ = (selector, startNode = D) => [...startNode.querySelectorAll(selector)]

```

It's also good to know that the `$` and `$$` functions are already built-in aka [Command Line API](https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference) when you open the JS console in Devtools. 

With that dollar functions, you can already use a syntax that is similar to jQuery:

```html
<button id="button">click me!</button>
```
```js
$('#button').onclick = () => {
  alert('You clicked me!')
}
```

If you want to play with multiple elements, the `$$` shortcut to `document.querySelectorAll` comes into play.


```html
<button> button 1 </button>
<button> button 2 </button>
<button> button 3 </button>
```
```js
$$('button').map(btn => {
  btn.style.backgroundColor = 'red'
})
```

When it comes to event handling, having an `on` method can be useful:

```js
Array.prototype.on = function(type, listener, options) {
  this.map(el => {
    if (el instanceof Element) {
      el.addEventListener(type, listener, options)
    }
  })
  return this // for chaining
}
```

This way, you can register multiple event handlers on multiple elements at once:

```js
$$('button').on('click', e => {
  const btn = e.target
  alert('You clicked ' + btn.textContent)
}).on('mouseover', e => {
  const btn = e.target
  btn.style.backgroundColor = 'red'
}).on('mouseout', e => {
  const btn = e.target
  btn.style.backgroundColor = 'blue'
})

```
TIL: Standard Layouts of tmux
Tags: tmux, layout, todayilearned
Published: 2018-07-21 10:10:52

---
title: TIL: Standard Layouts of tmux
published: true
description: This is a basic showcase of the standard layout of tmux
tags: tmux, layout, todayilearned, til
---

# Standard Layouts of tmux

I can never remember these, so here goes

`PREFIX-"meta + 1"`

```
+-------------------+
|    |    |    |    |
|    |    |    |    |
|    |    |    |    |
|    |    |    |    |
|    |    |    |    |
|    |    |    |    |
|    |    |    |    |
+-------------------+
```

`PREFIX-"meta + 2"`

```
+-------------------+
|                   |
+-------------------+
|                   |
+-------------------+
|                   |
+-------------------+
|                   |
+-------------------+
```

`PREFIX-"meta + 3"`

```
+-------------------+
|                   |
|                   |
|                   |
|                   |
+------+------+-----+
|      |      |     |
|      |      |     |
+------+------+-----+
```

`PREFIX-"meta + 4"`

```
+-------------+-----+
|             |     |
|             |     |
|             +-----+
|             |     |
|             |     |
|             +-----+
|             |     |
|             |     |
+-------------+-----+
```

`PREFIX-"meta + 5"`

```
+---------+---------+
|         |         |
|         |         |
|         |         |
+---------+---------+
|         |         |
|         |         |
|         |         |
+---------+---------+
```

Originally posted in [my TIL collection](https://jonasbn.github.io/til/)
Orchid 0.9.0 Now Available
Tags: showdev, orchid, static, webdev
Published: 2018-07-18 16:54:05

---
title: Orchid 0.9.0 Now Available
published: true
description: Orchid 0.9.0 Now Available
tags: ['showdev', 'orchid', 'static', 'webdev']
---

I just released Orchid 0.9.0, a major update of the brand-new JAMstack framework for Java and Kotlin! This update adds many new features, like new Accordion and Tag tags, and greatly improves many existing features, like Github Pages deployment. 

If you haven't heard of Orchid yet, I'd encourage you to follow along with my tutorial series here on Dev.to, where I walk you through the process of building your own beautiful and unique website using Orchid.

{% link https://dev.to/cjbrooks12/your-first-orchid-site-4lij %}

Here are some more helpful links to get you started working with Orchid.

- [Homepage](https://orchid.netlify.com/)
- [Github Repo](https://github.com/JavaEden/Orchid)
- [Wiki](https://orchid.netlify.com/wiki/user-manual)
- [0.9.0 Release Notes](https://github.com/JavaEden/Orchid/releases/tag/v0.9.0)
- [Plugins](https://orchid.netlify.com/group/plugins)
- [Themes](https://orchid.netlify.com/group/themes)
How to make good code reviews and win colleagues?
Tags: codereviews, productivity, programming, culture
Published: 2018-07-21 07:02:58

---
title: How to make good code reviews and win colleagues?
published: true
description: 
tags: #codereviews #productivity #programming #culture
---

Code reviews do not only improve the quality of code but are a great tool to learn from others and share experience. Doing and having code reviews is not an easy task. Pointing to or criticising your colleagues and peers is not something someone would like to do daily. Therefore, doing it in a constructive and positive manner would be beneficial to both the reviewer and reviewee.

####Prepare:
1) Adhere to coding guideline or make one with your team members.


####Use the right words:
2) Avoid using negative words and comments like "Remove", "Change", "Not needed", "No", "Bad", "I don't like this" etc...
3) Don't use sarcasm.
4) Avoid referring to code as "mine", "yours", or "theirs".
5) Ask questions instead of giving orders. Use questions like "Do you think this would be better?", "What do you think about...?"
6) Be positive. Don't say words like "I didn't do this", "It wasn't me" etc...


####Clarify:
7) Explain the reason behind your comment and how it will improve the code.
8) Express yourself clearly and provide arguments. If needed, link to other code snippets or PRs.
9) Ask for clarification if the code is unclear. If there are too many questions it would be better asking them in person.
10) Be clear in the feedback. If a lot of discussion is needed it can be done in a different session.


####Accept:
11) Learn from the comments and how others tackle the same problem.
12) Don't take it personal, code reviews are about the code and not you as a person.
13) Accept all feedback. Whether you are a Junior or Senior take feedback positively.
14) Be open to other ways of writing code or methods.
15) Don't turn the feedback into an ongoing argument. You can always talk to the commenter in person.


####Support:
16) Be supportive. Help by pair-programming or showing an example.
17) Be responsive. Provide more information or clarification in the same day or after one day.
18) Be quick. Don't leave too many Pull Requests open. The codebase will grow, and the PR will stay behind.
19) Give positive feedback when the PR is accepted, like using the Like emoji or saying words like "Great, well done".
20) If a feedback helps, inform the reviewer how you find that helpful. Use words like "Good catch, thank you" etc...


Having a constructive and positive code review will foster a healthy work culture and allow team members to express themselves freely without the worry of shame and negative feedback. This will create an environment where team members feel respected, valued and productive. At the end it will allow an agile environment, knowledge sharing and growth.
Stay up to date with what is happening on Github
Tags: github, redux, react, graphql
Published: 2019-04-21 15:21:53

---
title: Stay up to date with what is happening on Github
published: true
tags: github,redux,react,graphql
canonical_url: https://dev.to/arojunior/stay-up-to-date-with-what-is-happening-on-github
---

After hearing several times from some friends who do not use social networks the phrase “my social network is Github”, I decided to make a feed that brings the activities of who you follow in Github. From comments on issues, pull requests, starred repositories, commits and etc … For you to follow everything that is happening in the open source community.

![](https://cdn-images-1.medium.com/max/600/1*2WmnaXxc9Nt9sr6hZ-cklQ.gif)<figcaption>Awesome feed — <a href="https://awesomefeed.js.org/">https://awesomefeed.js.org/</a></figcaption>

The similar twitter's layout is totally intentional, considering that it is the preferred social network of the open source community.

It still needs to improve a lot, but since I’ve been working alone, it is walking slowly.

You can collaborate on: [https://github.com/arojunior/awesome-feed](https://github.com/arojunior/awesome-feed)

The tools used are basically: React, Redux, GraphQL, Styled-components and Recompose.

As always, suggestions are very welcome. I'll be waiting for pull requests.

[https://awesomefeed.js.org/](https://awesomefeed.js.org/)
Stage with confidence using git add -p
Tags: git, gitadd, gitaddpatch, github
Published: 2018-07-21 00:07:44

---
title: Stage with confidence using git add -p
published: true
description: Stage with confidence using git add -p and avoid committing/pushing undesired changes!
tags: git, git add, git add patch, github
---
From the official documentation
>
-p
--patch
Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.
This effectively runs add --interactive, but bypasses the initial command menu and directly jumps to the patch subcommand. See “Interactive mode” for details.

Said so, `git add -p` allows you to pick which chunks of code are going to be staged from all your current changes.

![git add -p](https://thepracticaldev.s3.amazonaws.com/i/lawlmn8xi2xm76ybtjoh.png)
![git status -v](https://thepracticaldev.s3.amazonaws.com/i/n4wofe0t28x514wbk7yc.png)

I use this all the time to avoid committing something unintended.
Try it!
200 days of coding
Tags: housekeeping, codingmilestone
Published: 2018-11-10 17:11:34

---
title: 200 days of coding
published: true
tags: housekeeping,coding milestone
canonical_url: 
---

![](https://testfbdotblog.files.wordpress.com/2018/07/img_20180720_1848261471532215198391185.jpg?w=620)

Long story short, today I completed 200 consecutive days of writing code. It most definitely deserved a special treat.