teleren/devto huggingface dataset:
Ruby 2.5.0 Was Released
Tags: ruby, news
Published: 2017-12-26 01:54:28

---
title: Ruby 2.5.0 Was Released
published: true
description: Ruby 2.5.0 is the first stable release of the Ruby 2.5 series.
tags: ruby, news
---

- 5-10% performance boosts, en route to big promised perf boosts for 3.0
- rescue/else/ensure in do blocks now
- New test coverage capabilities for methods and branches

## [Full Release Details Here](https://www.ruby-lang.org/en/news/2017/12/25/ruby-2-5-0-released/)

Looks like a good release to me. Still love me some Ruby.
packagemain 1 - Code review of a triangle package
Tags: go
Published: 2017-12-26 01:53:44

---
title: packagemain 1 - Code review of a triangle package
published: true
description: Go code review
tags: go, golang
---

In this video I am reviewing https://github.com/esimov/triangle Go package.

Pull Request: https://github.com/esimov/triangle/pull/6

https://www.youtube.com/watch?v=HVVthvUGYi8
Singleton Pattern
Tags: designpatterns
Published: 2017-12-26 01:11:24

---
title: Singleton Pattern
published: true
description: Singleton Pattern Implementation
tags: Design Patterns
---

Here is a self reference for the Singleton Pattern that I wrote up.
http://www.smartdevnow.com/2017/12/25/singleton-pattern/

https://twitter.com/RJSchmertz
Get the longest method name in Ruby
Tags: ruby
Published: 2017-12-26 00:53:34

---
title: Get the longest method name in Ruby
published: true
description: 
tags: #ruby
---

It can get the longest method name.

```ruby
p ObjectSpace.each_object(Module).flat_map { |m| m.instance_methods + m.private_instance_methods }.uniq.max_by(&:size)
```

I tried it in local machine. (ruby 2.4.3p205)

```console
:fix_syck_default_key_in_requirements
```
No More Foo, Bar, and Baz
Tags: tutorials, writing, foo
Published: 2017-12-25 21:24:24

---
title: No More Foo, Bar, and Baz
published: true
description: Without tutorials, the world of coders would be lost. But, for the love of God, please stop using foo, bar, and baz in your tutorials.
tags: tutorials, writing, foo
---

When I was a kid, my best friend’s dad owned a computer company and told us he knew the secret to Fubar. He said he was sworn to secrecy and to this day has never divulged the secret. If you’re not familiar with Fubar, he was a 1980s robot whose name stood for Futuristic Uranium Bio-Atomic Robot. He seemed so life-like and I dreamed of owning one as a kid. Of course, now that I look back at old Fubar [videos], it’s pretty clear Fubar was nothing but a big remote control car with a walkie-talkie strapped to his head, probably operated by a guy in a nearby room.

This brings me to my next point. Maybe they’re not related, but I’d like to talk about the use of “foo, bar, baz” in coding tutorials. I’m not quite sure if foo/bar/baz comes from Fubar, but they sound similar enough to make my point.

For those of you who write tutorials, you do such great work and we are appreciative. Without tutorials, the world of coders would be lost. But, for the love of God, please stop using foo, bar, and baz in your tutorials.

Unfortunately this disease has reached epidemic proportions. I recently ran into a tutorial where the writer explained the concept of associations in ActiveRecord using a similar example to below (I’m code-paraphrasing here):

```ruby
class Foo < ActiveRecord::Base
  has_many :bazzes
  has_many :bars, through: :bazzes
end 

class Bar < ActiveRecord::Base
  has_many :bazzes
  has_many :foos, through: buzzes
end 

class Baz < ActiveRecord::Base
  belongs_to :foo
  belongs_to :bar
end 
```

First of all, what the hell is a foo and a baz? We know what a bar is but are we talking about a bar/pub or a parallel bar? And how does it relate to a foo? In what capacity does a foo have many bazzes? For me, so many of these concepts take time to grasp, but make it almost impossible when the examples don’t have concrete meaning grounded in reality. Tutorial writers are much better off using real world examples, like how a tweet belongs to a user, or how a dog has many bones.

So please, keep writing tutorials, but do not use foo, bar, or baz!

[videos]: https://www.youtube.com/watch?v=0b5YWvyLT5o
Clarifying Async and Promises
Tags: javascript, async, promises
Published: 2017-12-25 21:18:35

---
title: Clarifying Async and Promises
published: true
description: I wanted to clearly present async and promises since the concepts were hard for me to understand at first.
tags: javascript, async, promises
---

I wanted to clearly present async and promises since the concepts were hard for me to understand at first. Here’s my attempt:

Synchronous javascript means to wait for one action to complete before moving onto the next. For example, imagine a line of five small tables. On all of the tables is a coin, with the exception of the second table, which contains a spinning top. Your job is to go along to each table, flip the coins and spin the top. If you’re doing this synchronously, you would go to the first table, flip the coin and move to the next table. But at the second table, you spin the top but you can’t move to the next table until the top stops spinning. In the real world, this can lead to a bad user experience if you have to wait for something to finish before the rest of the page loads.

Asynchronous requests solve this problem. Instead of waiting for each function to finish, the action is passed to a thread outside of JS. When the request is fulfilled, it’s added to the end of the thread and the callback function will fire. So in our table example, once you spin the top, you can move onto the next table and flip the coin. When the top stops spinning, the table will get shifted to the end of the queue and be ready once you reach the end of the tables.

This ties into promises. A promise is essentially an object that represents an action that hasn’t finished yet but will finish at some point down the road. This makes it easier to handle multiple async requests. When the promise has resolved, we can use the .then function to do something with the returned data. This also makes it easier to chain .then requests together. For example, if we make a request to a server for a token, we want to wait for the token to come back. Once we receive the token, we parse it, and finally do something with that data.

Another example would be if we had an application that is making three separate API requests. Say one API request is for an image, another for the comments, and another for the user data. But we want to wait for all the data to come back before we update the UI so we can use a promise to wait for all the data to finish and then display it to the user. We can use .all to accomplish this with promises.

As a final example below to illustrate promises, we see that A will fire first. Then a fetch request is fired where we wait for a promise from C and then for D. In the meantime, B is fired while we wait. Once C resolves, it fires, then finally D resolves and it fires.

```javascript
apiCall = () => {
    console.log(‘A')
    fetch('http://someAPI/data')
        .then(res => {
            console.log(‘C’)
            return res.json()
    })
        .then(theData => console.log(‘D’, theData))
        console.log(‘B‘)
}
```
Асинхронный параллельный запуск кода в PHP на примере Laravel Collection
Tags: php, laravel, async, parallel
Published: 2018-02-08 11:59:04

---
title: "Асинхронный параллельный запуск кода в PHP на примере Laravel Collection"
published: true
tags:  php, Laravel, async, parallel
canonical_url: http://phpprofi.ru/blogs/post/90
---

Фреймворк Laravel имеет&nbsp;отличный [класс для работы с коллекциями](https://laravel.com/docs/5.5/collections), который имеет [много полезных операций](https://laravel.com/docs/5.5/collections#available-methods). Класс также является [macroable](https://laravel.com/docs/5.5/collections#extending-collections). Это означает, что к нему можно добавлять функции во время выполнения путем вызова его метода `macro` и передачи названия и замыкания. В наших проектах мы, как правило, пишем один и тот же макрос снова и снова. Вот почему мы вынесли эти макросы в [пакет laravel-collection-macros](https://github.com/spatie/laravel-collection-macros), так что вы можете их использовать.

![](http://phpprofi.ru/resources/img/blogs/ac1cb6d8-6b2b-43b9-b081-d113a13b0d29.jpeg)

В этом посте я хотел бы поговорить немного о [новом макросе](https://github.com/spatie/laravel-collection-macros#parallelmap),&nbsp; называемом `parallelMap`.

----
Читать далее: http://phpprofi.ru/blogs/post/90

----
En: https://murze.be/an-async-map-function
最近のWebサイトについて思うこと
Tags: web
Published: 2018-08-01 01:20:27

---
title: 最近のWebサイトについて思うこと
published: true
tags: web
canonical_url: https://takimura.hateblo.jp/entry/2017/12/26/032008
---

昨今のWebサイトは、表示した後にもそのまま表示し続けると一定間隔で[Javascript](http://d.hatena.ne.jp/keyword/Javascript)が動き、データを更新するタイプのものを散見します。[Twitter](http://d.hatena.ne.jp/keyword/Twitter)等の[SNS](http://d.hatena.ne.jp/keyword/SNS)サイトに多く見られるものですが、これはブラウザを重くしてしまい、[ユーザビリティ](http://d.hatena.ne.jp/keyword/%A5%E6%A1%BC%A5%B6%A5%D3%A5%EA%A5%C6%A5%A3)が良いとはとても言える状態ではありません。  
  
現在、Webサイトにおいては以前とかなり変わってきてるところがあり、Webサイトといってもほぼ[アプリケーションソフトウェア](http://d.hatena.ne.jp/keyword/%A5%A2%A5%D7%A5%EA%A5%B1%A1%BC%A5%B7%A5%E7%A5%F3%A5%BD%A5%D5%A5%C8%A5%A6%A5%A7%A5%A2)のような挙動をするものも増えてきています。  
  
[Read more](https://takimura.hateblo.jp/entry/2017/12/26/032008)
An awesome thread about developers’ careers
Tags: businessandwork, coding, careers
Published: 2017-12-26 15:58:44

---
title: "An awesome thread about developers’ careers"
published: true
tags: Business and work,Coding,Careers,coding
canonical_url: https://pauljacobson.me/2017/12/25/an-awesome-thread-about-developers-careers/
---

Stephanie Hurlburt asked for stories from developers about their career paths [on Twitter](https://twitter.com/sehurlburt/status/945039569291919360), and it quickly became one of the best threads I’ve read in a while. As you can imagine, I have a particular interest in stories about other developers’ careers given [my journey this year](https://pauljacobson.me/2017/12/08/42/). This thread didn’t disappoint.

I started reading the thread when I woke up this morning and, boy, what a great way to start a day.

{% twitter 945039569291919360 %}
genstrings with Swift
Tags: swift
Published: 2017-12-25 12:18:43

---
title: genstrings with Swift
published: true
description: 
tags: swift
---

1st step
Localizable protocol in Localizable.swft

```swift
import Foundation

protocol Localizable {

    var key: String { get }
    var bundle: Bundle { get }
    var comment: String { get }

    var string: String { get }
}

extension Localizable {

    var string: String {

        return NSLocalizedString(key, tableName: nil, bundle: bundle, comment: comment)
    }
}

struct LocalizedString: Localizable {

    let key: String
    let bundle: Bundle = .main
    let comment: String


    init(_ string: String, comment: String) {
        self.key = string
        self.comment = comment
    }
}
```

2nd step
LocalizedStrings struct in LocalizedStrings.swift.

this file is actual Localize settings.
```swift
struct LocalizedStrings {

    static let hoge = LocalizedString("Hoge", comment: "Hoge Comment")
    static let foo = LocalizedString("Foo", comment: "Foo Comment")
}
```


3rd step
run genstrings with 's'option to 'LocalizedStrings.swift'

```
genstrings -s LocalizedString LocalizedStrings.swift
```

4th step
use LocalizedStrings in your code.

```
let foo = LocalizedStrings.foo.string  // getting localized string.
```
Type safe NSViewAnimation
Tags: swift
Published: 2017-12-25 12:09:03

---
title: Type safe NSViewAnimation
published: true
description: 
tags: swift
---

```swift
protocol ViewAnimationTarget {}
extension NSView: ViewAnimationTarget {}
extension NSWindow: ViewAnimationTarget {}

struct ViewAnimationAttributes {

    private(set) var animations: [NSViewAnimation.Key: Any]

    init(target: ViewAnimationTarget, startFrame: NSRect? = nil, endFrame: NSRect? = nil, effect: NSViewAnimation.EffectName? = nil ) {

        animations = [.target: target]
        animations[.startFrame] = startFrame
        animations[.endFrame] = endFrame
        animations[.effect] = effect
    }

    var startFrame: NSRect? {
        get { return animations[.startFrame] as? NSRect }
        set { animations[.startFrame] = newValue }
    }

    var endFrame: NSRect? {
        get { return animations[.endFrame] as? NSRect }
        set { animations[.endFrame] = newValue }
    }

    var effect: NSViewAnimation.EffectName? {
        get { return animations[.effect] as? NSViewAnimation.EffectName }
        set { animations[.effect] = newValue }
    }
}

class ViewAnimation: NSViewAnimation, NSAnimationDelegate {

    var completeHandler: (() -> Void)?

    init(viewAnimations: [ViewAnimationAttributes]) {

        super.init(viewAnimations: viewAnimations.map { $0.animations })
    }

    required init?(coder: NSCoder) {
        fatalError("Can not initialize with NSCoder")
    }

    /// コンプリートハンドラー付き
    /// start with completion handler
    func start(completeHandler: @escaping () -> Void) {

        delegate = self
        self.completeHandler = completeHandler

        start()
    }

    ///
    func animationDidEnd(_ animation: NSAnimation) {

        completeHandler?()
        delegate = nil
        completeHandler = nil
    }
}
```

example

```swift
let view1 = NSView()

// 個々を別々に設定
// divide initialize and setting. 
var animeAttr1 = ViewAnimationAttributes(target: view1)
animeAttr1.startFrame = NSRect(x: 0, y: 0, width: 100, height: 100)
animeAttr1.endFrame = NSRect(x: 100, y: 100, width: 100, height: 100)
animeAttr1.effect = .fadeIn

let view2 = NSView()

// 初期化時に全部設定
// initialize with all setting.
let animeAttr2 = ViewAnimationAttributes(target: view2,
                                         startFrame: NSRect(x: 100, y: 100, width: 100, height: 100),
                                         endFrame: NSRect(x: 0, y: 0, width: 100, height: 100),
                                         effect: .fadeOut)

let animation = ViewAnimation(viewAnimations: [animeAttr1, animeAttr2])

animation.duration = 0.5

// コンプリートハンドラー付きstart
/// start with completion handler
animation.start {
    print("Finish animation")
}
```
Observing notification only once
Tags: swift
Published: 2017-12-25 12:05:32

---
title: Observing notification only once
published: true
description: 
tags: swift 
---

```swift
extension NotificationCenter {

    func addObserverOnce(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) {

        weak var token: NSObjectProtocol?
        token = addObserver(forName: name, object: obj, queue: queue) {notification in

            token.map(self.removeObserver)
            block(notification)
        }
    }
}
```
Servlet API 4.0のJavaDocを日本語に翻訳しました。
Tags: java, servlet
Published: 2017-12-25 09:00:13

---
title: Servlet API 4.0のJavaDocを日本語に翻訳しました。
published: true
description: Servlet API 4.0のJavaDocを日本語に翻訳しました。
tags: java, servlet
---

Servlet API 4.0のJavaDocを日本語に翻訳しました。
以下からどうぞ。

https://megascus.github.io/servlet-spec/docs/apidocs/index.html
How to get a DbContext from a DbSet in EntityFramework Core 2.0.
Tags: dotnet, efcore20, entityframework, netcore
Published: 2017-12-25 03:49:44

---
title: How to get a DbContext from a DbSet in EntityFramework Core 2.0.
published: true
description: This article describes how to get a DbContext from a DbSet in EntityFramework Core.
tags: #dotnet, #efcore20, #entityframework, #netcore
---


In EntityFramework Core programming, You can get a DbContext object from a DbSet object like this:


```csharp
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;

public static class DbContextGetter
{
  public static DbContext GetDbContext<T>(this DbSet<T> dbSet) where T: class
  {
    var infrastructure = dbSet as IInfrastructure<IServiceProvider>;
    var serviceProvider = infrastructure.Instance;
    var currentDbContext = serviceProvider.GetService(typeof(ICurrentDbContext))
                               as ICurrentDbContext;
    return currentDbContext.Context;
  }
}

// How to use:
// 
// class MyDbContext {
//    public DbSet<FooBar> FooBar { get; set; }
// }
// ...
// var myContext = new MyDbContext();
// var contextFromDbSet = myContext.FooBar.GetDbContext();
//                                         ~~~~~~~~~~~~~~
// myContext == contextFromDbSet; // -> true

```

Happy coding :)
Check values of method arguments in Ruby
Tags: ruby
Published: 2017-12-25 01:15:40

---
title: Check values of method arguments in Ruby
published: true
description: 
tags: ruby
---

I try it.

```ruby
method(__method__).parameters.map { |t, v| [v, eval(v.to_s)] }.to_h
```

Example

```ruby
def foo(a = 3, b = 'hello', *test)
  p method(__method__).parameters.map { |t, v| [v, eval(v.to_s)] }.to_h
end

foo #=> {:a=>3, :b=>"hello", :test=>[]}
```
Key questions during an interview
Tags: discuss
Published: 2017-12-25 00:26:40

---
title: Key questions during an interview
published: true
description: 
tags: #discuss
cover_image: http://jasoncarrwrites.com/wp-content/uploads/2016/01/THE-QUESTIONING-MIND.jpg
---

I've had the chance to interview many people at the company I currently work for now and I've found that around 1/10 candidates actually take the chance to ask questions about our stack, roles, activities, etc, even after we explicitly ask them to ask us anything they might be curious about.

So, what are some of the key questions you would ask an interviewer to find out if you would like to join their team?
Released chochoi v0.0.6
Published: 2017-12-25 00:23:22

---
title: Released chochoi v0.0.6
published: true
description: 
tags: 
---


Released [chochoi](https://github.com/karad/chochoi) v0.0.6!

I added `merry` command.

![merry command capt](https://thepracticaldev.s3.amazonaws.com/i/67ajym6231bwcwa2zwrb.png)

You can run below.


```
$ npm i -g chochoi
$ chochoi merry
```
What's Rust good for?
Tags: rust, discuss
Published: 2017-12-24 23:28:45

---
title: What's Rust good for?
published: true
description: lorem ipsum
tags: rust, discuss
---

I'm on my way to learn something new in 2018 and currently looking at Rust. I know Mozilla uses it for some parts of Firefox but I haven't seen any other projects outside of the Firefox ecosystem that uses Rust heavily (maybe I didn't look up good enough?)

So, my question is simple - what's Rust good for?
Active NYC Tech Meetups
Tags: discuss
Published: 2017-12-24 21:24:22

---
title: Active NYC Tech Meetups
published: true
tags: discuss
---

I've come back to the NY area after a few years, and was looking for suggestions on fun and engaging technical meetups of any size and subject. Meetup sometimes doesn't do the _best_ job of surfacing these, so I was wondering what the Dev community could suggest! 

So I'm not just freeloading, I would suggest the [VueNYC](https://www.meetup.com/vueJsNYC/) meetup. It has an active slack channel and held a great event covering simple SSR vs Nuxt, basics with Vuex, and upcoming changes to Vue, when I attended in November.
React Beginner Question Thread ⚛
Tags: react, javascript, beginners, webdev
Published: 2017-12-24 21:01:29

---
title: React Beginner Question Thread ⚛
published: true
description: No question is too simple!
tags: react,javascript,beginners,webdev
---

Hey folks! My name is Dan, and I work on the React team.

I really like the idea of semi-regular “beginner threads” where people can ask simple questions without getting judged. This seems like a great community so I thought: can we try this here? 🙂

We run a [thread like this](https://www.reddit.com/r/reactjs/comments/7hifb6/beginners_thread_easy_questions_december_2017/) on Reddit but to be honest I'm finding Reddit hard to use and very impersonal so I don't hang out there much.

The rules are simple:

1. One question per comment.
1. The questions have to be about React.
1. **No question is too simple!** Seriously, ask away, I don’t bite.
1. Try to keep questions to a few paragraphs at most. If you need a code sample, put it in a [gist](https://gist.github.com) or, better, [a sandbox](https://codesandbox.io/s/new).
1. Please reply to the questions too if you know the answer! I might not be able to reply to all of them although I’ll do my best for this thread.

Note this is an experiment. 😉 I don’t know if enough people here are React users, and if the format is a good fit for this website. If that’s not interesting to you folks that is fine too. Cheers!
Software Transactional Memory in Go
Tags: go, stm, concurrency
Published: 2017-12-24 19:47:22

---
title: Software Transactional Memory in Go
published: true
description: Experimental implementation of software transactional memory in Go
tags: Go, Golang, STM, Concurrency
---

I have recently written [decillion/go-stm](https://github.com/decillion/go-stm/), which is a software transactional memory (STM) implementation for Go. It provides a new way of synchronization to Go programmers, while it is still experimental one. 

The package enables one to atomically execute a sequence of operations on shared variables without explicit locking. I present a simple example below. Please see the repository or a [blog post](https://qiita.com/decillion/items/d5da905e28b54dc769cd) (in Japanese) for further information.

```go

// Initialize two transactional variables.
x := New(0)
y := New(0)

// Define a transaction that transfer 100 from x to y.
transfer := func(rec *TRec) interface{} {
	currX := rec.Load(x).(int) // Read the value of x.
	currY := rec.Load(y).(int) // Read the value of y.
	rec.Store(x, currX-100)    // Write currX-100 to x.
	rec.Store(y, currY+100)    // Write currY-100 to y.
	return nil
}

// Execute the transaction atomically.
Atomically(transfer)
```

If you want to know more about the STM itself, I recommend you to read the article, [Beautiful concurrency](https://www.microsoft.com/en-us/research/publication/beautiful-concurrency/), written by Simon Peyton Jones.


There has been [another STM package](https://github.com/lukechampine/stm) written by lukechampine. It provides a richer STM interface but is less performant than the present package. Here is the result of a very simple benchmark, in which two transactional variables are atomically incremented or read. The benchmark is taken at Ubuntu 17.10 on a DigitalOcean's High CPU Droplet with 32 cores.

    Benchmark_Read90Write10_decillion-4      	10000000	       156 ns/op
    Benchmark_Read90Write10_decillion-8      	10000000	       144 ns/op
    Benchmark_Read90Write10_decillion-16       	10000000	       214 ns/op
    Benchmark_Read90Write10_decillion-32       	 5000000	       289 ns/op

    Benchmark_Read90Write10_lukechampine-4   	 2000000	       761 ns/op
    Benchmark_Read90Write10_lukechampine-8   	 2000000	       822 ns/op
    Benchmark_Read90Write10_lukechampine-16    	 2000000	       912 ns/op
    Benchmark_Read90Write10_lukechampine-32    	 2000000	       966 ns/op