teleren/devto huggingface dataset:
How and when to add foreign key constraints
Tags: rails, showdev, tutorial, ruby
Published: 2019-04-14 15:33:12

---
title: "How and when to add foreign key constraints"
published: true
description: Quickly add foreign key constraints to improve database query performance
tags: rails, showdev, tutorial, ruby
cover_image: https://www.kcoleman.me/images/hand-connections.jpg
---

Many rails projects rely on application validation to ensure data integrity. With rails `presence` validation, you can require associations exist in order for an object to be saved. This works until it doesn't.

## Not having foreign key constraints

If a developer forgets to define a dependency option on a rails validation (e.g. `has_many :users, dependent: :nullify`), uses `#delete` instead of `#destroy`, or even manually deletes it via a query, and the associated rows will point to empty records. This isn't ideal, because now you can't reliably test if an association exist by seeing if the id exists.

```ruby
# good
puts "company exists!" if user.company_id

# bad - N+1 to load the company
puts "company exists!" if user.company.id
```

If the company is deleted, but the users are not deleted with the company, you might be accidentally invalidating your models, thus preventing you from saving any attribute changes!

```ruby
class User < ApplicationRecord
  belongs_to :company, required: true
end
user.company.delete
user.update name: 'kevin' # false - company is missing
```

wat. I can't save the name if the company isn't there?

## Adding foreign key constraints

In Rails 5, adding foreign key constraints was added to have the database protect the integrity of associated data. Once a foreign key constraint is defined, your database will not allow you to remove records that are required by other tables.

```ruby
add_foreign_key :users, :companies
```

<img src="https://raw.githubusercontent.com/KevinColemanInc/yeet_dba/master/yeet_dba.png" alt="logo of the yeet_dba gem" title="logo of the yeet_dba gem" />

A quick way to add foreign key constraints to your entire rails schema is to use the [yeet_dba](https://github.com/kevincolemaninc/yeet_dba) gem. `yeet_dba` includes rake tasks and generators that scan your entire database searching for columns missing foreign key constraints. If the data is valid, it can add the foreign key constraint speeding up your joins and where queries or if the data is invalid, it will help you resolve the problem.

By adding foreign key constraints to your database you reduce N+1 calls, improve join and where query performance, and prevent unexpected failures with missing associations.

### Further reading

- [lol_dba](https://github.com/plentz/lol_dba) - This gem helps find indexes that are missing, but not foreign keys.
- [Postgres foreign key guide](http://www.postgresqltutorial.com/postgresql-foreign-key/)
- [Rails foreign key constraints](https://www.kcoleman.me/2019/03/14/how-to-add-foreign-key-constraints-rails.html)
Maven or Gradle?
Tags: java, kotlin, maven, discuss
Published: 2019-04-14 14:54:03

---
title: Maven or Gradle?
published: true
description: 
tags: java,kotlin,maven,discuss
---

Currently, I am migrating from Java to Kotlin. One of the changes I am not making is to move from Maven to Gradle. This is something we should probably discuss company wide to do or not.

I am curious about your thoughts, which do you prefer: Maven or Gradle? What made you to move? Or did you switch back?
Fix neovim errors
Tags: vim, neovim
Published: 2019-04-14 14:40:04

---
title: Fix neovim errors
published: true
description: 
tags: vim, neovim
---

![image](https://user-images.githubusercontent.com/10719495/56094309-19e30500-5f0e-11e9-921f-6add35cba9fb.png)


From latest OSX update, some plugins started to not working. Especially, `deoplete` and `UltiSnips` show errors.

The reason may be missing Python3, so the following commands will fix them:

```
brew install neovim
pip3 install -U neovim
nvim

# in neovim
:UpdateRemotePlugins
```

If you still have troubles, run `checkhealth` in vim.

```
:checkhealth
```
After all I thought that making LP was enough in Strikingly
Tags: lp, landingpage, strikingly
Published: 2019-04-14 12:29:37

---
title: After all I thought that making LP was enough in Strikingly
published: true
description: I wanted to focus on product development, LP just wanted to get it out early
tags: LP, LandingPage, strikingly 
---

note: Start-up, individual developer who wants to bring product to market early is conditional on condition

▼ I made my LandingPage by Strikingly▼

<a href="http://bit.ly/2Iidshd" target="blank">
![](https://thepracticaldev.s3.amazonaws.com/i/yc5p5l2f12bx8a536o4c.jpg)
</a>

Strikingly
<https://strikingly.com>

## Wanted to focus on product development, LP wanted to get out anyway

This time, when I made a desktop app called Watari personally, I left the download link at first.

I decided to create a download page, thinking that "It is not good that the link of s3 is straight and put in place."

Requirements are

- [Most important] be able to make with minimal construction
- Know the number of pressing the download button (if you charge GoogleAnalytics)
- Make it easy to copy pages and create English version sites quickly
- Ability to set up your own domain

so

As a candidate

a. Make a slightly rich LP with Webflow (<http://webflow.com/>)
b. Write in html and Scss and hosting on firebase and github pages
c. Sticking only with FV and OGP

It became like this and it was Strikingly chosen.

## Price

Anxious price is ** $ 20 / month (Pro version) **
Now you can publish 3 sites (does not enter the Strikingly logo)
You can set your own domain.

If you pay in a year, it will be cheaper to $ 16 / month,
The direction of the app has changed
When it comes to saying "If you can register by LP, it will be easy?"

I'm thinking of making LP by myself and I pay monthly.

## But maybe I will graduate soon

I'm writing with the momentum of product launch, but maybe I wrote it above
"If you want to incorporate service functions into LP"
If you want to look richer, Strikingly is not enough.

If it is rich, let's create it in Webflow, and in-house service if the service is embedded.

I'm sorry I just wrote the momentum, I will return to the development of the service.
Bookmarks, Saves, Hearts, Stars, Claps
Tags: webdev, showdev, productivity
Published: 2019-04-14 12:07:59

---
title: Bookmarks, Saves, Hearts, Stars, Claps
published: true
tags: 
- webdev
- showdev
- productivity
description: I realized that I rarely use bookmarks, but I still bookmark interesting sites, projects, or tools.
canonical_url: https://www.silvestar.codes/articles/bookmarks-saves-hearts-stars-claps/
---

[![Bookmarks, Saves, Hearts, Stars, Claps](https://thepracticaldev.s3.amazonaws.com/i/a5j644zsyjanyybnaiei.jpg)](https://www.silvestar.codes/articles/bookmarks-saves-hearts-stars-claps/)

_This post was originally published on [silvestar.codes](https://www.silvestar.codes/articles/bookmarks-saves-hearts-stars-claps/)._

I realized that I rarely use bookmarks, but I still bookmark interesting sites, projects, or tools. I guess this is because my browser is displaying bookmarked pages first in the suggestions which could be very useful when you know only part of the title or a domain.

![Search bar with bookmark suggestions.](https://thepracticaldev.s3.amazonaws.com/i/r731nuj0lv73h5j0dqbo.png)

Since I am using only dozens of bookmarked links, I thought I could share the exported bookmark file with the community, before I clean them up. There are many interesting, useful, and not-so-useful links here. You could [download the file] or <a href="https://www.silvestar.codes/bookmarks/browser/" target="_blank">see it in your browser</a>.

If you think this list is enormous, you should see the export from my Pocket application. In fact, <a href="https://www.silvestar.codes/bookmarks/pocket/" target="_blank">you could see it here</a>. I started to save the links in 2012, and I stopped last year. During that time I have collected more than *two thousand* links. Some of them are outdated today, but some are evergreen. Some of them are rubbish, some of them are gold. The list is just too big to review it. The shocking part is that I have read a vast majority of those links. 😱

I like [to star GitHub projects], [save CodePens], [clap Medium stories], [like Tweets], and [love tracks], too. Also, I am an excellent follower: I follow more than 3000 authors on CodePen, Medium, and Twitter combined. If you write it and I read it, you will get notified about it. I also like to share all of my findings [on Twitter]. I must say this practice helped me a few times when I needed to find a specific article. But this happens very rarely. I still have not found a useful way how to benefit from these links yet, except acquired knowledge and experience. 🤷‍♂

Do you have a similar experience? Or is it just me? 🤔

[download the file]: https://www.silvestar.codes/bookmarks/bookmarks.zip
[to star GitHub projects]: https://github.com/maliMirkec?tab=stars
[save CodePens]: https://codepen.io/CiTA/pens/loved/?grid_type=list
[clap Medium stories]: https://medium.com/@malimirkeccita/has-recommended
[like Tweets]: https://twitter.com/malimirkeccita
[love tracks]: https://www.last.fm/user/maliMirkec/loved
[on Twitter]: https://twitter.com/malimirkeccita
React Native Loading Spinner Overlay
Tags: reactnative, webdev, andriod, ios
Published: 2019-04-14 10:29:08

---
title: React Native Loading Spinner Overlay
published: true
description: React Native Loading Spinner Overlay
tags: #reactnative #webdev #andriod #ios
---

Source : <a href="https://www.skptricks.com/2019/04/react-native-loading-spinner-overlay-example.html" >React Native Loading Spinner Overlay </a>

In this tutorial we are going to discuss how to display loading spinner overlay animation effect in react native application. You may have seen this kind of loading spinner overlay animation effect in various app like Flipkart, Amazon, Myntra, Snapdeal etc. We will use the react-native-loading-spinner-overlay library to make an overlay Loading animation effect. This is basically used to block the screen while the application is doing some work like fetching data from the server or processing any big data which needs some resources.

<a href="https://www.skptricks.com/2019/04/react-native-loading-spinner-overlay-example.html" >React Native Loading Spinner Overlay </a>

<img src="https://3.bp.blogspot.com/-akeiZK8c7ZE/XLK9IVSVG3I/AAAAAAAACqM/is8WMtpVkkcrSdDX3J8w2Q5PFOoxd5fBQCLcBGAs/s640/spinner.jpg" />

<a href="https://www.skptricks.com/2019/04/react-native-loading-spinner-overlay-example.html" >Continue Reading... </a>
Building your career development
Tags: career, discuss
Published: 2019-04-14 09:55:59

---
title: Building your career development
published: true
description: How do you approach career development?
tags: #career #discuss
cover_image: https://thepracticaldev.s3.amazonaws.com/i/jx8s17vul6ol61x0v6bu.jpg
---


We all get moments of doubts. I’m living one of those moments these days, and all these questions start to creep to the surface.

* Is this worth my time?
* Am I focusing on the right things?
* Is this the correct path?
* Do I want to do this now and/or in the future?

And finding the answers to these questions can be hard.

I recently read an article called *Finding Your Niche as a Developer* by Nick Shoup.

{% link https://dev.to/shoupn/finding-your-niche-as-a-developer-bgc %}

Shoup talks about being a T-shaped developer/person. To have some base knowledge/skills in many areas but have a deep understanding of one. I completely agree with this approach.

By blogging, I aim to gain general knowledge of different subjects and then direct my attention to the thing(s) I find most interesting.

I’m still working on obtaining general knowledge, but I haven’t come across an area that I want to immerse myself into entirely. However, it’s possible that once I decide to dive into a specific topic, I might develop a thing for it.

So, I’ve been wondering. Should I change things up? Maybe put all of my eggs in one basket.. well, almost all of them.. for around six months, focus on one subject and see how that turns out? And if I don’t like it by then, I’d just move on to the next one.

Maybe I’m just a little bit impatient.. might need to listen to a few Gary Vee episodes to shake that off.

How do you approach career development?

Thanks for reading.
[C++ CODE] Haunted Matrix Elements Sum
Tags: thetealpickle, algorithms, coding, challenge
Published: 2019-04-14 09:15:22

---
title: [C++ CODE] Haunted Matrix Elements Sum
published: true
description: Determine the cost of possibilities
tags: #thetealpickle #algorithms #coding #challenge
cover_image: https://thepracticaldev.s3.amazonaws.com/i/ppjjnz4w0k2bai8cdia7.png
---

THE TEAL PICKLE CODING CHALLENGE!! Given matrix, a rectangular matrix of integers, where each value represents the cost of the room, your task is to return the total sum of all rooms that are suitable for the CodeBots. I solved this problem with bae (C++). TRY IT 👀

<img src="https://thepracticaldev.s3.amazonaws.com/i/ojim6r13ip29vf6a03dv.png" />


Check out my solution and share yours!! ~ 💻 💻 

<img src="https://thepracticaldev.s3.amazonaws.com/i/gflir7zv1btvs6ogt3ht.png" />
How every developer job is not the same
Tags: job, newrole, developerjob
Published: 2019-04-14 07:21:30

---
title: How every developer job is not the same
published: true
description: 
tags: job, new role, developer job
---

A new job is like moving into a new house. You don't know where everything is , you're not sure what is right and wrong yet but you have a rough idea of it all. This rush of the unknown and excitement is what alot of my colleagues would describe as the *honeymoon phase* . These first days, weeks or even weeks are the best parts of a job but they aren't the reality of that job.

 But with these times, i believe these are the times where you get reflect on your previous job and see how much better this new exciting place is, the new people you'll meet and the new problems you'll solve. I apologise for such a short piece but i haven't written in months so look forward to much lengthier pieces. Until then, keep pushing to be the best dev you can be!
Orientation about store files/images in backend
Tags: discuss
Published: 2019-04-14 05:59:20

---
title: Orientation about store files/images in backend
published: true
tags: discuss
---

Hi fellows!

I'm writing here looking for wisdom about good practices to prepare and develop my backend.

###Context:
I want to develop a backend that allows to store files/images that comes from a User UI. Those images should be uploaded via RestFul Api and store in the backend.

###Your help
You'll help if you can share some knowledge about your way to store file/images in the backend exposing a api to achieved it.

* Which technology have you use to achieved it?
* Will you use Node.js backend to it?
* How would you store the files/images? Blob to a db or files with ref?
* Which framework could help?

Thanks a lot for your help.
[C++ CODE] Almost Increasing Sum
Tags: thetealpickle, algorithms, coding, challenge
Published: 2019-04-14 02:35:17

---
title: [C++ CODE] Almost Increasing Sum
published: true
description: Determine whether the sequence is almost increasing
tags: #thetealpickle #algorithms #coding #challenge
cover_image: https://thepracticaldev.s3.amazonaws.com/i/g9l5ysf5r91798z5bntm.png
---

THE TEAL PICKLE CODING CHALLENGE!! Determine whether the sequence is almost increasing. I solved this problem with bae (C++). TRY IT 👀

<img src="https://thepracticaldev.s3.amazonaws.com/i/fqgunshfw7orvp5962nt.PNG" />


Check out my solution and share yours!! ~ 💻 💻 

<img src="https://thepracticaldev.s3.amazonaws.com/i/1wxs5sqamnf7octpnia8.PNG" />
How to disable in browser linter errors in an ejected create-react-app application
Tags: createreactapp, react, codenewbie, eslint
Published: 2019-04-14 01:31:09

---
title: How to disable in browser linter errors in an ejected create-react-app application
published: true
description: How to disable in browser linter errors in an ejected create-react-app application
tags: create-react-app, react, codenewbie, eslint
---

So, you've ejected your app that was created with create-react-app, and you're using your own linter, and now all of a sudden, when a linter error occurs, you get an error screen.  This may be a good thing, but what if have `no-console` as error, and you want to log things while doing development, but not in production.


Open up `config/webpack.config.js`, and delete these lines 293-310:
```js
// First, run the linter.
// It's important to do this before Babel processes the JS.
{
  test: /\.(js|mjs|jsx)$/,
  enforce: "pre",
  use: [
    {
      options: {
        formatter: require.resolve("react-dev-utils/eslintFormatter"),
        eslintPath: require.resolve("eslint"),
        failOnError: false,
        failOnWarning: false,
      },
      loader: require.resolve("eslint-loader")
    }
  ],
  include: paths.appSrc
},
```

We just removed the linter check that gets done when you run your application in development mode, and when your application gets built for production.
It doesn't make sense to run the linter for either of these scenarios. 

It does, however, make sense to run the linter while running `npm test` or `yarn test`.

In `package.json`, change `"test": "node scripts/test.js"` to `"test": "yarn linter && yarn jest"`.

And add the following scripts:
```js
"linter": "eslint src --ext .js,.jsx",
"jest": "jest"
```

Now, when you run `npm test` or `yarn test`, it will run your linter and your jest unit tests!
Hi, I'm Pandawan
Tags: introductions
Published: 2019-04-14 00:56:44

---
title: Hi, I'm Pandawan
published: true
description: 
tags: #introductions
---

I'm a 17 year old developer and high school student.

I'm French, but currently live in California.

I've been coding for about 5 years now.

I prefer web development (for now), but can also do game and mobile dev.

You can check out my GitHub at [@PandawanFr](https://github.com/PandawanFr).

I hope to continue learning and growing.


Nice to meet you.
Adding a estimated time to read to a .NET Core Blog with Razor
Tags: development, opensource, dotnetcore
Published: 2019-04-25 15:01:18

---
title: Adding a estimated time to read to a .NET Core Blog with Razor
published: true
tags: Development,Opensource,DotNetCore
canonical_url: 
---

This week i implemented a feature what shows you, how many time you have to spend, to read a blog article. ![](https://saschamanns.de/img/markers/ASPNetCore.jpg)

In the first step, i used my model BlogStory to get the content. Then Razor does the following:

1. It counts the spaces between the words and adds 1. So now we knowing how many words we have in that article.
2. The most people can read 200 to 250 in one minute. So we need to divide the counted words with 250. Then we knowing, how many minutes it takes to read.
3. Then we combine a modulo with a divide to get the seconds.

```
@{
    var word_count = @Model.Body;
    var counts = word_count.Count(ch => ch == ' ') + 1;    
    var minutes = counts / 250;
    var seconds = counts % 250 / (250 / 60);
    var str_minutes = (minutes == 1) ? "Minute " : "Minutes ";
    var str_seconds = (seconds == 1) ? "Second " : "Seconds ";    
}
```

Now we placing the code for displaying the estimated time to read

```
<i class="fas fa-clock"></i> @minutes @str_minutes  @seconds @str_seconds
```

On the place, where this snipped is, will be the estimated time to read.

Currently it is placed on client side. It is planned to move that function to server side in future.

[![Creative Commons License](https://i.creativecommons.org/l/by-sa/3.0/de/88x31.png)](https://creativecommons.org/licenses/by-sa/3.0/de/deed.en)

 This work by [Sascha Manns](https://saschamanns.de) is licensed under a [Attribution-ShareAlike 3.0 Germany License (CC BY-SA 3.0 DE)](https://creativecommons.org/licenses/by-sa/3.0/de/deed.en/).  
 Based on a work at [saschamanns.de](https://saschamanns.de).
How to Serve On-Demand Streaming Videos from AWS (Build Your Own Netflix)
Tags: aws, rails, webdev, devops
Published: 2019-04-13 20:47:49

---
title: How to Serve On-Demand Streaming Videos from AWS (Build Your Own Netflix)
published: true
description: 
tags: aws, rails, webdev, devops
---

⚠️ DEV.to video player is in beta doesn't play for people resulting in an error code but do not worry because we also upload our videos to youtube so [here is the youtube link to this video.](https://www.youtube.com/watch?v=kQwZUupLeqE&t=1s). If you do happen to go to our YouTube consider giving us a subscribe because it helps us to produce more free video content.


-------

So at ExamPro, we have lots of video content and instead of using an existing provider to serve On-Demand Video Streaming we rolled our own on AWS.  This allows us to have full control over the data and also allows us to have a video pipeline for pennies than using a third party provider.


[![](https://thepracticaldev.s3.amazonaws.com/i/08wlang8j83kvr1r5w2f.png)](https://www.youtube.com/channel/UC2EsmbKnDNE7y1N3nZYCuGw)
My Git Aliases
Published: 2020-05-11 09:18:16

---
title: My Git Aliases
published: true
date: 2019-01-31 16:05:36 UTC
tags: 
canonical_url: https://www.juanfernandes.uk/blog/my-git-aliases/
---

I use Git via the command line and have always used it that way ever since it was introduced at a company I worked at a few years ago.

But soon after using it Git for a few days, I started disliking the repetitiveness of the commands - so I did some googling and found that I could create shortcuts (aliases) in Bash.

So I started creating aliases for the commands I used several times a day and over the years I have added to them as I find other developers' own git aliases.

## How to create an alias

You can create an alias in a .bash\_profile or in . bashrc, usually in the your users home directory.

A bash alias takes on this format:

```
alias ALIAS_NAME="ALIAS_COMMAND"

```

Here are my aliases:

![List of GIT aliases](https://www.juanfernandes.uk/assets/imgs/aliases.png "List of GIT aliases")

You can see the list on this [Github gist](https://gist.github.com/juanfernandes/7e13fa0c81253ae46f8d "GIt Aliases Gist")

## Bash the fish

With my new laptop (MacBook Pro) I decided to try Fish, a bash alternative, so creating aliases with fish is not done the same way - they are know as functions in Fish.

Instead of adding them to a file, you create them on the command line, like so:

```
alias x='exit'

```

Then, save it using this command:

```
funcsave x

```

The functions are then saved in a folder: ~/.config/fish/functions/ - to see all the functions in a web based interface, type the following command:

```
fish_config functions

```

I won't get too deep into Fish, as I'm still learning it - maybe a future post.

Did you find this useful? Have you got a your own set of aliases - please share them.