teleren/devto huggingface dataset:
Stimulus component: Calculator for input fields
Tags: stimulus
Published: 2018-11-02 10:19:19

---
title: "Stimulus component: Calculator for input fields"
published: true
description: 
tags: 
  - stimulusjs
canonical_url: https://tomk32.github.io/2018/08/04/stimulus-component-calculator.html
---

Here's a small stimulusjs component at I wrote for [Budget Fox](https://budget-fox.com?utm_source=dev.to).

It calculates the value of an input with basic arithmetic like 2 + 10/3
and shows the result in the `result` target.

When leaving the input or submitting the form, the input's value is
replaced with the calculated value.:w

If the `result` target is set its `innerText` will be replace with the
value while the user is typing numbers and restored on leaving the input.

```html
<div data-controller="input-calculator">
  <label for="amount" data-target="input-calculator.result">Amount</label>
  <input name="amount" data-action="keydown->input-calculator#calculate keyup->input-calculator#calculate blur->input-calculator#calculate" />
</div>
```

The data-action has three event listeners simply because stimulus is opinionated about
what events to listen to. We need more to update the result on key-strokes (keyup)
and update it when the users hits enter to submit the form (keydown)

```coffeescript
import { Controller } from "stimulus"

export default class extends Controller
  @targets: ['result']

  connect: ->
    if @resultTarget && @resultTarget.dataset
      @flipResult = true
      @resultTarget.dataset['oldInnerHTML'] = @resultTarget.innerHTML

  calculate: (event) ->
    val = event.target.value
    if @flipResult
      @resultTarget.innerHTML = @resultTarget.dataset['oldInnerHTML']
    if val.match(/[+\-\*\/]/)
      try
        val = eval(val)
        if event.type == 'blur' || event.code == "Enter" || event.keyCode == 13 || event.which == 13
          event.target.value = val
        else if @flipResult
          @resultTarget.innerText = val
```

The code if of course MIT licensed.
Rspec: Shared context for DRY controller tests
Tags: rails, rspec
Published: 2018-11-02 09:38:01

---
published: true
title: "Rspec: Shared context for DRY controller tests"
tags: 
  - rails
  - rspec
canonical_url: https://tomk32.github.io/2018/09/03/rspec-shared-context.html
---

Best if I start with a confession: The number of shared context or share examples that I have in my spec is a low digit.
No idea why I missed that trend, but with budget-fox.com I promise to do better and cut down on repetition in my specs.

If your controller specs are a bit like mine they might look like this:

```ruby
  # ...
  let(:user) { Fabricate(:user) }
  before do
    sign_in user, scope: :user
  end
  # ...
```

That's actually pretty slim but with this very same pattern repeated over a few dozen controller there's something in rspec-core that's useful: [shared
context](https://relishapp.com/rspec/rspec-core/docs/example-groups/shared-context)

If you repeat the same `let` and `before` calls over and over again, it's best to put them into your `spec/support` folder, in my case in `sign_in_context.rb`. The context is then included from the controller spec.

```ruby
# only argument is:
# scope (defaults to :user)
RSpec.shared_context "sign in user", :shared_context => :metadata do |args|
  signed_in_scope = args.fetch(:model, :user)
  let(signed_in_scope) do
    Fabricate(signed_in_scope)
  end
  before :each do |c, a|
    sign_in self.send(signed_in_scope.to_sym), scope: signed_in_scope
  end
end
```

And in the controller spec:

```ruby
RSpec.describe Admin::UsersController, type: :controller do
  include_context 'sign in user', model: :admin
  it "GET #index" do
    # ...
  end
end
```
Why do you follow a person on Github?
Tags: github, question
Published: 2018-11-02 08:32:05

---
title: Why do you follow a person on Github?
published: true
description: 
tags: github, question
---

I follow 137 people on Github. I follow some of them because of just my friend. They can be a really good developer but some followings don't push any code to Github for a while. I just worry why we follow a person on Github? What are your reasons? Why should we follow a person who hasn't any activities on Github?

- being your friend
- being your colleague
- being a really good developer
- being a good open source develop
- being a famous guy like a big tech company CTO or etc
- ...

The other point, I can ask, why do you push the unfollow button? That can be the second question. Actually, two questions are related to each other.


Cheers.
How are regex used in the real world?
Tags: beginners, javascript, regex
Published: 2018-11-02 08:30:55

---
title: How are regex used in the real world?
published: true
description: A code newbie's question   
tags: beginner, JavaScript, Regex 
---

Hey ya'll JavaScript ninjas! 

I am currently going through the regex module on FCC and I am just wondering how Regular Expressions are used in the real world and how often is it used?
Ionic 3 tips you might need in your native applications.
Tags: androiddevelopment, ionicframework, ionic
Published: 2019-11-19 19:25:53

---
title: Ionic 3 tips you might need in your native applications.
published: true
date: 2018-11-02 07:53:33 UTC
tags: androiddevelopment,ionicframework,ionic
canonical_url: 
---

![](https://cdn-images-1.medium.com/max/750/0*6yZvOqBADoY_AjzO.png)<figcaption>google image</figcaption>

Ionic is one of the most used cross-platform app development frameworks. With Ionic 4 beta out, you can now integrate ionic with your favorite front-end frameworks (Angular, React, Vue, etc).

Making your Ionic app look native and feel native is what ionic developers strive for, as an Ionic developer the following hacks/tips can improve the user experience of your app to look more native.

- **Using native transitions:**   
Native transitions make your app feel native when transitioning between pages.

> [https://ionicframework.com/docs/native/native-page-transitions/](https://ionicframework.com/docs/native/native-page-transitions/)

- **Showing notifications when downloading a file**  :  
Using ionic file transfer and showing notifications can be a daunting task. Use the following Cordova plugin which would use the android download manager and show a download notification.

> [https://github.com/vasani-arpit/cordova-plugin-downloadmanager](https://github.com/vasani-arpit/cordova-plugin-downloadmanager)

- **Displaying a loader when using the Ionic themeable browser plugin:**   
At some point in our application, we might be required to use an in-app browser, just to make your app feel more native and not breaking the user experience at that point. A common problem is to display a loader while the webpage is being loaded otherwise it might be blank. Using the Loading controller wouldn’t work. A quick fix is to use the ionic native spinner dialog.

> [https://ionicframework.com/docs/native/spinner-dialog/](https://ionicframework.com/docs/native/spinner-dialog/)

- **Using a custom status bar color :**   
The status bar is the notification bar of your app. Changing the color to your app primary color or something similar would make your app feel more native.

> [https://ionicframework.com/docs/native/status-bar/](https://ionicframework.com/docs/native/status-bar/)

- **Using a custom a header color :**  
The android multitask view allows you to change the header color. Using the ionic native plugin it improves the look and native feel of your app.

> [https://ionicframework.com/docs/native/header-color/](https://ionicframework.com/docs/native/header-color/)

#### **Conclusion**

The above tips will improve the feel of your Ionic app and make it look more native, thereby giving your users a better app experience.

> _Reach out to me via switchdevelop1@gmail.com and give me a follow on_ [twitter](https://twitter.com/feezyhendrix) and[ github](https://github.com/FeezyHendrix).

* * *
Send long terminal output to a log file
Tags: commandline, linux
Published: 2018-11-10 17:11:21

---
title: Send long terminal output to a log file
published: true
tags: command line,linux
canonical_url: 
---

There are times when a command line output is too long and it’s hard to scroll through all the lines to see the beginning of the stack trace. This usually happens when you get errors and the best way to fix errors is to read the very first few lines to understand what error message you got and where the error is coming from.

The other day, a co-worker shared a tip in our Slack channel about the command _script_, which is a great tool to use in a case where the output is super long: it saves all the output in a log file. Then you can open it in a text editor and analyse it properly.

In the command line type:

```
script my\_script\_name.scr
```

The Unix script command will then start ” logging” the output. Then you can run the command that gave you the long output again and the script command will save everything until you type

```
exit
```

All you have to do then is to open my\_script\_name.scr in your favourite text editor for easy reading.

Things you should know:

– It only works on Unix systems (Mac, Linux)

– If you forget to give a file name, it will save the output in a file called ˋtypescriptˋ

– You can also pass a path with the file name, otherwise it will save in your current work directory

– For more info about this command you can read it man page (man script) or check this link out: [https://www-users.cs.umn.edu/~gini/1901-07s/files/script.html](https://www-users.cs.umn.edu/~gini/1901-07s/files/script.html)

One cool thing was that I got to use this tool on that same day my co-worker shared it. I hope this is useful to you too.

> The post [Send long terminal output to a log file](https://wp.me/pa0b0y-t) was originally posted on [flaviabastos.ca](https://flaviabastos.ca)

_Photo: [Photo by Markus Spiske on Unsplash](https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)_
Almost NaNoWriMo
Tags: motivation, learning, discuss, writing
Published: 2018-11-05 02:13:16

---
title: Almost NaNoWriMo
published: true
tags: motivation, learning, discuss, writing
series: November Daily
description: Kickstarting the writing habit with a NaNoWriMo-like cadence.
canonical_url: https://www.anonjr.com/2018/11/Almost-NaNoWriMo.html
---

(A few days after I'd published this on my site, I found a [kindred spirit](https://dev.to/mark_nicol/an-article-a-day-for-november-41f5) for the exercise. This and the articles that seem to fit in the Dev.to space will be posted here. Expect a rush now that I got the RSS hooked up.)
<hr>
It seems a little ridiculous to tag this "NaNoWriMo", but I'm not really sure what to call it. I've had a few posts in draft for longer than I care to mention, and while the desire has been there the energy has been lacking… most likely to be the subject of some upcoming posts.

For those who don't know, [NaNoWriMo](https://nanowrimo.org/) is short for National Novel Writing Month. The idea being that you just start writing at the start of November, and work at a steady pace to have a completed work by the end of the month. Just writing, edit later. It's a really nice idea for helping those of us who just need a little push to get started.

<!--more-->

I've gone through the motions of starting a novel a couple of times, and unfortunately never actually followed through. My intent had been to actually participate this year and produce one of the two novels that's been kicking around in the back of my mind for quite some time. Life being what it's been, I just wasn't ready to start and didn't want to feel behind this early on.

So - new objective. Blogging has been another writing activity that I've long intended to do, but never seem to actually make happen. For the month of November my goal is to get at least one post out a day. By the end of November I'll work out a more reasonable posting schedule. The hope is that once I get started, maintaining momentum will be a lot easier.

Look for some updates on old projects, some "talking out loud" type planning on upcoming projects, and a few other things.

Quite frankly I feel like an athlete who's been on a long recovery finally getting back into training. Now that I think about it, that's probably a more apt analogy than I'm ready to admit to.
Getting an Open Source Projects Off the Ground
Tags: opensource, javascript, vue, discuss
Published: 2018-11-02 02:40:50

---
title: Getting an Open Source Projects Off the Ground
published: true
description: What's the best ways to connect potential devs with your project? 
tags: opensource, javascript, vue, discuss
cover_image: https://thepracticaldev.s3.amazonaws.com/i/09s2exnw1pax42692drn.jpg
---

Some of you may remember when I published an article a month or so back on [Binding charts to data in Vue](https://dev.to/ignoreintuition/binding-data-to-charts-using-vue-components-and-d3-4i27).  Since then I have found myself engaged in trying to build out a full featured library of D3 charts for Vue.js.  This has been a great learning experience and by embracing Hacktoberfest I was able to get some contributors to pick up a few features here and there.  Nearly two months in I feel like it is coming together nicely but I don't feel like it is reaching an audience.  Now it could be that this is too niche or because there are other, more mature libraries that provide similar functionality.  I like to think, however, that there is a slice of the development community that would be interested in building out a robust, standards-based, customizable charting library for Vue.

What are some of the things that you have done to get your open source project in front of developers?  Is it just about getting stars (which I would greatly appreciate [wink wink](https://github.com/ignoreintuition/v-chart-plugin)) so that it hits Github's trending page?  Or is there something else to it?  I would love to hear some of your personal experiences and how to build that audience.

Thanks and keep coding.
Episode 1 - Building a JSON API with docker, node.js, and Express
Tags: node, javascript, docker, expressjs
Published: 2018-11-02 02:13:21

---
title: Episode 1 - Building a JSON API with docker, node.js, and Express
published: true
description: Episode one of a video series covering the start to finish of building an application with express.js using docker and other tools.
tags: node.js, JavaScript, docker, express.js
series: building-a-json-api-with-express
---

{% youtube nZg2Nsiv91I %}

Hey everyone. This is part one of a series I'm doing on `express.js` with some docker help. I'd absolutely love feedback, as I'm rather new to the youtube space. 

The source code for the episode is available here: [NathanBland/core s1.ep1](https://github.com/NathanBland/core/tree/s1.ep1)
(it currently lacks a readme so I can't embed it)
Can You Guys Not ❤️🦄📚🏷 Something Like These Posts?
Tags: meta
Published: 2018-11-02 01:51:10

Report these as spam. 
I see them do this almost every night. 

Starts with a post 
.#Hello 
Then off to spam post

![](https://thepracticaldev.s3.amazonaws.com/i/jq72hgejl9sw3yix6p6o.png)
Why isn't my Canonical URL rendering in my first post?
Tags: help
Published: 2018-11-02 01:05:59

---
title: Why isn't my Canonical URL rendering in my first post?
published: true
description: Why isn't my Canonical URL rendering in my first post?
tags: #help
---

Why isn't my first post giving cross-post credit to my blog?

This is my front matter:

```
title: "Pourquoi - et comment - apprendre PL/SQL (…T-SQL…PL/pgSQL…)"
published: true
description: "Pourquoi les bases de données incluent, en plus de SQL, des langages 'procéduraux' -- et comment en apprendre un"
tags: ['explainlikeimfive','discuss','sql','french']
canonical_url: https://katiekodes.com/sql-pourquoi-plsql
cover_image: https://thepracticaldev.s3.amazonaws.com/BlahBlahBlah.png
```

Thanks so much, everybody -- this looks like a great community!
Released the Hope in Source Podcast!
Tags: faith, hope, opensource, community
Published: 2018-11-02 00:45:21

---
title: Released the Hope in Source Podcast!
published: true
description: We released Hope in Source podcast, a 10-episodes series about faith and open source
tags: faith, hope, opensource, community
---

After about 5 months of work (we pre-recorded all the episodes), [Nadia](https://twitter.com/nayafia) and I have released a [podcast](https://hopeinsource.com/) about the parallels between open source and faith (with our own blog posts on why)! It should be interesting to anyone that see value in community, service, and vision in tech or elsewhere or if anyone was curious why/how I think about open source.

Check it out on [Apple](https://itunes.apple.com/us/podcast/hope-in-source/id1437677655?mt=2), [Spotify](https://open.spotify.com/show/5EXwiyKzPrrucncKyrHy0B), [Google](https://www.google.com/podcasts?feed=aHR0cHM6Ly9yc3Muc2ltcGxlY2FzdC5jb20vcG9kY2FzdHMvNzA0OS9yc3M%3D), or our website [hopeinsource.com](https://hopeinsource.com/)

{% tweet 1052290013059153920 %}

I also just published a post about the experience of making a podcast for the first time, which might be helpful whether or not the content is interesting to you!

{% tweet 1057693724275326976 %}

I'm happy to answer any questions here as well!

If you appreciate the work we're doing, you can support me on [Patreon](https://www.patreon.com/henryzhu) and signup for Nadia's [newsletter](https://tinyletter.com/nayafia).
Underrated design patterns
Tags: discuss, design, pattern, coding
Published: 2018-11-02 00:00:40

Thinking back, I mostly used patterns like adapter, strategy, factory, template method - whatever helped me get the job done.

There are some patterns I probably never used, or only used rarely, like flyweight or memento.

What are the more “exotic“ patterns you used? In which context? What pattern is the most underrated?
Modernizing your build pipelines
Tags: ci
Published: 2020-05-04 12:44:57

---
title: Modernizing your build pipelines
published: true
date: 2018-11-02 00:00:00 UTC
tags: Continuous integration
canonical_url: https://hceris.com/modernizing-your-build-pipelines/
---

I have been writing an article about modernizing build pipelines and it finally got published in our [Insights Blog](https://www.thoughtworks.com/insights): [https://www.thoughtworks.com/insights/blog/modernizing-your-build-pipelines](https://www.thoughtworks.com/insights/blog/modernizing-your-build-pipelines)

It ended up being pretty long, but it condenses a couple of months of work. I hope it is useful for anybody who actually reaches the end of it!
Video: Serverless – a new way to build modern applications
Tags: serverless, webinar
Published: 2018-11-13 19:37:19

---
title: Video: Serverless – a new way to build modern applications
published: true
tags: #serverless #webinar
canonical_url: https://maxkatz.org/2018/11/01/video-serverless-a-new-way-to-build-modern-applications/
---

Curious about serverless/function-as-a-service/cloud functions technologies, but haven’t had a chance to dig in? Wondering what all the excitement is about? Serverless doesn’t mean no servers. It’s a new way to build modern applications. Watch this video to learn more about this new approach to building modern applications. The video covers:

- The current state of the serverless ecosystem & major players
- Recognized ideal use cases for serverless solutions
- Best practices for serverless architecture
- Good sources of information to keep abreast of new developments
- Live coding example

{% youtube 3D-4zhQNfTE %}

If you want to learn more about this topic, please read this blog post: [Serverless – simply an approach to building modern applications?](https://dev.to/maxkatz/serverless--simply-an-approach-to-building-modern-applications-395g-temp-slug-6408986)
An article a day for November?
Tags: motivation, learning, discuss, writing
Published: 2018-11-01 22:16:57

---
title: An article a day for November?
published: true
description: Write a dev.to article every day during November. Hardly an original idea - more sharing to keep me motivated.
tags: motivation, learning, discuss, writing
---
Very quick idea. Would anyone else be up for trying to write a dev.to article a day during the rest of November?

This is, of course, a big cheat on my part because I'm counting this as my first one.

---

My lesson for the day was to always stash your code. Even for experiments. 

This post by @srebalaji saved me quite a bit of time. 

{% link https://dev.to/srebalaji/useful-tricks-you-might-not-know-about-git-stash-117e %}

Long story short I was asked to see if something was possible with our code several months ago. I did the experiment we agreed it worked but not to implement it. 

Because our Git branching is already pretty Byzantine I didn't do what I should have done and create a branch for it. Luckily though I did stash it with an almost sensible label.

Today I was asked to make the change, and thanks to having a stashed copy the code was still findable.

Looking back there are a couple of learns for me. Ones I really should have learned long ago.

* Always keep your code safe.
* People do change their minds or come back to things
* A stash can sometimes save your bacon.
Simple TDD in 5 minutes in Ruby
Tags: ruby, tdd, tutorial
Published: 2018-11-01 22:14:35

---
title: Simple TDD in 5 minutes in Ruby
published: true
description: 
tags: Ruby, TDD, Tutorial
---

Considering my exaggerated title, I will try to explain it briefly. 

The test driven is a huge advancement from Kent Beck that enhances developer confidence and code quality and slows the developer's hair whitening. Although it has been popular for 10 years, I still see people saying that this technology is difficult. I don't think so. The technology itself is very simple. Below I use a simple example to illustrate.

#Create directory

I use a simple calculator to illustrate, create an empty directory calc-tdd

```bash
mkdir calc-tdd
cd calc-tdd
touch test_calc.rb
touch calculator.rb
```

Now that we have the directory and two files, let's start writing the code test\_calc.rb and write the test first.

#Write Test

```ruby
#test_calc.rb

require "minitest/autorun"

require "./calculator.rb"

class TestCalculator < MiniTest::Test
    def test_add
        calc = Calculator.new
        assert calc.add(1, 2) == 3
    end
end
```

After the test is finished, you can run it.

```bash
ruby test_calc.rb
```

The result will be reported because the code has not been implemented.

# Implementation code

```ruby
#calculator.rb

class Calculator
    def add(a, b)
        a + b
    end
end
```

Ok, run the test again and you will find the code passed. It’s simple enough, look at the watch for five minutes.

Next you can add a subtraction test sub yourself.

Follow-up can learn the usage of setup and teardown, and of course there are many things worth learning, such as RSpec.

# in conclusion

TDD is a huge improvement, and the basic concept is simple. Of course, the test itself is a complex field, and there is still a lot to learn to become a test expert.
Challenge: Parse simple and complex types from a string
Tags: challenge, javascript
Published: 2018-11-01 21:00:44

---
title: Challenge: Parse simple and complex types from a string
published: true
description: 
tags: challenge, javascript
---

# The Challenge

Create a function to parse to parse the signatures into an array of types. There are two types one is simple like `Apple`, the other is complex like `(Banana -> Grape)`. There could be any number of Arrows, even in the complex type.

```javascript
"Apple" //=> ["Apple"]
"Apple -> Banana -> Grape" //=> ["Apple", "Banana", "Grape"]
"(Apple -> Banana) -> Grape" //=> ["(Apple -> Banana)", "Grape"]
"Apple -> (Banana -> Grape)" //=> ["Apple", "(Banana -> Grape)"]
"Apple -> (Banana -> Grape) -> Cherry" //=> ["Apple", "(Banana -> Grape)", "Cherry"]
```

```javascript
function parseSignature(signature) {
  /* insert code here */
}

parseSignature("Apple -> (Banana -> Grape) -> Cherry")
//=> ["Apple", "(Banana -> Grape)",  "Cherry"]
```

Fun tip: This has a real world use case as it is part of the hindley milner signature pattern used by Haskell or the [Fantasy Land](https://github.com/fantasyland/fantasy-land#type-signature-notation) specification.