teleren/devto huggingface dataset:
Mod 1 Project
Tags: ruby, rails, productivity
Published: 2020-02-13 14:35:14

---
title: Mod 1 Project
published: true
description: flatiron school bootcamp mod 1 project blog
tags: ruby, rails, productivity 
---
# Summary
Mod 1 here at //flatiron school is nearing completion and that means a project; and blogs.
Here are the requirements for the project
1. Use ActiveRecord
2. Make use of at least 2 `has_many` models and 1 `belongs_to` model
3. Pull in at least 1 API into our app
4. App is to run in terminal, nothing too fancy ... yet ;)

# Details
The group I am a part of choose to make a recipe builder. The premise is a protein and a vegetable are selected and the app pulls in data from an API to search recipes with those two ingredients. We then can choose that recipe or not. There's functionality to update the protein and vegetable lists as well as save recipes for later.

# User stories
The app had to have at least 1 CRUD methods each in the form of user stories.

_Create_
"As a user, I want to choose a protein and a vegetable so that I can be given a choice of recipes."

_Read_
"As a user, I want to be able to select from a list of saved recipes."

_Update_
"As a user, I want to be able to update my protein, vegetable, and recipe list."

_Delete_
"As a user, I want to be able to remove proteins, vegetables, and recipes from my lists."

# Regex "fun"
I took on the task of taking the text dump from the API for recipe instructions and making it display it in a reasonable and repeatable manner. After testing I noticed the text was showing up in only 3 different patterns; this was great as it simplified what I was going to do with regex. Now I am not a regex expert (noob, I'm a noob). Here is what I came up with.  
```ruby
text = recipe_hash["recipes"][0]["instructions"]
i = 1
        
# each group will make an ordered list
# from the lump of text provided by the API

# newline used lump return
if text.scan(/$/)
  while i < text.scan(/$/).count do
    puts "#{i}. #{text.split(/$/)[i][1..-1]}"
    i += 1
  end 
end 

# ordered list, not formatted lump
if text.scan(/\d\./)
  while i < text.scan(/\d\./).count do
    puts "#{i}. #{text.split(/\d\./)[i]}"
    i += 1
  end
end 

# remove html tags
# replace line items with ordered list number
if text.scan(/<ol>/)
  text_array = text.gsub(/<\/li>|<ol>|<\/ol>|<\/html>|<\/body>/,'').split(/<li>/)
  while i < text_array.length do
    puts "#{i}. #{text_array[i]}"
    i += 1
  end 
end
```
Daily Challenge #186 - Jumping Frog
Tags: challenge
Published: 2020-02-13 14:31:59

---
title: Daily Challenge #186 - Jumping Frog
published: true
series: Daily Challenge
description: Implement a function to help a frog jump across the pond. 
tags: challenge
---
###Setup
There is a lonely frog that lives in a pond. Lily-pads are laid out on a coordinate axis atop the pond. The frog can only jump one unit more than the length of the last jump. 

With a starting point of 0, reach the target point of `n` using the frog's jumping ability. You can choose to jump forward to backward. Reach the target with the minimal amount of steps. 

###Examples
For `n = 2`, the output should be `3`.
<pre>step 1:  0 ->  1  (Jump forward, distance 1)
step 2:  1 -> -1  (Jump backward, distance 2)
step 3: -1 ->  2  (Jump forward, distance 3)</pre>

For `n = 6`, the output should be `3`.
<pre>step 1: 0 -> 1  (Jump forward, distance 1)
step 2: 1 -> 3  (Jump forward, distance 2)
step 3: 3 -> 6  (Jump forward, distance 3)</pre>

###Tests
`n = 1`

`n = 10`

`n = 25`

`n = 100`

`n = 1000`

Good luck!
***
_This [challenge](https://www.codewars.com/kata/5954b48ad8e0053403000040) comes from myjiinxin2015 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!_
List Your Yarn Scripts Real Quick!!!
Tags: yarn
Published: 2020-02-13 14:31:23

---
title: List Your Yarn Scripts Real Quick!!!
published: true
description: 
tags: yarn
---

_Do **YOU** write lots of yarn scripts?_

_Do **YOU** sometimes give them easy-to-forget names?_

_Have **YOU** ever wanted to list all your yarn scripts from the terminal?_

Well, now you can!

***

Hi, my name is Boots, and I use yarn for no reason in particular.

I often write yarn scripts, because they are basically like poems of the frontend development world.

I write so many yarn scripts that I often forget their names.

Am I doomed to crack open my `package.json` just to look them up?

**NO!**

All I gotta do is type:

```sh
yarn run
```

Because if you don't pass a script name to `yarn run`, it'll list all your scripts. Like this:

![Example output from yarn run](https://dev-to-uploads.s3.amazonaws.com/i/jmwjgui1zveischeuqx0.png)

Wow! So cool.
How to Join a Background Image and Background Color Together Using CSS
Tags: css3, latestposts, after, before
Published: 2020-02-13 14:37:51

---
title: How to Join a Background Image and Background Color Together Using CSS
published: true
date: 2020-02-13 14:30:05 UTC
tags: CSS3,Latest Posts,::after,::before
canonical_url: http://robdoylecreative.com/how-to-join-a-background-image-and-background-color-together-using-css/?utm_source=rss&utm_medium=rss&utm_campaign=how-to-join-a-background-image-and-background-color-together-using-css
---

Learning how to join a background image and background color together using CSS is a valuable skill. Have you ever been given the task of converting a PSD file into HTML and found the image assets did not always fit your needs?. This will often require the intervention of custom CSS to solve the problem. […]

The post [How to Join a Background Image and Background Color Together Using CSS](http://robdoylecreative.com/how-to-join-a-background-image-and-background-color-together-using-css/) appeared first on [Rob Doyle Creative](http://robdoylecreative.com).
defer
Tags: go, beginners
Published: 2020-02-13 14:19:28

In the <a href="https://golang.org">Golang</a> programming language you can use the defer statement. A defer statement defers the execution of a function until the surrounding <a href="https://golangr.com/methods/">function</a> returns. 

So in practice, that means first finish the current function before executing the deferred function.

## Examples 

The program below is a go program that imports the "fmt" module for output and then calls the Println function twice. It uses the defer statement;

```go
package main

import "fmt"

func main() {
	defer fmt.Println("world")
	fmt.Println("hello")
}
```

The deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns.

Instead of the output "hello world", it outputs:

```
hello
world

Program exited.
```

The Println function "world" is only called once the function main is finished.

## Defer

If you would extend the function with several calls, it will output world last. The program remains in normal execution order.

```go
package main

import "fmt"

func main() {
	defer fmt.Println("world")
	fmt.Println("hello")
	fmt.Println("there")
	fmt.Println("the")
}
```

You can defer more than one function call, then all the deferred functions are executed after the main cycle has completed:

```go
defer fmt.Println("world")
defer fmt.Println("hello")
defer fmt.Println("there")
fmt.Println("the")
```

**Related links:**
* <a href="https://golangr.com/defer/">Defer statement</a>
* <a href="https://golangr.com/">Learn Go</a>
Database High Availability in Old Days
Tags: database, highavailability, cluster
Published: 2020-02-13 14:05:45

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/30vzmh054462fwewcyzx.png)

In old days, under the pressure of budge, we decided to utilize open source HA solution for the production database system.

I struggled to install Linux packages and find the right version dependencies between packages. After writing the configuration files for each layer like corosync, pacemake, and hearbeat, I tested individual layers and then all layers together. This had ran on the production for quite a while.

Nowadays DBaaS is really good to lighten the burden of setup.
Help with DEV Quotes and Jokes
Published: 2020-02-13 13:59:29

Hello,

A while ago I created and shared an API containing fun or inspiering DEV Quotes and Jokes - https://funquote.herokuapp.com/quotes ( to see the full list).

I want to make the list as big as possible ( at least double it current size of 230 items).

Can you please help?

I cannot find good quotes or jokes anymore. Please share some links if you have any.

Thank you

P.S. Maybe before sharing you can check if the quote is not already there
python hashing
Tags: python, beginners
Published: 2020-02-13 13:56:53

In <a href="https://python.org">Python</a>, as in many other languages, you can make use of a <a href="https://en.wikipedia.org/wiki/Hash_function">hash function</a>. A hash function is a one way <a href="https://pythonbasics.org/functions/">function</a> that takes input of a variable length ( a byte <a href="https://pythonbasics.org/strings/">string</a> ) and converts it to a fixed length sequence. 

So if f is a hashing function, calculating f(x) is easy but the other way around will take years and years. Please note that hashing is not encryption, it doesn't make use of (private) keys.

![hash function](https://dev-to-uploads.s3.amazonaws.com/i/gp5fne9ssmkewlukas79.png)

This is very useful when you want to store passwords on a computer, to prevent leaks you hash them. In practice this doesn't always happen, and some companies store passwords in plain text which is a security risk.

Before playing with hashing, you should know the <a href="https://pythonbasics.org">basics of Python</a>

## Example

Example: if you use the <a href="https://en.wikipedia.org/wiki/SHA-2">sha256</a> hashing function, with several inputs:

*"Hello world"* hashed becomes 
```
'64ec88ca00b268e5ba1a35678a1b5316d212f4f366b2477232534a8aeca37f3c'.
```

If instead you use *"Hello World"* (capital W) you get:
```
'2161447856ce2af91e8b7efa6cfbad572f775609925f492e962ba8a7408d6b19'
```

So a small change in input is a large change in output. In Python you can do hashing with the module hashlib. 

```python
>>> import hashlib
>>> m = hashlib.sha256()
>>> m.update(b"Hello World")
>>> m.hexdigest()
```

There are many hashing algorithms, to see the ones included with your hashlib version type

```python
>>> import hashlib
>>> print(hashlib.algorithms_available)
{'blake2b512', 'shake_256', 'sha3-224', 'blake2s256', 'sha3-512', 'shake256', 'sha3-256', 'shake128', 'sha3_224', 'sha1', 'sha512', 'sha512-256', 'sha224', 'blake2b', 'shake_128', 'sha384', 'md5-sha1', 'md4', 'sha512-224', 'whirlpool', 'sm3', 'md5', 'sha3-384', 'sha3_256', 'sha256', 'sha3_384', 'sha3_512', 'blake2s', 'ripemd160'}
>>>
```

If you run the code below, you'll see a different hash for the same output, because they are different hashing algorithms.

```python
>>> print(hashlib.md5(b'Hello World').hexdigest())
>>> print(hashlib.sha1(b'Hello World').hexdigest())
>>> print(hashlib.sha224(b'Hello World').hexdigest())
>>> print(hashlib.sha256(b'Hello World').hexdigest())
>>> print(hashlib.sha384(b'Hello World').hexdigest())
>>> print(hashlib.sha512(b'Hello World').hexdigest())
>>> print(hashlib.blake2s(b'Hello World').hexdigest())
```

Be careful with using md5 and sha1 as they are <a href="https://it.slashdot.org/story/16/01/08/1427225/deprecation-of-md5-and-sha1----just-in-time">deprecated.</a>

**Related links:**
* <a href="https://docs.python.org/3.8/library/hashlib.html">The hashlib module</a>
* <a href="https://pythonbasics.org">Learn Python</a>
THIS IS UNSAFE (and a Bad Idea)
Tags: chrome, security, ssl
Published: 2020-02-13 13:49:27

---
title: THIS IS UNSAFE (and a Bad Idea)
published: true
description: Chrome be quirky
tags: chrome, security, ssl
---

I'm sure most of us are familiar with this screen in Chrome:

![Connection Not Private Warning In Chrome](https://dev-to-uploads.s3.amazonaws.com/i/m0a8ey0teb7i9psaot0k.jpeg)

This is the warning you get in Chrome when you visit a site with an invalid or expired certificate.

Typically, you just have to click "Advanced" then "Proceed" and everything's fine...Unless you're on a new-ish Mac! As of macOS Catalina, for certain SSL errors, there is no "Proceed" link.

So, poking around the internet, I found the workaround... Are you ready?

You type "[thisisunsafe](https://support.google.com/chrome/thread/16648034?hl=en&msgid=17568038)" while on the page, and it redirects you to the site.

After a little more digging, a likewise bemused colleague found that you used to be able to type [badidea](https://stackoverflow.com/questions/35274659/does-using-badidea-or-thisisunsafe-to-bypass-a-chrome-certificate-hsts-error/35275060).

This works cross-platform, and even when you can click "proceed." So, for those of you who dislike taking your hands away from the keyboard, it could come in handy (pseudopun intended).

Use with caution!

***

_Screenshot borrowed from [Google Support](https://images.app.goo.gl/28ZHDwXKbsmosfG78)_
My experience with TDD and how to implement it in a project
Tags: tdd
Published: 2020-02-13 13:48:59

Hi,

TDD (Test-Driven Development) is a development technique where a developer writes a certain number of tests to check or test the output of functional code he/she has written.

For example I might write a function to multiply two numbers. In TDD, I must write a number of tests first with the desired outputs based on all use cases and then write the function that must pass all the tests.

In traditional development a developer writes a function, then tests the output with desired inputs. Which is the complete opposite of TDD.

If, like me, you are used to the traditional way of development, it might take some learning to get used to TDD. 

However there are some available tools/frameworks like :
 -Mocha, Jasmine for JavaScript and 
 -Pytest or UnitTest for python

These tools help in the test automation process.

My personal favorite for JavaScript is Mocha. Mocha is open-source which is great. 

Let's go through the steps to install Mocha in your project.

Prerequisites:
-Nodejs v8.0.0 or newer
-npm

In your terminal, change the directory to your project's directory and type the following:

If you want to install mocha with npm globally:

<pre> $ npm install --global mocha </pre>

or if you want it as a development dependency for your project:

<pre> $ npm install --save-dev mocha </pre>

Now type the following lines to install mocha and create a new folder called 'test' and open a file named 'test.js' where we will write our test.

<pre>
$ npm install mocha
$ mkdir test
$ $EDITOR test/test.js # or open with your favorite editor
</pre>

In the test.js is where you will write your test.

Now, in your package.json file add this line under scripts

<pre>
"test": "mocha"
</pre>

Finally in your terminal type the following to test your function.

<pre>
npm run test
</pre>

As always, documentation always helps.

You may use other testing frameworks but for mocha, documentation can be found here: mochajs.org
I heard you like vector tiles...
Tags: unvt, vectortiles, docker
Published: 2020-02-13 13:37:50

Hi. I am Hidenori, Lead of the United Nations Vector Tile Toolkit (UNVT) under the [Working Group 4 of the United Nations Open GIS Initiative](http://unopengis.org/unopengis/what/what04.php).

I quickly show how to produce and host vector tiles using unvt/kawagoe, a UNVT setup for a scenario-based exercise of the [UN-GGIM WG-Disasters Conference 2020 in Tokyo](https://ggim-tokyo-2020.github.io/).

# Requirements
To follow the following vector tile produce / host process, you need the following computing environment. 

1. Docker
2. Ruby (to be more specific, `rake`)

# The process

```zsh
> git clone https://github.com/un-vector-tile-toolkit/kawagoe
> cd kawagoe 
> rake docker:run
$ cd kawagoe
$ rake produce:lc      # produce vector tiles of land cover data
$ rake build:localhost # build the site for localhost hosting
$ rake host            # run the server locally
# how you can browse http://localhost:9966 to see the web map
``` 

# Background Document
My UNVT colleague Taro M has a nice [slide deck](https://speakerdeck.com/smellman/distrubute-vector-tile) for JICA Training Course for National Surveying and Mapping in 2019.
Custom Cosmetic Boxes - Advantages and Disadvantages

Tags: customcosmeticboxes, cosmeticboxes
Published: 2020-02-13 13:32:46

<a href="https://boxesmaker.com/beauty/cosmetic-boxes.html">Cosmetic boxes</a> have been a part of the daily life of most people. It is no secret that we use these boxes as containers for items like food, cosmetics, perfume, and lotions to make the process of keeping these items away from dust and dirt easier. Custom cosmetic boxes have emerged as a way of doing business and making money.
So, what are the benefits of using custom cosmetic boxes? Well, firstly, they are much more expensive than bulk box products. These boxes are branded with high-quality labels for a reason - they are made using quality materials.

The best advantage of using custom cosmetic boxes is that it can easily be customized according to your requirements. Most businesses deal with packaging in bulk and have to use the same boxes over again. With these boxes, however, you can add your own labels to suit your business requirements.

Another benefit of using cosmetic boxes is that they are flexible. You can use them in any number of ways such as for example, it could be to keep envelopes, letters, or business cards. They can also be used as bathroom cabinets, cutlery trays, coffee glasses, napkin holders and display cases.
Another advantage of using custom cosmetic boxes is that they are a cheaper alternative. But there are some disadvantages as well. You will have to make sure that the boxes you use are of the highest quality that will allow them to last for long.
You can get these boxes from online stores that offer them. So make sure that you get these boxes from reputable and reputed stores.
In conclusion, you should buy custom cosmetic boxes from online stores. This will save you time and effort in searching for such a product. By buying them from online stores, you get a wide range to choose from, which in turn will increase your chances of getting a good deal.

Reference Source:
[https://boxesmaker.com/beauty/cosmetic-boxes.html]
Three mobile app ideas to build for fun
Tags: ideas, projects, ios, android
Published: 2020-02-13 13:26:16

I believe the best way to learn programming is to program. But it may be hard to know what to program. Because I have more [app ideas](https://github.com/nemecek-filip/App-ideas) than time and energy for executing them, I decided to share some of the ideas here.

They were initially conceived as iOS apps but there is nothing stopping you creating them for Android :-)

## Converter to animal units

There are tons of converters out there but that does not mean you cannot build another one that will stand out. I originally got this idea while doing Daily UI challenge which was to build interesting calculator if I remember correctly.

With this app, user could enter weight in kilograms for example and the app would show how much is that in elephants or lions or any other of your favorite animals. I wanted to include T-rex at first but there isn’t reliable data on its weight.

![Animal Units converter concept image](https://dev-to-uploads.s3.amazonaws.com/i/4m4v8jps7f6tbk5qjvlu.png)

Instead of finding suitable animal pictures you can use emoji with appropriate font size.

## Image compressor for sharing

Some chat apps do this automatically and some don’t. For users with constrained mobile data limits (or people travelling and using roaming) this could help a lot. You would select image/picture in phone’s gallery, it would open in this small app, users could select how much to compress and then “forward” the result to the chat app of their choice. 

Ideal project if you want to explore sharing, working with extensions and not having to spend a lot of time doing UI.

## Trip helper

For people who travel a lot. You would define your types of trips and specify what items to pack for each one. For simplicity bigger trips could easily include items from smaller trips to avoid duplication.

When preparing for a trip, the app would automatically create to-do list with all the items specified for current trip.

Main benefit is that users won’t have to create to-do lists over and over again for each trip.

_I have public repo on [GitHub](https://github.com/nemecek-filip/App-ideas) with those and other ideas. And I am trying to add new ones on at least monthly basis._
Git log pretty print aliases
Tags: git, bash, shell, alias
Published: 2020-02-13 13:26:14

---
title: Git log pretty print aliases
published: true
description: git log pretty print aliases
tags: git, bash, shell, alias
cover_image: https://thepracticaldev.s3.amazonaws.com/i/qobu36gh1f44gtuunqzs.png
---

A couple of git aliases for git log pretty print. Add them to your `.zshrc` or `.bashrc` for usage and source the file e.g.`source ~/.zshrc`, or restart your terminal for the changes to apply. 

## gitp - pretty print the last 10 logs
```bash
#Print latest 10 submit logs
alias gitp="git log --pretty=format:'%C(yellow)%h %Cred%ad  %Creset%s' --date=local --max-count=10"
# Usage
gitp
```
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/d0tgjd85r31mh8p89rtv.png)

## gitpp - pretty print all logs
```bash
#Print latest all submit logs
alias gitpp="git log --pretty=format:'%C(yellow)%h %Cred%ad  %Creset%s' --date=local"
#Usage
gitpp
```
Output the same as gitp but not limited to 10 commits


## gitpa - pretty print include author
```bash
# Include author
alias gitpa="git log --pretty=format:'%C(yellow)%h %<(24)%C(red)%ad %<(18)%C(green)%an %C(reset)%s' --date=local --max-count=10"
# Usage
gitpa
```
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/7he5z1h2n4voe1z1bugu.png)

## gitag - pretty print tags
```bash
#Print log information on tags
alias gitag="git log --no-walk --tags --pretty=format:' %C(yellow)%h %Cgreen%d  %Cred%ad  %Creset%s' --date=local"
# Usage
gitag
```
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/pshrd4qjpi44zkinngjp.png)

## gitbr - Provide minimal graphical display
```bash
#Provide minimal graphical display
alias gitbr='git log --oneline --decorate --graph --all'
# Usage
gitbr
```
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/buf949osyujf6v3kfqqp.png)

Used gitbr a lot in the passed but now use [tig](https://jonas.github.io/tig/) which does the same and more

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

Credit for these alias goes to https://github.com/usplitu