teleren/devto huggingface dataset:
Rails signed IDs for ActiveRecord
Tags: rails, activerecord
Published: 2020-05-19 22:56:56

---
title: Rails signed IDs for ActiveRecord
published: true
description: New feature in Rails 6.1
tags: Rails, ActiveRecord
---

Starting with version 6.1, `ActiveRecord` will support looking for records using signed IDs. This feature can be handy when doing things like resetting passwords, sending invitations, or doing email verification.

Signed IDs have three characteristics:
- They are tamper-proof
- They can be set to expire
- They can be scoped to a particular purpose

### How is this different from GlobalId?

The above seems oddly similar to [Signed Global IDs](https://github.com/rails/globalid#signed-global-ids), so you may be wondering, why was this feature introduced?

The main difference is that `ActiveRecord` signed IDs can only be used when referring to a single concrete class, conversely `GlobalId` can be used when the passed ID might respond to any number of classes.

### How can I use signed IDs?

When Rails 6.1 is released all `ActiveRecord` instances will respond to:
- `signed_id` to generate the token
- `find_signed` to find a record using the token
- `find_signed!` same as the above but instead of returning `nil` when the record is not found an error will be raised

Here's a simple example:
```ruby
signed_user_id = User.first.signed_id

User.find_signed(signed_user_id)
=> User.first
```

If you want to set a purpose and expiration to the token you can pass them as arguments to `signed_id`, like this:
```ruby
signed_user_id = User.first.signed_id(purpose: :email_confirmation, expires_in: 30.minutes.from_now)

User.find_signed(signed_user_id)
=> nil

User.find_signed(signed_user_id, purpose: :other)
=> nil

User.find_signed(signed_user_id, purpose: : email_confirmation)
=> User.first
```

If you don't want the query to silently fail, you can use the bang-method alternative:
```ruby
User.find_signed!("invalid_token")
=> ActiveSupport::MessageVerifier::InvalidSignature
```

Rails will automatically generate a `signed_id_verifier_secret` to be used when encoding and decoding the tokens. You can also provide your own in an initializer.
```ruby
# config/initializers/active_record.rb
ActiveRecord::Base.signed_id_verifier_secret = "custom_verfifier_secret"
```

If you are interested in learning how this was implemented, take a look at the [pull request](https://github.com/rails/rails/pull/39313/files) where this feature was introduced.
Top 5 DEV Comments from the Past Week
Tags: bestofdev
Published: 2020-05-19 22:26:11

---
title: Top 5 DEV Comments from the Past Week
published: true
description: Highlighting some of the best DEV comments from the past week.
tags: bestofdev
cover_image: https://res.cloudinary.com/practicaldev/image/fetch/s--7VrAA2ln--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://thepracticaldev.s3.amazonaws.com/i/qmb5wkoeywj06pd7p8ku.png
---

This is a weekly roundup of awesome DEV comments that you may have missed.  You are welcome and encouraged to boost posts and comments yourself using the **[#bestofdev](/t/bestofdev)** tag.

@steveblue kicked off a great "battlestations" with their submissions to **[Workspace Wednesday: Show me pics of your at-home setup](https://dev.to/ben/workspace-wednesday-show-me-pics-of-your-at-home-setup-4f11)**:
{% devcomment ope9 %}

@twigman08 adds their thoughts about the state of things in: **[In defense of the modern web](https://dev.to/richharris/in-defense-of-the-modern-web-2nia)**:
{% devcomment p2j6 %}

@foresthoffman let fly with their take in **[What is your pettiest programming-related opinion?](https://dev.to/peter/what-is-your-pettiest-programming-related-opinion-5f8f)**:
{% devcomment p0co %}

@gmopalafox quipped about ridiculous years-of-experience requirements in **[Learn Deno: Chat app](https://dev.to/aralroca/learn-deno-chat-app-37f0)**:
{% devcomment p07a %}

@mtpiercey shared their thoughts in **[Is the Tailwind approach a big step forward for CSS or just-yet-another-thing?](https://dev.to/ben/is-the-tailwinds-approach-a-big-step-forward-for-css-or-just-yet-another-thing-3n5k)**:
{% devcomment p523 %}

See you next week for more great comments ✌
Podcast: The History of Java
Tags: beginners, programming, java, coding
Published: 2020-05-19 22:13:41

---
title: Podcast: The History of Java 
published: true
description: In this podcast I talk about the history of Java
tags: beginner, programming, java, coding
---

I'm really proud of the work we did on [this podcast](https://bit.ly/25YearsofJava). I present: The History of Java

It's a tale of how a small project started in the early 90s and is nearly abandoned, yet then repurposed for this new thing called "the web". Then it experiences explosive growth, slows down then gets a new life with mobile devices. 

Check it out: 

{% podcast https://dev.to/allhandsontech/029-25-years-of-java %}

Let me know what you think!
SQL: Intro to Wild Cards 
Tags: sql, webdev, codenewbie, datascience
Published: 2020-05-19 21:12:29

It has been a while since I posted anything, so this one is going to be really simple and short just to warm up. This is going to be about wild cards.

##And let's get started :)


#Wild Cards 

A wild card is basically a way of searching through strings for characters. Wild cards use the "LIKE" operator. Most known and used wild cards are "%" and "_". If you are a programmer you are probably familiar with regular expressions and these wild cards work like them. Here is briefly how they work.


"%": represents zero or more than one character.
 
"_": represents only one character.



**If you do not know what the heck i am talking about here, relax this is normal. These examples will clear any confusion.**


##"%"

In the example below, we are telling sql to get the data from the table "customer" where the column "name" records start with the letter "m" and continue with any characters. 
   
```javascript
SELECT * FROM customers WHERE name LIKE "m%"; 
```

here is another example. Here we are basically telling sql to get the records from the column "name" that ends with the letters "ud" and can start with any characters.  


```javascript
SELECT * FROM customers WHERE name LIKE "%ud";
```
    

##"_"

As i said the "_" will represent one character.

The query below will get the data that starts by any character followed by the pattern "_ohamed".

```javascript
SELECT * FROM customers WHERE name LIKE "_ohamed";
```


Another example 


So we are telling sql here to get any result from the column name that starts with the pattern "ahme" and ends with any character. 


```javascript
SELECT * FROM customers WHERE name LIKE "ahme_";  
```





And, of course, we can combine the two of them to get more advanced.

This one is a little tricky. We are telling sql to get the data from the column email which starts with any number of characters and ends with only one character after "o". As you may have guessed this will retrieve any ".com" email.  
   

```javascript
SELECT * FROM customers WHERE email LIKE "%.co_";  
```






#Conclsuion 

you can see how simple it is, but there is a lot to add to this if you want to dive deep in SQL, consider checking out my course on [gumroad](https://gum.co/Dnfaz):)
LeetCode: Odd Even Linked List
Tags: datastructures, algorithms, leetcode, linkedlist
Published: 2020-05-19 20:57:31

---
title: LeetCode: Odd Even Linked List
published: true
description: Day 16
tags: datastructures, algorithms, leetcode, linkedlist
series: LeetCode May Challenge
---
### Problem Statement

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.

You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity.

**Example 1:**

```
Input: 1->2->3->4->5->NULL
Output: 1->3->5->2->4->NULL
```

**Example 2:**

```
Input: 2->1->3->5->6->4->7->NULL
Output: 2->3->6->7->1->5->4->NULL
```

**Note:**

- The relative order inside both the even and odd groups should remain as it was in the input.
- The first node is considered odd, the second node even and so on ...


### Solution Thought Process

For this problem, we have to create two linked list:

- `OddLinkedList` - for containing odd index elements
- `EvenLinkedList` - for containing even index elements

We iterate over the linked list, we initialize a counter to 1. Whenever -

- The counter is divisible by 2, we add the node to the `OddLinkedList`
- The counter is divisible by 1, we add the node to the `EvenLinkedList`



After that, we merge the tail of `OddLinkedList` to the `EvenLinkedList` head. And in the end, we make the tail of `EvenLinkedList` point to `NULL` to make sure that the linked list has ended in `NULL`.



### Solution

```c++
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* oddEvenList(ListNode* head) {
        ListNode* oddLinkedList = new ListNode();
        ListNode* evenLinkedList = new ListNode();
        ListNode* oddIterator = oddLinkedList;
        ListNode* evenIterator = evenLinkedList;
        ListNode* iterator = head;
        int counter = 1;
        while(iterator)
        {
            if(counter % 2)
            {
                oddIterator->next = iterator;
                iterator = iterator->next;
                oddIterator = oddIterator->next;
                oddIterator->next = NULL;
            }
            else {
                evenIterator->next = iterator;
                iterator = iterator->next;
                evenIterator = evenIterator->next;
                evenIterator->next = NULL;
            }
            counter++;
        }
        oddIterator->next = evenLinkedList->next;
        evenIterator->next = NULL;
        return oddLinkedList->next;
    }
};
```




###  Complexity:

**Time Complexity**: O(n)

**Space Complexity:** O(1)
What Microsoft does RIGHT.
Tags: microsoft, windows, opinion
Published: 2020-05-19 20:38:33

After I made many articles kinda bashing Microsoft's flagship product Windows 10, I really want to talk about their good side. While Windows 10 is something I hate, you cannot deny Microsoft does make fantastic products. One of them is going to probably get me killed (even my Windows users), but still. None of these are in any particular order, just as I think of them. I might also miss apps, so if you think of anything, post them.

# C-Sharp
Java done perfectly. I love C#, as a programming language, I just want to use it more. The only reason I don't use it is that I simply don't have it in my memory, and I prefer other languages at this time. I still love it.

# TypeScript
Another fantastic language. It earns the title of "JavaScript with superpowers." I haven't used it much, but still. Many love it, and I wish I had more PWA's I need to make. TypeScript feels great to write.

# MS Office
While I much prefer LibreOffice, that's because of personal preference. MS Office works well, and it is valid to love it as office software. That being unlike *some* **online** *office apps*.

# MS Paint
Iconic, yet oddly powerful. While MS Paint is associated with bad art, I have seen MS Paint used to the max. MS Paint is a valid art tool, and it - if used with care - can make excellent art.

# Visual Studio
Great IDE, I just wished it worked on Linux. Easy, simple, great for developers. It having a free version is also a plus.

# VSCode
A code editor that uses Electron as it should be used. It implementing TypeScript and modules as it did, just made it a perfect tool. I use VSCode for everything, and it's so powerful I can't even use other apps because it feels weird. Even the themes and extra tools just make it all worthwhile.

# Edge Browser
Even pre-chromium Edge was nice. While it is a bit weird, it still is just good. Now, this isn't going to be the one that get's me killed. For a built-in browser. It's just fine. It had tools I love, and now it is based on Chromium while keeping the tools, great.

# Windows Phone
The only issue with Windows Phone was the poor plans and the integration with Windows 8/8.1, which was why it was hurt. It needed to follow Android or Apple. Open licenses, or self-building. If it wasn't for it trying to have it both ways hurt it. As a phone OS, just good. With Nokia, just fine. I loved the Windows Phone OS. Please don't kill me.

# F# 
The last language, I promise. F# is C# made functional with it looking like Python. I love F#, and it feels great. I love it, and it's just an amazing language. I recommend it.
CodeNewbie Check-in Thread
Tags: codenewbie, checkin, beginners, discuss
Published: 2020-05-19 20:36:09

---
title: CodeNewbie Check-in Thread
published: true
description: A thread to ask questions, share progress, and stay accountable!
tags: codenewbie, checkin, beginners, discuss
---

You are encouraged to use this thread to:
- Ask for help (all questions encouraged)
- Explore topics you’re curious about
- Share something you’ve written or read
- Celebrate your wins
- Stay accountable to your goals
- Support your fellow programmers

Happy Coding!

---

_Interested in joining the twice-weekly live [#CodeNewbie Twitter chats](https://twitter.com/search?q=codenewbie)?  You can find us [on Twitter](https://twitter.com/search?q=codenewbie) each Wednesday at 9pm ET (1am GMT on Thursday) and Sunday at 2pm ET (6pm GMT)!_
Angular Tutorial - Learn to build Angular Firestore Todo App From Scratch | 3 Hours
Tags: angular, firestore, javascript, firebase
Published: 2020-05-19 20:32:56



The tutorial is Ready, 3+ Hours of Full Tutorial (free)
An App for your Portfolio .....

Learn how to build Modern Looking an Angular Firestore Todo App From Scratch,
This is a full package tutorial from design to deploy ....

you will learn,

Design the app using angular & css,
Manage Data (CRUD) using Firestore
Data Validation
Deploy the app to Firebase Host.
Link :- https://bit.ly/2zGHmJb
How to install Vscode on android
Tags: vscode, android, webdev
Published: 2020-05-19 20:24:23

Hello there. Today (about an hour ago) I tried something cool. As the title says it. I will show you how to install visual studio code (code Oss) on android. Yes, you got it right. 

I will assume you know how to use a terminal. In this tutorial, we will use the most popular android terminal called termux. You can get it [here](https://play.google.com/store/apps/details?id=com.termux).

# Code Oss
I will not waste your time. It's a fork of visual studio code intended for arm based computers like Chromebooks. You can check on their [official site](https://code.headmelted.com/)

# How to install
Here i assume you've installed termux 
## Steps :
Install Ubuntu in your Android device. It's targeted for such systems. Copy paste the following and wait for it to finish installing
```shell
pkg install wget openssl-tool proot -y && hash -r && wget https://raw.githubusercontent.com/EXALAB/AnLinux-Resources/master/Scripts/Installer/Ubuntu/ubuntu.sh && bash ubuntu.sh
```
Once done, run this command:
```shell
./start-ubuntu.sh
```
When you are in the Ubuntu terminal, you can run the following to grab the editor.
```shell
wget https://github.com/cdr/code-server/releases/download/2.1698/code-server2.1698-vsc1.41.1-linux-arm64.tar.gz
```
Extract it with the following.
```shell
tar -xvf ./code-server2.1698-vsc1.41.1-linux-arm64.tar.gz
```
Voila, you have the editor extracted . Now you can optionally delete the archive to free up some space else your are going to use it later.

> The files are no more in an executable format, they need to be placed in a /bin folder for you to have the ability to call it

Due to that, the following command should do the work :
```shell
cp ./code-server2.1698-vsc1.41.1-linux-arm64/code-server /bin
```

Voilà. You can now call the editor by running "code-server" any where in your terminal and you will be able to use it. It is served on _localhost:8080_. 

Final note: Each time you launch it, you'll see a new password and it can be annoying. So let's set a password in our environment variables.
Run this :
```shell
export PASSWORD="<your_password>"
```
Replace _<your_password>_ with any password of your choice and each time you launch the editor. You'll use the exact same password.

Here is my original tweet :
{% twitter 1262828219952226304 %}

Like and share 

Most credits : [Ada Rose article : Coding on Samsung DeX](https://medium.com/samsung-internet-dev/developing-on-android-phones-visual-studio-code-on-dex-4c99d2e80e91)

<a href="https://www.buymeacoffee.com/rocketstellar" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
What was the hardest concept you had to wrap your head around?
Tags: discuss, beginners, tutorial, javascript
Published: 2020-05-19 20:14:06

Looking back it sounds silly but I had the hardest time understanding `for each` loops in Javascript. Mostly because the tutorials I found were't explaining the parameters (value, index, array) of the call back function very well but also because I wasn't very comfortable with callback functions.

What was you Kriptonite while learning how to code?

*Source image: Kelly Sikkema/ @kellysikkema*
Windows 10 is getting a package manager - my thoughts
Tags: windows, packagemanagement
Published: 2020-05-19 20:07:49

I recently saw that Windows is getting a package manager. I, as a Linux user, am not excited, not because I fear for Linux but that I hate how Windows will implement it. While I am excited that Windows is actually trying to catch up to Linux, how they are trying to get to the level of Linux is laughable. 

The huge thing that makes me laugh at the Windows package manager is that it uses Powershell. As the sysadmins who saw me say that leave, let me explain why I hate this being built in Powershell. Five words: Wrong tool for the job. I wouldn't write a package manager in Bash, because it being the wrong tool for the job. Not that Powershell is bad, just a terrible tool for the job.

While Powershell is my favorite shell language, personally, I would more want C, C++, C#. Something that isn't built to work in a shell alone. Shells use the same principles as interpreters, while Powershell - if my memory serves me correctly - allows for compiling, I would prefer a language that is a pure compile. 

Another gripe with it is the use of YAML. I hate YAML. Same reason I hate Debian packaging. Last I remember using YAML, I had to be so precise that I hated my existence. I personally wish Microsoft would also at least design their own system, maybe borrowed from Debian. Something like:
```
Package: my-app
Version: 1.0.0
Developer: SomeDeveloper Inc.
DeveloperEmail: somedev@example.com
License: Copyright 2999 SomeDeveloper Inc.
Homepage: https://example.com
Architecture: amd64
Source: root
```
That's how I would write it, and even though their YAML is easy enough, two main things I HATE! I will borrow both of them from the WhatsApp package.

ID's: `Id: WhatsApp.WhatsApp`
and Installers:
```
Installers:
  - Arch: x64
    Url: https://web.whatsapp.com/desktop/windows/release/x64/WhatsAppSetup.exe
    Sha256: ECE62222419605FF607CB5BB68FE05A098D74320B9E2762CFC1C9DD42C31570B
    InstallerType: exe
```
This angers me, and for two reasons:

- The URLs can be long
- No from-source-compiles

While both of these will hopefully be solved, I do have a couple of other issues.

- No personal-package archives seem to be planned
- Package uploads can be rejected by Microsoft
  - Only angers me because again, no personal package lists
- Packages are hosted in the repository itself, with no external servers.


Now, can all of these be fixed? Yes. Will this convince me Windows is a good option as an OS? No. The package manager is a cool concept, but I feel like it is another Fucsia, an experiment that they don't really care to put to its max potential.

Can WinGet impress me? Well, it has a solid name, and I am hoping I am wrong about how it will end up. Currently, it seems like a gimmick to me, or maybe just a dumb experiment like the rest of their opensource apps. I really just want to see this prove me wrong, but currently, I am unimpressed.

----

What are your thoughts on Windows 10 getting a package manager? Do you agree with me about it seeming more like a gimmick/experiment than a product? I want to hear your thoughts.
How to Fix the Bugs Effectively
Tags: php, javascript, beginners, webdev
Published: 2020-05-19 19:47:42

Video Version can be found here.
https://youtu.be/wS4eaKIjqtw 

Bugs or Programming problems are part and parcel of the life of every programmer. Today, I am gonna discuss some of the bug handling techniques which are learnt over the last few years while programming

Here are a few rules to handle the bugs effectively.

1 - **Always have a Plan** - I learnt that rule from a book Think Like a programmer. The author says in the first chapter, You should definitely have a plan before solving a programming problem. When you are developing a new algorithm, start planning about it, Even a little plan is enough, after all, plans are made to be replanned. But a plan gives you a direction to follow.

So when you are trying to find the solution a programming problem, plan and point out what are the areas of the program where there may be the problem. Start testing each step and make sure each step is working correctly. As someone said, the well-defined problem is half solved. same way, if you know where the problem really is, you can come up with the solution quickly.

2 - **Use Pen and Pencil to Plan** - From my personal experience, when I try to do the planning with pen and paper, I come up with the ideas faster.

3 - **Always look for the reason** - Most often than not, we usually don't know where the problem is coming from. Trying to test each step and make sure the output from each step is as expected will help you get to the root cause of the problem quickly.

4 - **Use some Debugging Tool like Xdebug** - I procrastinated a lot on using Xdebug. I thought I don't need that, I have var_dump() or printer. but believe me, sir, You need a debugging tool, It will take a little bit of effort to set up at first, but it's definitely worth it.

5 - **Use Typecasting** - Unlike java or c, it's not required to define the data type of variables in PHP and Javascript. so we usually skip it. Until PHP 5, there was not much support for typecasting, but with the introduction of PHP 7, there is strong support for typecasting. Unfortunately, Javascript still does not have support to define data type(Typescript can be used where possible). Always do typecast it will prevent many unnecessary bugs.

```
boolean $decision = false; // typecasting the $decision variable to boolean

$decision = 'string'; // will  produce error
```

6 - **Finally, Use interfaces** - interfaces are your friends, They gonna help you in IDE code completion, Prevent many potential problems and make your code more readable.

That's all from my experience. Should you have any other idea or have a question, please do share in the comments box. Thanks