teleren/devto huggingface dataset:
A simple Stimulus table filter demo
Tags: stimulus, tutorial
Published: 2018-02-04 13:01:03

---
title: A simple Stimulus table filter demo
published: true
description: The before and after of implementing table filter with Stimulus
tags: stimulus, tutorial
---
# Goal
Show the before and after implementation of table filtering with the new modest js framework named [stimulus](https://stimulusjs.org/)

We'll focus on a simple page with a table and filter capability.

I'll break this down into 2 steps:
* Implementation without Stimulus
* Implementation with Stimulus

# Implementation without Stimulus

To accomplish this part I created a [simple project](https://github.com/dstull/stimulus-demo/tree/without-stimulus).  There are 2 files that are involved:

## [HTML File](https://github.com/dstull/stimulus-demo/blob/without-stimulus/app/views/hello/index.html)

## [CoffeeScript file](https://github.com/dstull/stimulus-demo/blob/without-stimulus/app/assets/javascripts/hello.coffee)

Here I am demonstrating the filtering of table rows when a user presses enter.

# Implementation with Stimulus

To accomplish this part I utilized the [master branch](https://github.com/dstull/stimulus-demo/). [This](https://github.com/dstull/stimulus-demo/commit/7681b4d0ab01c39ce09aaa8d562590a0b9539fb1) commit shows the diff of the conversion. Final demo app can be found [here](https://stimulus-demo.herokuapp.com/).

There are 3 files that are involved:

## [HTML File](https://github.com/dstull/stimulus-demo/blob/master/app/views/hello/index.html)

The notable changes here to notice are the utilization of the data attributes of target, controller, and action.  The action specifically defines the javascript event keyup and the controller and function it will invoke.

## [Application JS file](https://github.com/dstull/stimulus-demo/blob/master/app/javascript/packs/application.js)

Not much to say about this file, as it is the basic wiring needed as the entry-point for Stimulus use.

## [Hello Controller JS file](https://github.com/dstull/stimulus-demo/blob/master/app/javascript/controllers/hello_controller.js)

Here I am demonstrating the conversion into Stimulus from original CoffeeScript.

# Conclusions

Stimulus really shines when you can use it to describe the event handlers in the data attributes instead of having to deal with them in JavaScript.  If you are using server side rendering of html, this framework can really help you organize your javascript and manage events.
Add security.txt to your website
Tags: net, security, securitytxt
Published: 2019-02-22 15:29:12

---
title: Add security.txt to your website
published: true
tags: .NET,Security,security.txt
canonical_url: https://ankitvijay.net/2018/02/04/add-security-txt-to-your-web-app/
---

Recently, I came across below tweet from security expert Troy Hunt

> Google now has a security.txt file – so should you! [https://t.co/fXmeNG9Yem](https://t.co/fXmeNG9Yem) [https://t.co/drbJQ1Ynw8](https://t.co/drbJQ1Ynw8)
> 
> — Troy Hunt (@troyhunt) [February 3, 2018](https://twitter.com/troyhunt/status/959724034622595072?ref_src=twsrc%5Etfw)

<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

The tweet talked about a file named `security.txt`. I went on reading [his post](https://www.troyhunt.com/fixing-data-breaches-part-3-the-ease-of-disclosure/) to understand what exactly is `security.txt` and what problem does it solves.

## So, what is Security.txt

No organization wants to be caught on a wrong foot when it comes to security. A data or security breach could lead to financial and reputation loss of a company. When a security researcher finds a  potential breach or security vulnerability in an organization website/ application, he/she tries to contact the organization to “responsibly disclose” the issue. The disclosure is confidential in nature and allows the organization time to take appropriate action against the issue.

But, who does the security researcher reach out to? Usually, in scenarios like this, they would not prefer to reach out to the organization via a general “contact us” page on the website or emailing/ calling a customer care of the organization. They would rather like to reach out to someone in the organization who can take immediate action, someone with authority.

That’s where `security.txt` can come to rescue.  The concept of `security.txt` was proposed by security researcher  **Ed Foudil. ** According to his website, [securitytxt.org](https://securitytxt.org/):

> The main purpose of security.txt is to help make things easier for companies and security researchers when trying to secure platforms. Thanks to security.txt, security researchers can easily get in touch with companies about security issues.

The organizations can add `security.txt` to their website to provide information of how or who security researchers can reach out to when they come across a security vulnerability on their website.

The website also provides an easy way to [generate the security.txt](https://securitytxt.org/#generate) file. The file needs to be added to the path `/.well-known/security.txt`. 

Many websites including [Google](https://www.google.com/.well-known/security.txt) have started adding `security.txt`, maybe its time you should add one too ![🙂](https://s.w.org/images/core/emoji/11/72x72/1f642.png)

The post [Add security.txt to your website](https://ankitvijay.net/2018/02/04/add-security-txt-to-your-web-app/) appeared first on [Hi, I'm Ankit](https://ankitvijay.net).
Explore Bucharest -- Primaverii
Tags: bucharest, explore, primaverii, post
Published: 2019-01-20 15:22:42

---
title: Explore Bucharest -- Primaverii
published: true
tags: bucharest,explore,primaverii,post
canonical_url: https://horia141.com/explore-bucharest-primaverii.html
---

![Primaverii 1](https://horia141.com/assets/primaverii-1.jpg)

![Primaverii 2](https://horia141.com/assets/primaverii-2.jpg)

![Primaverii 3](https://horia141.com/assets/primaverii-3.jpg)

![Primaverii 4](https://horia141.com/assets/primaverii-4.jpg)

![Primaverii 5](https://horia141.com/assets/primaverii-5.jpg)

![Primaverii 6](https://horia141.com/assets/primaverii-6.jpg)

![Primaverii 7](https://horia141.com/assets/primaverii-7.jpg)

![Primaverii 8](https://horia141.com/assets/primaverii-8.jpg)

![Primaverii 9](https://horia141.com/assets/primaverii-9.jpg)

![Primaverii 10](https://horia141.com/assets/primaverii-10.jpg)

![Primaverii 11](https://horia141.com/assets/primaverii-11.jpg)

![Primaverii 12](https://horia141.com/assets/primaverii-12.jpg)

![Primaverii 13](https://horia141.com/assets/primaverii-13.jpg)

![Primaverii 14](https://horia141.com/assets/primaverii-14.jpg)
Catch and parse JSON Post data in PHP
Tags: php
Published: 2018-02-04 07:50:27

---
title: Catch and parse JSON Post data in PHP
published: true
description: Catch and parse JSON Post data in PHP
tags: php
---

A few days ago I've been working a project which, as many other projects out there today, communicates with some external APIs. At some point, in order to perform some tests, I had to write an API endpoint within my project itself to fake the actual external API. I need to mention that the external API was expecting `application/json` content type, so basically the `curl` setup looked like this:

```
<?php

//...

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_VERBOSE, true );
curl_setopt( $ch, CURLOPT_HEADER, true );
curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout_limit );
curl_setopt( $ch, CURLOPT_ENCODING, '' );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 ); 
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $data ) );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
   'Content-Type: application/json'
) );

// ...

```

The issue was that when I've been trying to catch the POST data and use it, I was getting `null` as a value for both `$_POST` or `$_REQUEST`, and I couldn't understand why 🤔. Apparently (and maybe many of you already knew that), if the data is sent as `multipart/form-data` or `application/x-www-form-urlencoded` then yes, you can use PHP globals `$_POST` or `$_REQUEST` to catch and use that data. But, if the data is sent as `application/json`, then prior to PHP 5.6 you could've use [$HTTP_RAW_POST_DATA](http://php.net/manual/en/reserved.variables.httprawpostdata.php) to grab the raw POST data, or (and based on PHP docs this is the preferable way to do it) use the [php://input](http://php.net/manual/en/wrappers.php.php) - a read-only stream that allows you to read raw data from the request body.

So, as a result I ended up grabbing the POST data like this:
```
<?php
// receive the JSON Post data
$data = json_decode( file_get_contents( 'php://input' ), true );
```

Big credits to these stackoverflow discussions:
[https://stackoverflow.com/questions/2731297/file-get-contentsphp-input-or-http-raw-post-data-which-one-is-better-to](https://stackoverflow.com/questions/2731297/file-get-contentsphp-input-or-http-raw-post-data-which-one-is-better-to)
[https://stackoverflow.com/questions/813487/how-to-post-json-to-php-with-curl/813512](https://stackoverflow.com/questions/813487/how-to-post-json-to-php-with-curl/813512)

Happy coding everyone! 💻 🤓 👍
Setting up a new development project. Best practices!
Tags: discuss
Published: 2018-02-04 00:17:14

---
title: Setting up a new development project. Best practices!
published: true
tags: discuss
---
I'm starting the last project of my Full Stack Developer Master. We're a 4 members team and we're planning our roadmap for this new adventure. So, what is the best way or points to take in consideration?

Thanks!!
Visualizing local requests w/ gource NodeJS & some magic 🦄 [wip]
Tags: node, javascript, gource, security
Published: 2018-02-03 23:10:15

---
title: Visualizing local requests w/ gource NodeJS & some magic 🦄 [wip]
published: true
description: https://www.youtube.com/watch?v=h9ORznim-XM
tags: node.js,javascript,gource,security
cover_image: https://thepracticaldev.s3.amazonaws.com/i/f4jwl5me1hvg84t5wd0o.png
---

TL;DR; 🍪
{% youtube h9ORznim-XM %}
Introducing a Rails 5.1 development environment via Docker
Tags: rails, docker
Published: 2018-02-04 00:15:01

---
title: "Introducing a Rails 5.1 development environment via Docker"
published: true
tags: rails, docker
canoical_url: https://www.michielsikkes.com/introducing-a-rails-5-1-development-environment-via-docker/
---

I’m working on something new: an easy to set up Rails 5.1 development environment in Docker, configured via docker-compose. I’m maintaining a template for this on GitHub here:[michiels/rails-docker-compose](https://github.com/michiels/rails-docker-compose). Follow the [README there for instructions](https://github.com/michiels/rails-docker-compose/blob/master/README.md)on setting it up on your app.

## Why?

Why am I doing this? I’d like all members in our team at[Firmhouse](https://firmhouse.com) to not have to think about local dependencies anymore when working on one of the many apps we develop. Getting set up with an app should be a matter of seconds.

Having a development environment per app also helps cleaning out any databases and Sidekiq queues and gem interdepencies. So you always have fresh and clean environment and you don’t have to recompile Ruby for each differeing version on your workstation.

## What it contains:

I want to maintain the repository so it always supports a Rails development environment for:

- Latest Ruby on Rails
- Latest Ruby version
- PostgreSQL
- Redis (for Sidekiq)
- RubyGems for installing gems (standard Rails)
- Yarn for installing JS dependencies (standard Rails)
- System tests with headless Chrome

## How does it work for your app?

You can read [more detailed instructions in the README](https://github.com/michiels/rails-docker-compose/blob/master/README.md), but here’s the gist:

First, you copy over the Dockerfile, docker-compose.yml file and slightly modify your database.yml and docker-compose.yml.

Then, you set up the app’s database via:

  ```
  $ docker-compose run --rm web rails db:setup
  ```

Finally, it’s super easy to start a local Rails development environment:

  ```
  $ docker-compose up
  ```

  Browse to http://localhost:3000/ and your app is up and running with Rails, PostgreSQL, Redis, and Sidekiq.

Bonus hint: Keep a local development session open for generating controllers and models, and running migrations and tests. For example:

```
$ bin/devconsole
# rails g controller homepage
# rails db:migrate
# rails test
# rails test:system
```

## Try it, please!

I’d love to see this set up work in your app. Let me know if it works out or what doesn’t.
What Happens When A User Edits A Post on Dev.to?
Tags: discuss
Published: 2018-02-03 19:25:54

---
title: What Happens When A User Edits A Post on Dev.to?
published: true
tags: discuss
---

I am catching up on [Ben's posts on web perf](https://dev.to/ben/making-devto-insanely-fast) and I still don't quite get what happens when a post is edited. I understand that things are cached but doesn't that mean that if a post is edited it will take an unpredictable amount of time to update to CDNs all around the world? What are the best practices around this? Does it cost anything to do this? These are the kinds of questions I have when wondering about what I would run into if I were to make a dev.to clone.
Do you think a CS degree is a requirement for get a job?
Tags: discuss
Published: 2018-02-03 16:03:23

---
title: Do you think a CS degree is a requirement for get a job?
published: true
description: 
tags: discuss
---
Hello dev.to() members. I was wondering wether you consider getting a CS degree as a requirement for those looking for a job in fields like web/mobile development ...
Building a Bitcoin Calculator with Javascript
Tags: bitcoin, javascript
Published: 2018-02-03 13:50:32

---
title: Building a Bitcoin Calculator with Javascript
published: true
description: 
tags: bitcoin, javascript 
---

#Introduction

Hey guys, I am going to show you how to use Bitcoin exchange rates and currency conversion that supports all major currencies. I am currently using Coindesk which provides API to make data programmatically available to others. 

To use the  API, you don't need to register, it is free!

You can check out the supported currencies available on their website (http://coindesk.com). To use the endpoint, you make a request to:

https://api.coindesk.com/v1/bpi/currentprice/[code].json


The code parameter accepts a valid ISO 4217 currency code 

##A sample request

![sample](https://3.bp.blogspot.com/-57hNfi3JTYE/Wl9ubE5FpFI/AAAAAAAAAfM/bKnAXzbWLVQhMViDXs-FiDKxsZNr55X6wCLcBGAs/s1600/Untitled.png)


Take a look at the result, you would notice the rate and the rate_float object, which contains the exchange rate for the local currency to BTC. Below is a formula to convert BTC to your local currency.


######Formula = BTC Amount * Exchange Rate = Local currency Price

#Building the Bitcoin Calculator

Using a client to consume the JSON data returned from the endpoint is the first thing to do. You can use Asp.Net HttpClient class, Jquery getJson() function which we are going to use here or you can use others you already know.


```
$.getJSON( "https://api.coindesk.com/v1/bpi/currentprice/usd.json", function( data) {
   var amountInBtc = 0.005; //convert 0.005 btc to usd
   var exchangeRate = parseInt(data.bpi.USD.rate_float);
   var amount = amountInBtc * exchangeRate;
   console.log(amount);
});
```

Follow Me: 

Blog: https://techcerberus.blogspot.com
Twitter: https://twitter.com/charlesnnaji
Medium: https://medium.com/@cizu64
First post, picolisp script
Tags: picolisp, lisp, functional, interpreted
Published: 2018-02-03 13:39:09

---
title: First post, picolisp script
published: true
description: Small picolisp script
tags: picolisp,lisp,functional,interpreted 
---

Today I made a oneliner for converting a set of ISO-coded XML files in the current directory to UTF-8. 

```lisp
(for X (dir) (and (match '(@A "." "x" "m" "l") (chop X))(and (out "sh.sh" (prinl "#! /bin/sh"))(out "+sh.sh" (prinl (pack "iconv -f ISO-8859-1 -t UTF-8 " X " > utf8_" X)))(call 'sh "sh.sh"]
```
A more readable, commented version could look like this: 

```lisp
(for X (dir) # for every file name in this directory
    (and 
        (match '(@A "." "x" "m" "l") (chop X)) # check if *.xml
        (and # it is or this is skipped, so...
            (out "sh.sh" # we write a new file
                (prinl "#! /bin/sh")) # with a hashbang 
            (out "+sh.sh" # and then add an instruction
                (prinl 
                    (pack "iconv -f ISO-8859-1 -t UTF-8 " X " > utf8_" X)))
            (call 'sh "sh.sh"] # and finally run it 
```

Now this isn't very lispy, but it can quickly be turned into a more functional style.

```lisp
(de qconv (Lst) # '(FromCode ToCode OutPrefix InSuffix FileList) 
    (for X (last Lst)
        (and 
            (match '(@A ~(chop (cadddr Lst))) (chop X))
            (and 
                (out "sh.sh" 
                    (prinl "#! /bin/sh"))
                (out "+sh.sh" 
                    (prinl 
                        (pack "iconv -f " (car Lst) "-t " (cadr Lst) " " X " > " (caddr Lst) X)))
                )))
    (call 'rm "sh.sh"]
```

Still quite ugly though.
Explain how a Random number is generated Like I'm Five
Tags: explainlikeimfive
Published: 2018-02-03 12:04:04

---
title: Explain how a Random number is generated Like I'm Five
published: true
tags: explainlikeimfive
---

what really happens when we put `Math.random()`

I have always listened that random numbers are not truly random, they are something pseudo-random.

Why true random number can't be generated?
Have you met Emmet?
Tags: tip, html
Published: 2018-05-28 07:38:24

---
title: "Have you met Emmet?"
published: true
tags: Tip,HTML
canonical_url: https://blog.jonstodle.com/have-you-met-emmet/
---

Most popular code editor today have support for _Emmet_ snippets and if you haven't started using them yet. Your life is about to get a bit easier.

You might have come across some code snippets while using your code editor of choice. The snippets let's you insert small blocks of code with the help of a simple shortcut. Emmet is this idea on steroids.

Emmet let's you use CSS syntax to define multiple parts of HTML in one simple go. Type what elements you want, what ids they should have, what classes should be included and what the content will be. Take a look at this for example:

![Creating a button with id, class and content](https://blog.jonstodle.com/content/images/2018/01/emmet-01.gif)

You can get pretty advanced with this. It supports adding child elements, content and much more. You can even multiply the expression to create multiple identical elements:

![Creating multiple elements in one go](https://blog.jonstodle.com/content/images/2018/01/emmet-02.gif)

There's a lot to bite into here, so I suggest heading over to the [documentation](https://docs.emmet.io/) of the project to see what is possible.

It's really adictive once you get used to it. The demonstrations above were recorded in Visual Studio Code where Emmet snippets are inlcuded out of the box for HTML files. A lot of editors come with Emmet included and there are loads of plugins for those that don't support it out of the box.

This is one really neat feature just waiting to be used!

Happy coding!
Lego House and new generation web development.
Tags: web, cdn, npm, webdev
Published: 2018-02-03 10:41:12

---
title: Lego House and new generation web development.
published: true
description: similarities between the Lego toys and new generation web development. 
tags: #web #cdn #npm #webdev
---

Maybe this article is purely my intuition on the web development, it's been one and a half year I'm working with a web app, quite a lot of things I learned from here. On my exploring free time I read and implemented few projects, last night I was linking them with the Lego toys but it was almost matching and the web development has more fun than the lego. 

Let's Look into what is lego? I hope most of know what it is and how we use it?

###Lego
The official home of the toy building brick with links to products, games, videos, the LEGO® Shop, LEGO history, fan creations and our help center. ( from the official doc )

![Example of Lego house](https://i.ytimg.com/vi/5EHf4oV-XuY/maxresdefault.jpg)


###web app

The new generation web also has lot of building bricks with linking products, like CSS file, js files and a lot of other cdn files.

![Example of Lego house](https://i.ytimg.com/vi/wrdR5Su_Stg/maxresdefault.jpg)



###What makes difference?

You have to pay money to get for each lego price ( even though it came as a package).

You can get the almost all cdn files for free from various cdn servers like Cloudflare it will fit almost all your needs.

### Let's have a look at a web app development.
I wish to create a basic note-taking application, 
Step 1: use cdn for framework ( bootstrap, Semantic UI ,.....)
Step 2: use cdn for JS Library ( Jquery*, angular or react ....)
Step 3: use the tinymce library.
Step 4: use backend code.

It is very basic steps to create a web, when i ever i create a web i feel its kind of lego toy.

Cheers :D
Need recommendations in Mocking database / Testing Cleanup (Unit Testing)
Tags: help, node, testing, mocking
Published: 2018-02-03 08:43:57

---
title: Need recommendations in Mocking database / Testing Cleanup (Unit Testing)
published: true
tags: help, node, testing, mocking
---

Hi everyone! I just started learning writing tests. I'm using Express, Mongoose, Mocha, Chai, and Chai-http.

As of now, I'm just clearing my model for every test.

```javascript
  before(function (done) {
    Users.remove({}, (err) => {
      console.error(err)
      done()
    })
  })
```

I've come across Mockgoose but I've had a hard time implementing it (or I hardly tried to implement it enough)

How do you usually mock database or do your cleanup in tests?

Here's my users.js test just to give more context. I am testing an API using Chai-http.

```javascript
'use strict'

// Require the dev-dependencies
const chai = require('chai')
const chaiHttp = require('chai-http')
const app = require('../app')

const mongoose = require('mongoose')
const Users = mongoose.model('Users')

chai.should()

chai.use(chaiHttp)

describe('Users', () => {
  before(function (done) {
    Users.remove({}, (err) => {
      console.error(err)
      done()
    })
  })

  describe('/GET users', () => {
    it('it should GET all the users', (done) => {
      chai.request(app)
      .get('/v1/users')
      .end((err, res) => {
        if (err) { console.error(err) }
        res.should.have.status(200)
        res.body.should.be.a('array')
        // res.body.length.should.be.eql(0)
        done()
      })
    })
  })

  describe('/POST users/register', () => {
    it('it should register a user', (done) => {
      chai.request(app)
      .post('/v1/users')
      .send({ email: 'test@gmail.com', password: 'password', name: 'Jason Bourne' })
      .end((err, res) => {
        if (err) { console.error(err) }
        res.should.have.status(201)
        res.body.should.be.a('object')
        // res.body.length.should.be.eql(0)
        done()
      })
    })
  })
})

```

Many thanks!
Evening Rust: Episode 10: Tron Gold... yes, still?
Tags: video, coding, rust, ai
Published: 2018-02-03 08:06:19

---
title: "Evening Rust: Episode 10: Tron Gold... yes, still?"
published: true
description: Okay, so we're still on Gold...
tags: video, coding, rust, ai
cover_image: https://thepracticaldev.s3.amazonaws.com/i/hgi52t2wsxvd35peh0au.jpg
---

{% youtube iADKKf_7Bhw %}

We continue on our quest to get up higher in gold. Troubles with the look-ahead are causing issues and there's something not quite right about score.

Subscribe to my [Twitch Channel](https://www.twitch.tv/mortoray) to watch live.