teleren/devto huggingface dataset:
Create table in Rails only if it does not exist already
Tags: rails, database, tips
Published: 2020-01-17 11:04:27

In Rails, we create the tables using the migrations. A typical create table migration looks like this.

```rb
create_table :repo_subscriptions do |t|
  t.string      :user_name
  t.string      :repo_name
  t.timestamps
end
```

If our database already contains `repo_subscriptions` table and we try to run above migration then we get an error.

You may be wondering when will you run into this situation 🤔? We have multiple Rails applications which share same database in staging  and production environment. But in development they do not share the database. So we need the migrations in all the applications for development but not in staging and production. This situation may also happen when working with legacy applications where tables already exist in production environment but not locally or in staging.

Rails provides a handy option `if_not_exists` that we can pass to `create_table`.

```rb
create_table :repo_subscriptions, if_not_exists: true do |t|
  t.string      :user_name
  t.string      :repo_name
  t.timestamps
end
```

This will ensure that Rails will attempt to create the table only if it does not exist already.

This option is supported from [Rails 6 onwards](https://github.com/rails/rails/pull/31382) so you need to be using Rails 6 to use it 😄

One more cool thing about this option is that adds the check for whether the table exists in database or not in SQL instead of checking it via Ruby code.

When we run above migration, it runs following SQL.

```sql
(3.3ms)  CREATE TABLE IF NOT EXISTS "repo_subscriptions" ("id" bigserial primary key, "user_name" character varying, "repo_name" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
```

----

This small trick helped us making sure that the migration did not fail and we didn't have to add any environment specific hackery!

If you want to know more about #Ruby and #Rails tips, [follow me on Twitter](https://twitter.com/_cha1tanya).
Kubernetes simply explained for beginners
Tags: kubernetes, devops, docker, beginners
Published: 2020-01-17 11:03:29

Kubernetes popularity rises constantly. So, **what is Kubernetes actually** and **what problems does it solve**?

With this short video I give a concise but thorough overview of

- What problems Kubernetes solves? Or why is there a need for a container orchestration tool?

- What features do container orchestration tools offer?

- Basic architecture: Master-Slave nodes, Kubernetes processes

- Basic concepts: Pods, Containers, Services. What is the role of each?

- and lastly show an Example Configuration

{% youtube VnvRFRk_51k %}


-----------------
► Get **30% off** - with this code: UDEMY_NANA_OCT2020: [Udemy course here](https://bit.ly/2IkzZez)
► **Kubernetes 101**: [Compact and easy-to-read ebook bundle 🚀](https://www.techworld-with-nana.com/e-books) 
It's a handy way to quickly look something up or refresh your knowledge at work and use it as your cheatsheet  😎

**Like, share and follow me** 😍 for more content:
- [Private FB group](https://www.facebook.com/groups/techworldwithnana)
- [Twitter](https://twitter.com/Njuchi_)
- [YouTube](https://www.youtube.com/channel/UCdngmbVKX1Tgre699-XLlUA?sub_confirmation=1)
- [Instagram](https://www.instagram.com/techworld_with_nana/)
- [LinkedIn](linkedin.com/in/nana-janashia)
Level up your Android dev skills with DroidUp Newsletter
Tags: newsletter, showdev, android, email
Published: 2020-01-17 11:03:18

---
title: Level up your Android dev skills with DroidUp Newsletter
published: true
description: A newsletter for Android Developers to level up their skills with handcrafted & curated resources by Wajahat Karim
tags: newsletter, showdev, android, email
cover_image: https://miro.medium.com/max/2500/1*oQfiBU6GaSB15kqKoUi0cQ.png
---

👐 Hey folks!

🔥 I am starting a newsletter called DroidUp. This is a newsletter for Android Developers to learn about the latest things, tips, and skills in Android development manually handcrafted and curated by me.

🙏 I need your support in bringing an impact on the community through this newsletter. So, sign up now and get excited about the first issue.

👉 Subscribe it on this link: https://wajahatkarim.substack.com/

In the meantime you subscribe, please share this with your friends and colleagues. It means the world to me.
¿WhoUr? A Tool for information gathering, IPReverse, AdminFinder, DNS, WHOIS, SQLi Scanner with google.
Tags: python, security, tool, pentesting
Published: 2020-01-17 10:53:22

About two years ago I created a tool written in python to obtain information from web pages and search for possible sql vulnerabilities using google, I will be taking up this project so I decided to publish it again and right here keep a change-log of this tool.

##WhoUr

WhoUr is a simple tool in python for getting info of a website and scan SQLi vuln with google. this is fast but is not powerful, actually is under construction, but is usefully.

https://www.sealdeal.net/whour-a-tool-for-information-gathering-ipreverse-adminfinder-dns-whois-sqli-scanner-with-google/
CrunchConf 2019 - From Zero to Hero with Kafka Connect
Tags: techtalks, apachekafka, crunchconf
Published: 2020-01-17 10:44:04

In October last year I had the pleasure to speak at CrunchConf about Apache Kafka's integration API, called Kafka Connect. 

{% youtube q6NWpOS8nxY %}

Check out the slides here: [From Zero to Hero with Kafka Connect](https://rmoff.dev/crunch19-zero-to-hero-kafka-connect)

Fun fact: Crunch Conf is held in a train museum! 

![Trains at CrunchConf](https://thepracticaldev.s3.amazonaws.com/i/or9m7ma02j68mzhpv5x9.jpeg)
Choosing third-party Angular components
Tags: angular
Published: 2020-01-17 10:30:33

Hello everyone,

I work in a UI component vendor and I wish to know more about the needs of Angular developers outside our community.

If you have evaluated third-party Angular components for a production application, then I invite you to tell me about it in a remote session in exchange for a $50 Amazon gift card.

I confirm I am not trying to sell you anything or recruit you.

- We will discuss how did you research and decide which components to use (or possibly, implement your own).
- The remote session will last about 30 minutes.
- Your component evaluation should have happened in the last year.

Your insights will be valuable and you may influence our roadmap decisions.

If you are interested, please contact me by January 31, 2020 at dimodi {at} gmail.com.

Regards,
Dimo
mozilla firefox keyboard shortcuts
Tags: mozilla, firefox, browser
Published: 2020-01-17 10:26:25

ive been using ctrl+pgup & ctrl+pgdn keyboard shortcuts to move between mozilla firefox tabs for years but only just discovered alt+1 and alt+9 (even if you have 20 tabs) to move to first and last tab (see previous post) !

you can read about 100s of other shortcuts here
* https://support.mozilla.org/en-US/kb/keyboard-shortcuts-perform-firefox-tasks-quickly#w_windows-tabs
Animations in React 2020 - react-spring
Tags: javascript, react
Published: 2020-01-17 10:14:26

Lately I've been working with animations in React and react-spring. There are many animations libraries out there but currently react-spring seems to be one of the most popular ones and for a good reason. I really like the hooks api since it plays very well into the remaining of my code that is also using the hooks syntax.

I have tried to create some more intermediate and advanced animations using react-spring (not just a simple fade/slide) and created YouTube videos showing how: 

https://www.youtube.com/watch?v=kNH95mlNJd8&t

Let me know if they are useful to you if you're getting started with animations in React or if there are other libraries out there that looks exciting for animations in React here in 2020.
How to create a favicon and add them to your Django site
Tags: django, webdev
Published: 2020-01-17 09:57:58

![django website](https://66.media.tumblr.com/6c8ba59892761dbb37218e3ab364047d/b6c8b915ad30d963-02/s1280x1920/a147d806ceb89b50f6cd3f4dd4a5f00c262b66dc.jpg)

Favicon icons help users to identity a certain website, not only in the browing tab of our browsers, but also in some search engine results pages (SERPs).
We’ve written a post about [how to create a favicon and add them to your Django site](https://apijack.com/resources/post/django-favicon-instructions/).
should DEV.TO be banned from 9am to 5pm ?
Tags: devto, webdev, distraction
Published: 2020-01-17 09:52:08

ive just spent the last hour browsing such great articles on DEV.TO and havent even started todays project - 'you' the DEV.TO community are just TOO good ! (reminds me of the good old ning and vox days)

the irony is that i was on DEV.TO in the first place to find relevant articles and i have found some VERY relevant ones but i also clicked on dozens of SEE ALSO links 

MAYBE i should create a feature request to block SEE ALSO links between 9 and 5 ? would that be the answer ? OR i could create browser extension to block them ? NOOOOOO that would be another distraction
a nasty git alias hack
Tags: git, github, hack, bash
Published: 2020-01-17 09:42:50

a nasty git bash alias hack

DO NOT DO THIS IN THE REAL WORLD

create a file `~/.bash_aliases`
```
$ cat ~/.bash_aliases 
alias ga="git add ."
alias gc='git commit -m "autocommit"'
alias gd="git diff"
alias gp="git push"
alias gs="git status"
```

now you can add commit and push with 6 chars
```
$ ga
$ gc
$ gp
```

# WARNING 
FOR RAPID PROTOTYPING USE ONLY 
this is a sackable offence in many outfits as it creates meaningless commit messages :grin:
image processing cloudinary v imagekit apis
Tags: imageprocessing, api, images, webdev
Published: 2020-01-17 09:26:48

i have just uploaded a VERY (!) low res image of last weeks lunar eclipse (btw with a mobile it looks the same as a normal moon) to cloudinary and imagekit so i can compare the results of their image processing apis

RAW (should be identical !)
moon on cloudinary
![the moon](https://res.cloudinary.com/osde8info/image/upload/v1579252702/IMG_20200110_185704_isfjnk.jpg)
moon on imagekit
![the moon](https://ik.imagekit.io/0h2y0y2rw/IMG_20200110_185704_fRq74Iq_2.jpg)

PROCESSED (can we see a difference ?) 
moon on cloudinary 
TODO 
moon on imagekit 
TODO
Angular vs. React vs. Vue: A 2020 comparison
Tags: angular, react, vue
Published: 2020-01-17 09:18:16

A brief history of Vue vs React vs Angular
Before we get into the technical details, let’s first talk about the history behind these frameworks – just to better appreciate their philosophy and their evolution over time.


How it all started
 
<img src="https://iotvnaw69daj.i.optimole.com/w:141/h:146/q:90/https://mk0codeinwp10tp0961a.kinstacdn.com/wp-content/uploads/2019/01/angular-logo.png">
Angular, developed by Google, was first released in 2010, making it the oldest of the lot. It is a TypeScript based JavaScript framework. A substantial shift occurred in 2016 on the release of Angular 2 (and the dropping of the “JS” from the original name – AngularJS). Angular 2+ is known as just Angular. Although AngularJS (version 1) still gets updates, we will focus the discussion on Angular. The latest stable version is Angular 7, which was released in October 2018.

 <img src="https://iotvnaw69daj.i.optimole.com/w:141/h:122/q:90/https://mk0codeinwp10tp0961a.kinstacdn.com/wp-content/uploads/2019/01/vue-logo.png">

Vue, also known as Vue.js, is the youngest member of the group. It was developed by ex-Google employee Evan You in 2014. Over the last two years, Vue has seen a substantial shift in popularity, even though it doesn’t have the backing of a large company. The current stable version is 2.17, released in August 2018. Vue’s contributors are supported by Patreon. Vue 3, currently in the prototyping phase is planning to move to TypeScript.

 
<img src="https://iotvnaw69daj.i.optimole.com/w:141/h:132/q:90/https://mk0codeinwp10tp0961a.kinstacdn.com/wp-content/uploads/2019/01/react-logo.png">
React, developed by Facebook, was initially released in 2013. Facebook uses React extensively in their products (Facebook, Instagram, and WhatsApp). The current stable version in 16.X, released in November 2018.

 
Here’s a short summary of <a href="https://codersera.com/blog/angular-vs-react-vs-vue/">Angular vs React vs Vue,</a> in terms of their status and history:

The history of Angular vs React vs Vue.

<img src="https://codersera.com/blog/wp-content/uploads/2020/01/angular_react_vue.png">

<B>Job market for Angular vs React vs Vue</B>

<img src="https://codersera.com/blog/wp-content/uploads/2020/01/Jobs.png">
Keeping Javascript test naming updated after refactoring
Tags: javascript, testing, refactoring
Published: 2020-01-17 09:11:02

Some days ago I ran into a problem. I [refactored](https://en.wikipedia.org/wiki/Code_refactoring) (simply renamed) some Functions and faced the situation, that I also had to update all the names in my tests, too... manually!

This is because I did not assigned the Functions a proper name, when I created them as a property of something else:

```javascript
export const Utils = {}

Utils.isDefined = function (obj) {
  return typeof obj !== 'undefined' && obj !== null
}

// ...
```

In the tests I then wrote the function name by hand:

```javascript
import { Utils } from '../Utils.js'

describe ('Utils', function () {
  describe ('isDefined', function () {
    // ...
  })
})
```

Now later I realized, that the name `isDefined` is somewhat wrong picked and I refactored it to `exists`:

```javascript
Utils.exists = function (obj) { 
  return typeof obj !== 'undefined' && obj !== null
}
```

Well, my tests were not covered by the update and still were outputting the old `isDefined`:

```bash
Utils
  isDefined
    ✓ ...
```

I was thinking "how could I make my test automatically reflect my Function's namespaces?" and luckily (since ECMA2015) there is a nice way to always get a Function's name, using the `name` property:

```javascript
import { Utils } from '../Utils.js'

describe ('Utils', function () {
  describe (Utils.exists.name, function () {
    // ...
  })
})
```

This will always be the Function's name, because it references to it and is thus covered by the refactoring. Keep in mind however, that in the current state of this code there will be **nothing** returned as name. This is because the Function simply has no name, yet. To do so we need to declare not only the property but also the Function name:

```javascript
Utils.exists = function exists (obj) { 
  return typeof obj !== 'undefined' && obj !== null
}
```

and the tests are then automatically reflecting the naming:

```bash
Utils
  exists
    ✓ ...
```

Simple tweak with a great reduction in follow-up work here. For those of you, who think this would then require to double rename (property and Function name) then I encourage you to try out with your IDE: usually you should just have to refactor-rename one of them to trigger the refactoring of both.

Note, that in order to make this work with [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), you need to declare them as variables:

```javascript
const exists = (obj) => typeof obj !== 'undefined' && obj !== null
Utils.exists = exists
```
Django vs. Flask: Which Python Web Framework to Choose?
Tags: python, webdev, django, tutorial
Published: 2020-01-17 08:58:37

When it comes to web development in Python, Django isn’t the only game in town. Flask is a scrappy young framework that takes a very different approach – whereas Django ships with tons of features ready and eager to be used, Flask provides a bare minimum feature-set with rock-solid extensibility and incredible flexibility. This talk, given by a web developer who has experience with both frameworks, takes a good look at the pros and cons for both Flask and Django. If you’ve ever felt that Django is too hard to learn, or too inflexible, this is the talk for you!

{% youtube JkMc56Xa3jE %}
Completing tickets - How long should it take? as a junior dev!
Tags: juniordeveloper, ruby, rails, react
Published: 2020-01-17 08:53:39

As a junior developer with less than a year experience in coding. How long should it take me to complete full stack tickets at work? 

e.g. a ticket has full features - graphql mutation, tests, frontend react modal, mutation, forms.

I have been in my first dev job for 3 months now but I still feel like I need guidance and I feel this pressure to deliver as fast as my colleagues with years of experience. A I missing something?
virtualbox VM user experience improvements 
Tags: virtualisatio, ux, webdev, vm
Published: 2020-01-17 08:38:45

oracle [virtualbox](virtualbox.org) VM user experience improvements 

* always install (& keep updated) virtualbox guest additons
* throttle cpu set execution cap to 85% instead of 100%

why the latter ? it seems daft !

because IMHO there is nothing worse than a frozen VM and although your VM runs slower at 85% it never appears to freeze like it does if is has access to the default setting of 100% CPU

why not try it and let me know if you can "feel the difference" !

tip 
open 20 ff tabs or run `npm update` to instantly get to 100% utilisation
JetBrains Mono
Published: 2020-01-17 08:24:00

For those who've missed: JetBrains released a new font. It's called "JetBrains Mono" and it's open-source as well. It supports ligatures, 143 languages (wide range of Unicode characters) and it looks good (imo).

It's going to be the default font in IDEA 2020.1 (and its "forks": AppCode, PyCharm, etc).

{% github JetBrains/JetBrainsMono %}

Demo, characters table, comparisons with other fonts, and more: [here](https://www.jetbrains.com/lp/mono/).
SOLID: Single Responsibility Principle in JavaScript
Tags: javascript, solid
Published: 2020-01-17 08:12:03

**SOLID** is an acronym referring to the SOLID Principles of class design that were popularized by Robert C. Martin.

Usually, these principles get applied to OOP languages that have classes. JavaScript is different in that it uses prototypal inheritance instead of classical inheritance. In the code samples, I will be using ES6 classes because I prefer the new syntax over the ES5 syntax.

## THE SINGLE RESPONSIBILITY PRINCIPLE

> "A class should have one, and only one, reason to change"  
> **Robert C. Martin**

The word **"class"** here can also be replaced by **"module"**, the point is that the Single Responsibility Principle (SRP) is not limited to object-oriented design.

The best way to understand the SRP is to look at some examples of code that violates this rule.

```javascript
/* Bad example */

class Employee {
  calculatePay() {
    //...
  }

  reportHours() {
    //...
  }

  saveToDB() {
    //...
  }
}
```

This class violates the SRP because it has more that one reason to change.  

Let's say that we wanted to change the **reportHours** method. To do this we have to change the code inside the **Employee** class, which means that we could potentially break some other methods in our class.

If you think about it, it makes no sense. Why should we be able to break
something that does not need to change?

This is where the SRP is important, it ensures that there is only "one reason to change". Robert C. Martin defines "only one reason to change" as "should only be responsible to one".

In this case, this means that the Employee class should be split up into smaller classes.

**This does not mean that the Employee class should only have one method, it can have many methods but it should only have on reason to change.**
¿js.apies.org who is? ¡Wordpress WebShell!
Tags: wordpress, webshell, php, security
Published: 2020-01-17 08:08:06

From time to time I get to check the log files of my servers (in which I have hosted several clients), there are times like this in which one comes to find surprises in how a WebShell for WordPress on an almost recently site installed.

https://www.sealdeal.net/js-apies-org-who-is-wordpress-webshell/
Getting Started with Docker
Tags: docker, devops, tutorial, beginners
Published: 2020-01-17 07:30:08

Docker is everywhere but maybe you aren't quite up to speed yet. You can talk about it or at least fake your way through a conversation but you haven't had time to get started actually using it yet. If that sounds like you, this is your session. We will walk through Docker from the beginning. Don't be fooled though. This isn't a PowerPoint session. We won't be doing fun pictures and abstract concepts. We will be taking code and putting it into containers. Then we will look at how to use those containers, how to communicate with them, how to manage them, and more. After we cover the basics, we will get into orchestration and other more complicated topics. While this is a language-agnostic talk, we will use the Visual Studio tools for some sites and situations.

{% youtube ahxJsLX-p6A %}
Cryptocurrency Pyramid Scheme To Be Investigated By Thai Officials
Tags: cryptocurrency, bitcoin, cryptocurrencytrading, cryptonews
Published: 2020-01-17 07:24:09

A case of cryptocurrency pyramid scheme has been forwarded to the Department of Special Investigation of Thailand by a human rights lawyer. According to the Bangkok Post, 20 victims suffered the loss of 75 million baht are looking up to go beyond the investigation of local police of Krabi province in Thailand. 
Working independently of the Thai Royal Police Force, The DSI, a department of the Thai Ministry of Justice has been tasked with taking care of special cases, including criminal network cases that threaten national security. 
Victims Get Duped With a Promise of 8% Returns

According to reports, the alleged pyramid scheme naming ‘’Khung Nong cryptocurrency Trading’’ was operating since 2018 in Krabi province. Duped with the promise of 8% returns, the locals of Krabi, Yala, Trang, Narathiwat and Pattani falsely became the victim and sold off their essential belongings, including cars, motorcycles and even private land in the purpose of raising their money for making investments.

Read Out More 👉 https://www.cryptoknowmics.com/news/cryptocurrency-pyramid-scheme-to-be-investigated-by-thai-officials
Neumorphism (soft UI) sass mixin
Tags: css, productivity, uiweekly, ux
Published: 2020-01-17 07:11:03

Just a little sass mixin to help implement neumorphism or soft ui styling. It take a color and set box-shadows based on that given color.

{% gist https://gist.github.com/wingleung/b0605296286ef18a6cd91c06177d3379 %}

### What is neumorphism?

"The neomorphic effect is a combination of the current famous flat UI and the old skeuomorphic principles! The components have a dark box-shadow on the bottom and a light box-shadow on top; the combination of both creates the effect of the elements pushing themselves through your display." 
~ [Design trends: Neomorphic design
](https://medium.com/@s.jagoori/design-trends-neumorphism-59a9ba9d9284)

### Demo

{% codesandbox neumorphism-sass-mixin-kzc1o module=/neumorphic-mixin.scss %}
Rethinking Front-End Apps with SvelteJS
Tags: javascript, webdev, tutorial, beginners
Published: 2020-01-17 07:06:02

Svelte is a compiler which understands and converts code into native DOM API calls at build time. Svelte also introduces the concept of Reactive Programming within your components along with patterns that reduce the overall LOC that you end up committing. Speaker Umang Galaiya explains how Svelte allows developers to write components in a way similar to developers first started writing HTML when doing web development.

Since everything is converted to native DOM API calls and not shipping a runtime to the user, apps built with Svelte are faster than those shipped with a runtime (like React or Vue). Svelte also brings in built-in, first-class support for CSS animations and transitions. Therefore developers don’t need to import other libraries into their app to get transitions working.

In this talk, Umang Galaiya introduces the ideas behind Svelte and Svelte itself. He walks audiences through an introductory idea about Svelte and the patterns Svelte introduces. This talk will help developers to experiment with and write performant Svelte components.

{% youtube _GgD_tJAWuE %}