teleren/devto huggingface dataset:
Bitcoin price with Ruby
Tags: ruby, programming
Published: 2019-10-24 20:55:55

We aren't talking about the value of a Ruby or a get rich quick talk. No, we are talking about the <a href="https://www.ruby-lang.org/en/">programming language Ruby</a>.

Getting the bitcoin price is one the simpelest program you can make, while still having a meaning (beyond "Hello World")

How can we do that with Ruby? 

## Get price with Ruby

The first step is to import some modules, or as ruby calls them gems.

    #!/usr/bin/ruby
    require 'rubygems'
    require 'json'
    require 'pp'
    require 'open-uri'

Data is retreived from an API. We use an API to download data. In this example we download the bitcoin price. 

Data is presetend to the computer in some way. Sometimes its XML Format, sometimes JSON, sometimes something else.

I like the JSON format personally, because it's so simple.

    obj = JSON.load(open("https://api.coinmarketcap.com/v1/ticker/bitcoin/"))

Then it returns the JSON data, something like this

    [{"id"=>"bitcoin",
      "name"=>"Bitcoin",
      "symbol"=>"BTC",
      "rank"=>"1",
      "price_usd"=>"7511.40312364",
      "price_btc"=>"1.0",
      "24h_volume_usd"=>"16880618621.5",
      "market_cap_usd"=>"135289661862",
      "available_supply"=>"18011237.0",
      "total_supply"=>"18011237.0",
      "max_supply"=>"21000000.0",
      "percent_change_1h"=>"0.05",
      "percent_change_24h"=>"-0.26",
      "percent_change_7d"=>"-7.3",
      "last_updated"=>"1571949454"}]

So we need to get the price (prie_usd). The price has micro cents, mili cents, nano cents and so on. This has no real world meaning, so we round the number after converting it to a floating point number..

    val = obj[0]["price_usd"].to_f.round(2)
    puts "$ #{val}"

Thats it

**Related links**
* <a href="https://ruby-lang.co/">Ruby programming tutorial</a>
* <a href="https://coinmarketcap.com">Cryptocurrency data</a>
Open bank mark goes USA
Tags: graphql, techtalks, rust
Published: 2019-10-24 20:52:56

Last few months have been really busy. I was finalising the now finally published [blog post](https://www.confluent.io/blog/getting-started-with-rust-and-kafka)about using Rust with Kafka. And also preparing to talk at [GraphQL Summit](https://summit.graphql.com/) which will be the first conference I'll be speaking.

Been a really hectic time especially since there was also some trouble at home, leaving less time as usual to do stuff. But I'm really looking forward to visit San Fransisco and learning more about GraphQL.

I'm still busy with the finishing touches to the repo that is more centred about the GraphQL part. One of the most important changes is using the GraphQL endpoint to increase the load of the system. If all goes well the presentation will be recorded.
My first community project!
Tags: contributorswanted, showdev, productivity, hacktoberfest
Published: 2019-10-24 20:43:37

This Hacktoberfest, I decided to do something different than last. Specifically, I became a maintainer. I wanted to do what people had done before to help me, and so I created a resources guide. I created a list called *Coding Resources* (any ideas for something more creative, just let me know). It includes multiple sections, and includes podcasts and newsletters. I even got my first pull request (so excited about that, btw)!

{% github b3u/coding-resources %}

That's all from me. Happy Hacktoberfesting!
*Binyamin Green*
[GitHub](https://github/b3u) | [Blog (Coming along)](https://b3u.netlify.com) | [Twitch](https://twitch.tv/binyaming)

{% user b3u %}
LPW2019: Perl 6, losing your Perl 5 accent
Tags: uncategorized
Published: 2019-11-11 23:12:05

---
title: LPW2019: Perl 6, losing your Perl 5 accent
published: true
date: 2019-10-24 20:36:59 UTC
tags: Uncategorized
canonical_url: https://lancewicks.com/2019/10/24/lpw2019-perl-6-losing-your-perl-5-accent/#utm_source=rss&utm_medium=rss
---

This year I was able to attend the London Perl Workshop (LPW2019) once again.

I gave a talk titled “Perl 6, losing your Perl 5 accent” which is available at [https://slides.com/lancewicks/lpw2019?utm\_source=rss&utm\_medium=rss](https://slides.com/lancewicks/lpw2019?utm_source=rss&utm_medium=rss) and the video will be available soon I think.

The talk is mainly around the idea that being a Perl 5 developer means that when I write Perl 6 it looks like Perl 5. I give some examples where I take Perl 5 and in some instances am able to run it directly in Perl 6. Then I modify the code to be increasingly Perl 6 styled.

I’m not a fan of the name change; basically because it seems noise that has delayed the progress of Perl6 development and caused division in the community. That said, meh change the name lets see what happens.

The conference itself was great with a new venue. The energy was great and the “vibe” felt positive. It was great to spend time with a bunch of colleagues and former colleagues.

Along with the talk on Perl 6, I did a little lightning talk about our attempt at rebooting the Perl Podcast over at [http://perlcast.net?utm\_source=rss&utm\_medium=rss](http://perlcast.net?utm_source=rss&utm_medium=rss) I was also able to record a couple of interviews with people which I hope to put on the cast soon.

The podcast is a second attempt to reboot it. It’s harder than I expected so it the community can jump onboard and maybe join us and contribute to the repo: [https://github.com/PerlPodcast?utm\_source=rss&utm\_medium=rss](https://github.com/PerlPodcast?utm_source=rss&utm_medium=rss)

Well, until next year, happy perling.
Announcing Wired-Elements 2.0
Tags: sketchy, handdrawn, webcomponents
Published: 2019-10-24 20:36:55

---
title: Announcing Wired-Elements 2.0
published: true
description: What's new in 2.0 release of wired-elements - Common UI Elements with a sketchy hand-drawn look.
tags: sketchy, hand-drawn, webcomponents
canonical_url: https://shihn.ca/posts/2019/wire-elements-2
cover_image: https://thepracticaldev.s3.amazonaws.com/i/fkreg37ul81lrjy3nmsc.png
---

I'm happy to announce the 2.0 release of [wired-elements](https://wiredjs.com/). It started of, and still is, a fun project to work on. In this era of really slick and buttery smooth design systems, a brutal and rough beacon of light 😉

In this release, the underlying base code for all components was refactored to create smaller and more efficient components. By more efficient, I mean fewer re-renders of the sketchy shapes. This was done mainly by not re-rendering shapes if the dimensions do not change, and also by utilizing the [Resize Observer](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver) where it's available.

View all components in action in the [wired-elements showcase](https://wiredjs.com/showcase.html).

New components in 2.0 👇

## wired-calendar

This is the first fully community contributed component. [Eduardo Martinez](https://github.com/elingerojo) created this. The calendar is customizable in many ways, for details check out the [wired-calendar readme](https://github.com/wiredjs/wired-elements/tree/master/packages/wired-calendar).

![wired-calendar example](https://shihn.ca/stuff/posts/wire-elements-2/calendar.jpg)

## wired-video

A simple video player that shows a sketchy progress and hand-drawn controls for play/pause and volume. 

![wired-video example](https://thepracticaldev.s3.amazonaws.com/i/7r4k4opuhw36xjtbt9p9.png)

## wired-image

An image component akin the the `<img>` tag, but it frames the image in a hand-drawn box. The elevation of the box is configurable.

![wired-image example](https://shihn.ca/stuff/posts/wire-elements-2/image.jpg)

## wired-dialog 

A modal dialog implementation. This contents of the dialog look like paper cutouts around a hand drawn box.

![wired-dialog example](https://thepracticaldev.s3.amazonaws.com/i/ht00p9a0mn01diahmayr.png)

## wired-divider

A hand-drawn horizontal line that can be used to divide two sections.

## wired-link

Akin to `<a>` tag, a link with href, and a sketchy underline.

## wired-search

A search input control

![wired-search example](https://thepracticaldev.s3.amazonaws.com/i/nkug8vg345rqw2ufwseo.png)

## MORE

Try wired-elements out on [Glitch playground](https://glitch.com/edit/#!/wired-elements-vanilla).

Checkout [wiredjs.com](https://wiredjs.com/) for more.
Things a program must not do under Bazel
Tags: build
Published: 2019-10-24 20:27:23

Don't expect the environment to have implicit things like tools in the PATH. Bazel builds are meant to be portable so you can invoke them remotely or share cache hits with your coworkers. Be explicit about getting tools you need as inputs, or using Bazel's toolchain feature to locate them on the disk.

Don't rely on the working directory to be next to the inputs. Bazel always sets the working directory in the root of the workspace, next to the WORKSPACE file. (Of course you can always chdir inside the process after Bazel starts it. In NodeJS, for example, you can do this with a [`--require` script](https://github.com/bazelbuild/rules_nodejs/issues/1840#issuecomment-619277667).)

Don't try to write to the sources. The input directory will be in a read-only filesystem by default. For example Angular CLI runs the `ngcc` program which tries to edit `package.json` files in the inputs:
https://github.com/angular/angular/pull/33366

Don't try to write in a subdirectory of the sources either. Only write to the output directory.

Don't resolve symlinks of the inputs. Node programs often try to read symlinks because of a common pattern of linking build outputs of one package to be dependencies of another. Bazel creates an execroot (for build actions) and a runfiles root (for test/run) filled with symlinks to sources or other outputs. Resolving the symlinks causes non-hermeticity by finding undeclared input files, or causes logic bugs in the program if it compares a symlink target path and expects them to be the same.

Don't rely on stdin/stdout to communicate inputs and outputs. Bazel will sometimes use stdin for a protocol that communicates with the program, like worker mode or ibazel watch mode. It's possible to work around this with a genrule but that introduces a bash dependency.

Don't rely on accepting all the configuration over command line arguments. You will likely run into argv length limits. Consider accepting a configuration file or params file with the CLI flags written into it.

My earlier post about getting Nativescript tools to run under Bazel: https://medium.com/@Jakeherringbone/running-tools-under-bazel-8aa416e7090c
Introduction to CSS
Tags: css, beginners
Published: 2019-10-24 20:03:18

---
title: Introduction to CSS
published: true
description: A brief introduction to CSS
tags: css, beginners
series: FrontEnd Development Zero to Hero
---

CSS which stands for __Cascading Style Sheets__ is one of the buddies of HTML, you will  find it at the Presentation layer of the Web and it's specifically used to make HTML much more presentable and pleasing to the eyes (if done right).

CSS can be used to achieve lots of effects in a Web document, some example include:

* Changing text font size
* Adding background colors
* Creating Page Layout
* Hiding and Showing HTML Elements
* Transition and Animations

We can apply CSS to an HTML Element using any of the methods below:
* Directly to the Element
* With a `style` tag within the `head` Element
* Using an External Style Sheet
* With JavaScript

One of the beauty of CSS is that its quite easy to get started with, but without patience you might get frustrated along the way.

Learning CSS well will go a long way in helping you figure out solutions when you find yourself in such situations. Now you might be thinking, have done a few Google searches on CSS and it seems to be quite easy at a glance, of course it is. Then you go a little deeper and come across terms like:

* Specificity
* The Cascade
* Inheritance
* Margin Collapse
* Block Formatting Context

Reading the terms above for the first time, might make you think like: I just want to apply some color, increase my paragraph font size, why do i need to care about this? Specificity? The Cascade? Inheritance? Common! . Well, starting out with CSS, these terms might seem non-existence until you work on a project and stumble on roadblocks like:

* styles  not getting applied
* page layout crashing

Doing some Google searches you might get recommendation of slapping `!important` at any property that fails to do your bidding, you proceed with the advice and voila! it works! The time you spent on searching online could have been saved if you had learnt CSS well.

Just like HTML, there are some accessibility gotchas that we need to watch out for when using CSS, some are:

* The combination of colors to use on a web page
* Making text readable irrespective of the device accessing the document
* Making the document adapt to different screen sizes
* Hiding page objects the right way

That's it for the introduction. Next,  Some history lesson.
🎻🎻 A first step to becoming an npm virtuoso
Tags: npm, javascript, webdev
Published: 2019-10-24 19:42:06


## The obvious

visit npmjs.com to find modules. Use [bundlephobia](https://bundlephobia.com/) to get size information of the packages. 

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/uv0qd93tdp4vmy957wtu.png)

Use [npmtrends](https://www.npmtrends.com) or [npmcharts](https://npmcharts.com/) to compare the popularity of packages.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/6zo6pp7e888o0cktx626.png)

installing a package
```
npm i express
```
---

installing a package as dev dependency
```
npm i --save-dev express
or
npm i -D express
```
---
installing a package globally
````
npm i express -g
```
---
removing a package
```
npm uninstall express
```
(add `-g` to install / uninstall globally)

## The not so obvious

get outdated packages
```
npm outdated
```


show all installed packages
```
npm list
```

(`ls`, `la` and `ll` can be used as aliases for `list`)


show all globally installed packages
```
npm list --global
```

you should probably use it like this, otherwise the output will be quite long, because this also shows the dependencies of your globally installed packages.

```
npm list --global --depth=0
```

visit the package page on npmjs.com

```
npm home <package>
```


## Getting information about packages

show which version is used and which packages are requiring the specified module
```
npm ls express
```

show all available versions, description, contributers of a package
```
npm view express
```


## Local Development with packages aka Linking

in my-module (will later on be used in the host project)
```
npm link
```

in the host project (which is going to use my-module)
```
npm link my-module
```

If you link a package, it'll be automatically updated in the target application

or just install the local module via the file system
```
npm install ../my-module
```

show all globally linked modules
```
npm ls -g --depth=0 --link=true
```

## Creating a local package

```
npm init
```

or 

```
npm init -y 
```

to answer all the questions during the installation process with yes.

---

Do you have some useful npm commands, that you are using on a regular basis? Or some lifesavers? Please add them in the comments! 

Thanks for reading!
Functional Interfaces In Java
Tags: java, functioninterface, lambdaexpressions
Published: 2021-05-24 12:58:45

---
title: Functional Interfaces In Java
published: true
date: 2019-10-24 04:25:53 UTC
tags: java,functioninterface,lambdaexpressions
canonical_url: https://medium.com/java-epic/functional-interfaces-in-java-d81393caa6a4
---

#### What to do with it?

![](https://cdn-images-1.medium.com/max/560/0*AoisXxTTKc7_Eojd.jpg)<figcaption><a href="https://www.journaldev.com/2763/java-8-functional-interfaces">https://www.journaldev.com</a></figcaption>

A functional interface is an interface that contains only one abstract method. They can have only one functionality to exhibit. From Java 8 onwards, [lambda expressions](https://www.geeksforgeeks.org/lambda-expressions-java-8/) can be used to represent the instance of a functional interface. A functional interface can have any number of default methods. **_Runnable_** , **_ActionListener_** , **_Comparable_** are some of the examples of functional interfaces.  
Before Java 8, we had to create anonymous inner class objects or implement these interfaces.

{% gist https://gist.github.com/sovannarithcheav/bc6422e60787dd074caf64158e581a0f %}

Java 8 onwards, we can assign [lambda expression](https://www.geeksforgeeks.org/lambda-expressions-java-8/) to its functional interface object like this:

{% gist https://gist.github.com/sovannarithcheav/7478f7fd8fc6728f0474bfb5a7628461 %}

### **@FunctionalInterface Annotation**

> **@FunctionalInterface** annotation is used to ensure that the functional interface can’t have more than one abstract method. In case more than one abstract methods are present, the compiler flags an ‘Unexpected **@FunctionalInterface** annotation’ message. However, it is not mandatory to use this annotation.

{% gist https://gist.github.com/sovannarithcheav/0a2578de3f2d89b34757dccb5d1c045e %}

**READMORE**  : [geeksforgeeks](https://www.geeksforgeeks.org/functional-interfaces-java/)

> @Override

> **public**  **void**  run()

> {

> System.out.println("New thread created");

> }

> }).start();

> }

> }

* * *
Is There a Cat in The Code!?
Tags: jokes, javascript
Published: 2019-10-24 19:32:22

---
title: Is There a Cat in The Code!?
published: true
description: Funny issue resolution conversation
tags: jokes, javascript
cover_image: https://thepracticaldev.s3.amazonaws.com/i/d9xed2wpibj6w0cebg13.PNG
---

Just saw this on [Twitter](https://twitter.com/kaydacode/status/1187364168489459712):

![There's a cat in the code](https://thepracticaldev.s3.amazonaws.com/i/d9xed2wpibj6w0cebg13.PNG)

:laughing: :laughing:
ActiveRecord Callbacks
Published: 2019-10-24 19:01:21

Callbacks (callback functions) are a common way to execute custom code at certain points in the life cycle of an Active Record object, such as right before it is created, after it is saved, or after it is destroyed. For example, it can be useful for transferring all characters from a user's email to lowercase when creating his or her account. Callbacks are a way of saying something like "Hey Active Record, when you finish creating a new user object, let me know so that I can run this method before anything else happens."

Here is a list of the life cycle events:
- **Initialization** - when the object was first created in memory.
2. **Validation** - This happens when you try to save an object, or when you manually call a #valid? method.
3. **Save** - saves a newly made object to the database.
4. **Create** - creates and saves a new object.
5. **Update** - updates an existing object.
6. **Destroy** - deletes an existing object from the database.

As a rule, you have a choice of 3 callbacks. Not all objects’ life cycle steps support the full set of callbacks, but the main ones are:

- **before_**  - starts the method before the specified action
- **after_**  - starts the method after the specified action
- **around_** - In this case, you can execute the code both before and after the action, so that YOU can decide at what point the initial action will be performed. This is not used very often.

## **Using callbacks**

To use a callback, you will need to register it at the top of your model using the appropriate method. You can either add a code block or pass another method as a parameter to the callback function.
```ruby

# app/models/song.rb
class Song < ActiveRecord::Base
      
  after_create do |song|
    puts "Just created a song"
  end

  before_create :song_created

  private
  def song_created
    puts "about to create #{song.title}"
  end
end

```

## **Specifying Callback Features**

Callbacks allow you to narrow down the list of actions in which the callbacks will run. If you just want to start a callback when a certain controller action calls it, use **on:** .

```ruby
...
  before_validation :normalize_name, on: :create
 
  private
    def normalize_name
      self.name = name.downcase.titleize
    end
...
```
You can also use conditional logic options **:if** and **:unless** to test the method before starting the callback. For example:

```ruby
...
  before_save :normalize_card_number, if: :paid_with_card?

  private
  def paid_with_card?
      true
  end
...

```
Creating my side-project in 2 weeks - day 3
Tags: laravel, vue, design
Published: 2019-10-24 18:48:21

# **Creating my side-project in 2 weeks**
## **Third day: improving cards**

Here is the third day of this series, let's begin now!

**Auto-updating cards**
When a card is moved or his title is changed, we need to send a request through the API to update it in the database. But how to know **when** I need to update the card ? Here are the points for the moment:

- When the card title is edited
- When the card content is edited
- After the card was moved

So let's jump to it. I first added a `update` data to the Card.vue, and set it to false by default. Then for the input of the title and the textarea of the content, I choose to use the event `@blur` which is activated when the user leave the field, to then set the `update` value to true. And which event choose when I move the card ? I used the `@mouseup` which is rather explicit.

With this, the request is always not sent, but I now know when I need to update the card. So in the `mounted` method, I added a `setInterval` which run every 0.5s to check if we need to send the request:
```js
mounted() {
    setInterval(() => {
        
        if(this.update) {
            
            this.update = false; // Set back 'update' value to false

            // ... Perform the request
        }
    }, 500); // Run the task every 0.5 seconds
}
```
And with this, when I edit the title/content/move the card, I can see that a request is sent...

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/su06oix5isgoj0fqjrcs.png)

...and the `update` data goes back to false:

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/c0qxkmijfpwhdkcj824p.png)

Now I just need to update the card's data in the controller, and return back a **JSON** with the key `success`, which can be true or false.

**Icon pack**
I choose to switch from [FontAwesome](https://fontawesome.com/) to [Simple Line Icons](https://simplelineicons.github.io/) which - I think - looks really better, simply because it's simpler and thiner - even if there are not as many icons as FontAwesome has. Here is the result on the dashboard sidebar:

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/faqx6u1ndjyrmn1ala3x.png)

**Dev environment**
I also setup a dev environment where **you** can test the - very basic - card sustem. Here ares the credentials for the test account:

- Email: test@gmail.com
- Password: testtest

You can login [here](https://dev.shineboard.io/auth/login) if you want to test it.

Infortunnately I don’t got the time to create the custom right-click menu, so it will be for tomorrow, with I think the options to create/delete cards and even change the color. Hope you liked this episode, see you tomorrow!
Starter email template skeleton layout for designing and building emails
Tags: opensource, productivity, html, webdev
Published: 2019-10-24 18:48:09

---
title: Starter email template skeleton layout for designing and building emails
published: true
description: Standard layout components for designing and building emails
cover_image: https://raw.githubusercontent.com/blocksedit/starter-email-template/master/starter-template-use-example.png
tags: opensource, productivity, html, webdev
---

An open source, modular email template system to quickly kick off your email's design. It's essentially a prototype for email layout and content. The design focuses on essential layouts and components you would need with minimal styling for you to build on top of when theming your template.

UPDATE: Now with much cleaner code that is also more semantic and accessible!

###[Check out the repo on GitHub](https://github.com/blocksedit/starter-email-template)