teleren/devto huggingface dataset:
More readable string method in rails
Tags: ruby, rails, tricks
Published: 2020-06-24 14:14:28

---
title: More readable string method in rails
published: true
description: 
tags: ruby, rails, tricks
---
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zysoijq8bica6qvyy5fz.jpg)

First look at the code:

```ruby
Rails.env.development? #=> true

```

If rails run at local development environment it will return `true`

Why can call the `development?` method directly on the `Rails.env` object? 

The point is that you can use **?** suffix at method very simple, let's show you source code.

```ruby
module ActiveSupport
  class StringInquirer < String
    def method_missing(method_name, *arguments)
      if method_name[-1] == "?"
        self == method_name[0..-2]
      else
        super
      end
    end
  end
end
```

In fact `Rails.env` is an` ActiveSupport::StringInquirer` instance object. the `ActiveSupport::StringInquirer` object extends the `method_missing` of the `String` class. 

Mainly compare the string before `?` with the string itself

```ruby
name = ActiveSupport::StringInquirer.new("mixbo")
name.mixbo? #=>true

'mixbo?'[0..-2] #=> 'mixbo' 
'mixbo' == 'mixbo' #=>true
```

Hope it can help you :)
Template Haskell vs GHC.Generic
Tags: haskell, generic
Published: 2020-06-24 13:30:31

WARNING: This is not from experience, all hearsay.

## Template Haskell

### Pros

- Relatively fast compile time
- Guaranteed no runtime overhead

### Cons

- Source order dependent
- Weakly typed (AST to AST)

## GHC.Generic

### Pros

- Source order independent like all other Haskell source
- Strongly typed

### Cons

- Slow compile time
- May not be fully optimized away
Daily Challenge #262 - No One Likes Spare Change
Tags: challenge
Published: 2020-06-24 13:26:48

---
title: Daily Challenge #262 - No One Likes Spare Change
published: true
series: Daily Challenge
description: Let's avoid all jingling in your pockets and get rid of that change.
tags: challenge
//cover_image: https://direct_url_to_image.jpg
---

No one enjoys carrying around spare change. And to avoid all that jingling it's absolutely necessary to have an efficient algorithm to calculate the minimum number of coins needed to pay for something. So given a set of coin denominations determine the fewest number of coins required to add up to a given amount. Coin denominations WILL NOT be standard.

**Example**
US Currency includes the penny, nickel, dime and quarter or the coins with denominations: [1, 5, 10, 25] If I were to ask you to make 75 cents you would just return 3 since 75 cents can be made with 3 quarters.

*Denominations:*
coins1={1,5,10,25};
coins2={1,2,5,10,20,50};

*Tests:*
coins1(123)
coins2(123)
coins1(75)
coins2(75)

Good luck!
***
_This [challenge](https://www.codewars.com/kata/58dfc0d8ca6895cb4e00005c) comes from RasPat1 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!_
How To Check URL Is Working Or Not In Programing Languages?
Tags: ruby, python, php, bash
Published: 2020-06-24 13:24:25

# Ruby
```ruby
require 'net/http'
require 'open-uri'

def working_url?(url_str)
  url = URI.parse(url_str)
  Net::HTTP.start(url.host, url.port) do |http|
    http.head(url.request_uri).code == '200'
  end
rescue
  false
end
```

# PHP
```php
$url = "http://www.domain.com/demo.jpg";
$headers = @get_headers($url);
if(strpos($headers[0],'404') === false)
{
  echo "URL Exists";
}
else
{
  echo "URL Not Exists";
}
```

# Python
```py
from urllib2 import urlopen
code = urlopen("https://kipalog.com").code
if code == 200:
   print "Exists!"
   

# Or

import urllib2
ret = urllib2.urlopen('https://kipalog.com')
if ret.code == 200:
    print "Exists!"
```

# Shell
```bash
#!/bin/bash

http_code=$(curl -I -s -o /dev/null -w "%{http_code}" "https://kipalog.com/")

if [ "$http_code" == "200" ]; then
  echo "Exist!!!"
fi
```

# CURL

```bash
$url = "http://www.domain.com/demo.jpg";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_NOBODY, true);
$result = curl_exec($curl);
if ($result !== false)
{
  $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  if ($statusCode == 404)
  {
    echo "URL Not Exists"
  }
  else
  {
     echo "URL Exists";
  }
}
else
{
  echo "URL not Exists";
}
```
Svelte Routing | page.js as routing for Svelte JS
Tags: javascript, development, beginners, webdev
Published: 2020-06-24 13:05:06

---
title: Svelte Routing | page.js as routing for Svelte JS
published: true
description: Learn how to setup routes easily in Svelte
tags: #javascript #development #beginner #webdev
---

Svelte is cool ... So cool that I created a premium beginner course on it. =) This video is from that course. I'll show you how to create routes easily in Svelte with a tiny library called page.js

{% youtube eohan_OS8N0 %}
How Lex learned to code without a CS degree
Tags: beginners, bootcamp, webdev
Published: 2020-07-10 13:52:31

---
title: How Lex learned to code without a CS degree
published: true
date: 2020-06-24 13:01:25 UTC
tags: Beginner, Bootcamp, Webdev
canonical_url: https://www.nocsdegree.com/lex-developer-no-cs-degree/
---

Lex shares his tips for learning to code in this exclusive interview. He never saw himself as a developer.
How to create nuxtJS components using TypeScript.
Tags: nuxt, vue, typescript, help
Published: 2020-06-24 12:57:58

Hello developers,
	I'm building a nuxt app with typescript but I'm having problem while creating / exporting components,

I've read the [documentation](https://typescript.nuxtjs.org/cookbook/components/#template) but it doesn't completely explains how to create components using options API i.e. ``Vue.extend({})`` not with classes and decorators.
Changelog: Status page
Tags: changelog, meta
Published: 2020-06-24 12:53:19

We are happy to announce our status page at https://status.dev.to! 

We've been relying solely on our twitter account to communicate our status since the very beginning and now that is changing. Our status page will provide another channel of immediate communication about the status of dev.to to all DEV users and API consumers.

![status page](https://dev-to-uploads.s3.amazonaws.com/i/wv6bshjjj67qwr5v3j77.png)

Keep up with our real-time status and metrics at https://status.dev.to!
Progress Bar Tutorial with Blog Layout- HTML/CSS/ JavaScript Beginner Tutorial(Video)
Tags: javascript, beginners, webdev, html
Published: 2020-06-24 12:44:12

In this video tutorial you will make a simple blog layout with a fixed header, body, and footer using CSS flexbox. You will then use some simple Javascript to create a progress bar that updates dynamically as you scroll down the page.

##Customize for your portfolio
At the end of the video I'll leave you with some optional features to add so you can have something unique for your portfolio

{% youtube rKAd_GFo7cw %}

Some example ideas:
- Send API request when user has reached bottom of page
- Slide out modal email form when user is 50% down page
- Social sharing buttons in sidebar
- Debouncing to make event handler more efficient
cannot read property 'classlist' of undefined javascript
Tags: help, javascript, beginners
Published: 2020-06-24 12:53:15

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/jvzmotu7g8cdl4ui31sl.PNG)

I'm practicing a challenge of making an order checkout page. And I have made a few payment options using the radio button. The text content inside will be visible only if I click on it. But when I click on the radio button it doesn't show the content inside it and shows the "Cannot read property 'classList' of undefined" error.
------------------------------------------------------------------
Here is the Javascript code:

var Input = document.querySelectorAll("input[name='method']");
var show = document.querySelectorAll(".on");

for(var i = 0, max = Input.length; i < max; i++) {
    Input[i].onclick = function() {
        show[i].classList.add("visible");
        show[i].classList.remove("hide");
    }
}
------------------------------------------------------------------
Here is a link to my codepen for HTML and CSS code:

https://codepen.io/sanket-n-jain/pen/jOWypYM
Modern JavaScript Learning Path in 2020
Published: 2020-06-24 12:48:10

Few days ago, I published {% link https://dev.to/gopinav/react-learning-path-in-2020-3fai %} 
It turned out to be helpful for many people so I figured I'd do something similar for Modern JavaScript as well. If you're new to JavaScript or just getting started or even working with it for a while now, you might find this useful. The video below is my take on learning Modern JavaScript in 2020 and hopefully it will serve as a guideline for anyone who is on a JavaScript learning path.

{% youtube gSnbnYffz7k %}
Capacitor Ionic Vs Cordova
Tags: javascript, android, ios, ionic
Published: 2020-06-24 12:36:25

Cordova is a framework that runs JavaScript apps in a WebView which has additional native extensions, it is called hybrid app. From the beginning of Ionic, Apache Cordova has been an integral part of the project. Ionic is based on Cordova and comes with Angular.

Cordova applications use less and more simple code, which iterates faster development and execution. It is profitable for all the business owners because less effort is required to develop an application to work across all mobile platforms

Is capacitor the new Cordova?
Yes, we can say it is a modified version of cordova with some amazing changes and enhancements. Due to some political disputes and dependencies it has become necessary to start a new project called Capacitor.

How Capacitor is different from Cordova?
Both Capacitor and Cordova manage a Web View and provide a structured way of exposing native functionality to your web code. However, Capacitor has a few key differences that require web developers, previously used to Cordova’s approach, to change app development workflows.

Learn more here: https://medium.com/@rlogicaltech/cordova-vs-capacitor-ionic-91016a344970
Enrich your career with OpenShift Training
Published: 2020-06-24 12:28:00

OpenShift training classes provide you in-depth knowledge on all the key features and fundamentals of OpenShift. The course introduces containers, Kubernetes, Red Hat OpenShift Container Platform, and builds core knowledge to manage containers with hands-on exercises. Through this training, you will work on real-time projects which are primarily inline with the OpenShift Certification Exam. 

you can have free demo:-https://mindmajix.com/openshift-training
How Roy Derks learned to code with no CS degree
Tags: webdev, career, beginners
Published: 2020-11-25 12:30:31

---
title: How Roy Derks learned to code with no CS degree
published: true
date: 2020-06-24 12:27:31 UTC
tags: Webdev, Career, Beginner
canonical_url: https://www.nocsdegree.com/roy-derks-software-developer/
---

Roy is a self-taught developer who teaches people at coding bootcamps how to program. Read this exclusive interview for his advice on learning to code 👇
Remote Letter - Weekly newsletter for remote workers
Tags: remote, freelancing, wfh
Published: 2020-06-24 12:17:15

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ubixhe91mfto4pniufi8.PNG)

I launched [Remote Letter](https://remoteletter.com) as a way to help and entertain digital nomads, freelancers and employees who have been forced to work for home because of the pandemic.

Every Tuesday you will receive a email containing useful products, news and information, podcasts, interviews, discussions from Hacker News, Reddit and Twitter. This will help you keep updated with what's going in the Remote work world.

To read our previous issues, visit [newsletter](https://remoteletter.com/newsletter/1) section.
The first UI Kit for Bootstrap 5! Using Material Design 2.0
Tags: css, javascript, bootstrap, webdev
Published: 2020-06-24 12:13:32

# Bootstrap 5

Bootstrap's first alpha was officially released on June 16, 2020.

Along with the new version of the most popular HTML, CSS, and JS library, there were most anticipated changes released - jQuery was removed & the project switched to plain JavaScript. However, this is only the beginning of changes

You may learn more about the changes implemented into v.5 with this **[video](https://www.youtube.com/watch?v=c9B4TPnak1A)**

---

# MDB 5 alpha

Just a few days after the release of the new Bootstrap version,  the first **UI Kit for Bootstrap 5** using **Material Design 2.0** was released!

What are the key features of the MDB 5 UI Kit? The most important is simplicity and ease of use, and we owe it to:

* Latest Bootstrap 5 & Material Design 2.0
* 500+ material UI components
* Super simple, 1-minute installation
* Detailed docs & multiple practical examples
* Lots of tutorials
* Plenty of free templates
* Plain javascript (but works also with jQuery)
* Huge and active community
* MIT license - free for personal & commercial use

---


**[Learn more](https://mdbootstrap.com/docs/standard/)** about Material Design for Bootstrap 5

**[Get Started](https://mdbootstrap.com/docs/standard/)** & be ahead of everyone

**[Installation](https://mdbootstrap.com/docs/standard/getting-started/installation/)** takes only one minute
Daily Developer Jokes - Wednesday, Jun 24, 2020
Tags: jokes, dailydeveloperjokes
Published: 2020-06-24 12:00:06

---
title: "Daily Developer Jokes - Wednesday, Jun 24, 2020"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
cover_image: "https://private.xtrp.io/projects/DailyDeveloperJokes/thumbnail_generator/?date=Wednesday%2C%20Jun%2024%2C%202020"
published: true
tags: #jokes, #dailydeveloperjokes
---

Generated by Daily Developer Jokes, a project by [Fred Adams](https://xtrp.io/) ([@xtrp](https://dev.to/xtrp) on DEV)

___Read about Daily Developer Jokes on [this blog post](https://xtrp.io/blog/2020/01/12/daily-jokes-bot-release/), and check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/).___
### Today's Joke is...
![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1259169f6cb.png)

---
*Have a joke idea for a future post? Email ___[xtrp@xtrp.io](mailto:xtrp@xtrp.io)___ with your suggestions!*

*This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit.*

<!-- 
Joke text:
___Q:___ A SQL developer walked into a NoSQL bar.

___A:___ They left because they couldn't find a table.
 -->
Change Git's Default Branch From Master
Tags: blacklivesmatter, git, showdev
Published: 2020-06-24 11:48:40

---
title: "Change Git's Default Branch From Master"
published: true
description: "Because actually whatever your argument against it, you're probably wrong"
tags: blacklivesmatter, git, showdev
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/o23xwdlhpkc2j51h6b8s.png
---

[Scott covered this nicely](https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx) with links to topics that show how `master` originated from BitKeeper. [There is evidence to strongly suggest](https://mail.gnome.org/archives/desktop-devel-list/2019-May/msg00066.html) it does pertain to the outdated, oppressive and perverse `master/slave` metaphor, rather than `master-copy`.

**Edited 17th October 2020 (a bit late, I know!)**, Git now lets you set a default branch for `init`, and GitHub now defaults to `main`.

But if you have an older repository, some of these steps remain relevant.

So, here are the steps I followed:

## Move Master to Main

```
# maintain refs
git branch --move master main

# push to remote
git push -u origin main
```

## Change the Default on Remote

Now depending on your remote tool, this might differ.

### GitHub

0. Assuming you've pushed `main` from the steps above.
1. Go to your **Settings**
2. Go to the **Branches** section
3. Change "Default branch" from `master` to `main`

![GitHub change default branch from master to main](https://dev-to-uploads.s3.amazonaws.com/i/6v0k704fo0nluxia0mx1.png)

### GitLab

0. Assuming you've pushed `main` from the steps above.
1. Go to your **Settings**
2. Go to the **Repository** section
3. Change "Default Branch" from `master` to `main`

![GitLab change default branch from master to main](https://dev-to-uploads.s3.amazonaws.com/i/2b940ctcwsno41i8rfpn.png)

### BitBucket

0. Assuming you've pushed `main` from the steps above.
1. Go to your **Repository settings**
2. Go to the **Repository details** section
3. Change "Main branch" from `master` to `main`

![BitBucket change default branch from master to main](https://dev-to-uploads.s3.amazonaws.com/i/4twvtuvm9kyd8fy45ufh.png)

then...

4. Go to the **Branching model** section
5. Change "Development branch" from `master` to `main`

![BitBucket change development branch from master to main](https://dev-to-uploads.s3.amazonaws.com/i/b9jlri2h75v8jqc7ee7l.png)

## Git Now Lets You Name a Default Branch
~~Git Init Doesn't Let You Name a Default Branch~~

**Edited 17th October 2020** Since `git 2.28`, you've been able to change your default branch using built-in `git` features.

```
git config --global init.defaultBranch main
```

## Summary

Sort of past the point about caring which side you fall on here. The evidence is there. Be your own teacher, make the world a better place.
Algorithms Problem Solving: Running Array Sum
Tags: algorithms, python, computerscience, interview
Published: 2020-06-24 11:44:29

---
title: Algorithms Problem Solving: Running Array Sum
published: true
description: Solving algorithms problems with TK
tags: algorithms, python, computerscience, interview
cover_image: https://leandrotk.github.io/tk/series/algorithms-problem-solving/assets/notebook.jpg
canonical_url: https://leandrotk.github.io/tk/series/algorithms-problem-solving/running-array-sum.html
series: Algorithms Problem Solving Series
---

This post is part of the [Algorithms Problem Solving](https://leandrotk.github.io/tk/series/algorithms-problem-solving/index.html) series.

## Problem description

This is the [Running Array Sum](https://leetcode.com/problems/running-sum-of-1d-array/) problem. The description looks like this:

Given an array `nums`. We define a running sum of an array as `runningSum[i] = sum(nums[0]…nums[i])`.

Return the running sum of `nums`.

## Examples

```python
Input: nums = [1,2,3,4]
Output: [1,3,6,10]

Input: nums = [1,1,1,1,1]
Output: [1,2,3,4,5]

Input: nums = [3,1,2,10,1]
Output: [3,4,6,16,17]
```

## Solution

The idea here is to cache the sum of the numbers while iterating through the list. For each number, add to the sum and then add the sum to the result list.

```python
def running_sum(nums):
    sum = 0
    result = []

    for num in nums:
        sum += num
        result.append(sum)

    return result
```

## Resources

- [Learning Python: From Zero to Hero](https://leandrotk.github.io/tk/2017/09/learning-python-from-zero-to-hero/index.html)
- [Algorithms Problem Solving Series](https://leandrotk.github.io/tk/series/algorithms-problem-solving/index.html)
- [Stack Data Structure](https://leandrotk.github.io/tk/2020/01/stack-data-structure/index.html)
- [Queue Data Structure](https://leandrotk.github.io/tk/2020/01/queue-data-structure/index.html)
- [Linked List](https://leandrotk.github.io/tk/2020/02/linked-list/index.html)
- [Tree Data Structure](https://leandrotk.github.io/tk/2020/02/tree-data-structure/index.html)
Let your terminal greet you like a pro
Tags: linux, bash, ubuntu, beginners
Published: 2020-06-24 11:37:47

If you are a developer, the terminal is your one-stop for most of your day to day development activities. As a developer we made sure that our coding setup looks great, we have an amazing dark theme or minimal setup, etc, etc..

Recently I thought of making my terminal look geekier so I just added an `echo` in my `bashrc` file but that was not enough it has to look cool right? I just added the ASCCI representation of my profile picture.

So let's start by getting an image, I used one my own image that I created using gimp you can find the tutorial [here](https://www.youtube.com/watch?v=cjy7pOvEcBU)
### 1. Create an ASCII art of your image

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ady222t04udeaiq0g321.jpg)

You can visit [asciiart](https://asciiart.club/) URL and convert your image into an ASCII version.
 
If you don't have an image you can find some beautiful ASCII art at [ascii art archive](https://www.asciiart.eu/)

There are various tools to generate ASCII text I have used this one [here](http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20)

### 2. Let's get the things ready
 * First, open your terminal and create a new file
`nano mygreeting`
 * Next, copy and paste you ASCII art and text to this file
![nano terminal](https://dev-to-uploads.s3.amazonaws.com/i/m06mwxkcw1uk9myi03mb.png)

You can hit a few tabs to adjust in the center and save the file to use in future

### 3. Let's revive our terminal and add this as a greeting message
Now, we need to display the content of our file created in step 2 to get displayed in the terminal as soon as it is fired up
* Open your bashrc file
`nano ~/.bashrc`
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/gj7vjtmuboqv6xm9gnvs.png)

* Add a small line at the bottom `cat mygreeting` and it's done 

Fire up your terminal to have a look at your beautiful message waiting for you

![Amazing right?](https://dev-to-uploads.s3.amazonaws.com/i/t7cgzd4o7wc2o3gf45ln.png)

Cakewalk right !! Go ahead and try this let me know your thoughts in the comment section.

Thanks for reading!!
 <a id="6qT1gytDsSSXyi3BnJiewifRRHB3" href="https://blogtonft.com"><img src= https://img.shields.io/static/v1?label=Minted%20At&message=BlogToNFT&color=7c3aed&logo=leaflet&logoColor=green/></a>