teleren/devto huggingface dataset:
How to test PublishSubject in RxSwift
Tags: swift, rxswift, test, publishsubject
Published: 2019-04-29 14:16:28

---
title: How to test PublishSubject in RxSwift
published: true
description: 
tags: swift,rxswift,test,publishsubject
---

- RxBlocking does not work with Variable and PublishSubject, see https://github.com/ReactiveX/RxSwift/blob/0b66f666ba6955a51cba1ad530311b030fa4db9c/Tests/RxSwiftTests/Observable%2BSubscriptionTest.swift#L165

## Use homemade `Recorder`

```swift
class Recorder<T> {
    var items = [T]()
    let bag = DisposeBag()

    func on(arraySubject: PublishSubject<[T]>) {
        arraySubject.subscribe(onNext: { value in
            self.items = value
        }).disposed(by: bag)
    }

    func on(valueSubject: PublishSubject<T>) {
        valueSubject.subscribe(onNext: { value in
            self.items.append(value)
        }).disposed(by: bag)
    }
}
```

Then test

```swift
final class BookViewModelTests: XCTestCase {
    func testBooks() throws {
        let expectation = self.expectation(description: #function)
        let recorder = Recorder<Book>()
        let viewModel = BookViewModel(bookClient: MockBookClient())
        recorder.on(arraySubject: viewModel.books)
        viewModel.load()

        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.5, execute: {
            expectation.fulfill()
        })

        wait(for: [expectation], timeout: 2)
        XCTAssertEqual(recorder.items.count, 3)
    }
}
```

Need to use great `timeout` value as `DispatchQueue` is not guaranteed to be precise, a block needs to wait for the queue to be empty before it can be executed

## Make `expectation` less cumbersome

```swift
extension XCTestCase {
    func waitOrFail(timeout: TimeInterval) {
        let expectation = self.expectation(description: #function)

        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + timeout, execute: {
            expectation.fulfill()
        })

        wait(for: [expectation], timeout: timeout + 2)
    }
}

```


❤️ Support my apps ❤️ 

- [Push Hero - pure Swift native macOS application to test push notifications](https://onmyway133.com/pushhero)
- [PastePal - Pasteboard, note and shortcut manager](https://onmyway133.com/pastepal)
- [Quick Check - smart todo manager](https://onmyway133.com/quickcheck)
- [Alias - App and file shortcut manager](https://onmyway133.com/alias)
- [My other apps](https://onmyway133.com/apps/)

❤️❤️😇😍🤘❤️❤️
My developer profile page built with VuejS + Gridsome
Tags: vue, gridsome, resume, cv
Published: 2019-04-29 14:12:20

---
title: My developer profile page built with VuejS + Gridsome
published: true
description: My developer profile page built with VuejS + Gridsome
tags: vuejs,gridsome,resume,cv
---

I've built my developer profile with VueJS + Gridsome over the weekend. 
![](https://github.com/ittus/vue-developer-profile/raw/master/docs/images/gridsome_vue.png)

If you're interested, please take a look.

Demo: https://me.coddeine.com/
Github: https://github.com/ittus/vue-developer-profile

![](https://github.com/ittus/vue-developer-profile/blob/master/docs/images/promote.png?raw=true)

I'm glad to receive your comment.
Welcome Thread - v32
Tags: welcome
Published: 2019-04-29 13:56:13

---
title: Welcome Thread - v32
published: true
description: Introduce yourself to the community!
tags: welcome
---

Hey there! Welcome to dev.to!

![Pusheen Hi](https://media.giphy.com/media/L3nWlmgyqCeU8/giphy.gif)
Leave a comment below to introduce yourself to the community! ✌️

Here are some ideas to get you started:

1. You can talk about what brought you here, what you're learning, or just a fun fact about yourself.

2. Reply to someone's comment and say hello or ask them a question. 👋

3. Or answer this question: How did you get into programming, and what would you recommend to a newcomer today?
Typescript: No Index Signature
Tags: typescript
Published: 2019-04-29 14:54:23

---
title: Typescript: No Index Signature
published: true
tags: [typescript]
canonical_url: https://scottw.com/typescript-index-signature
---

I have been spending some free time dabbling in Typescript.

One thing recently caught me off guard. I had a simple object which looks like this:

```
const unitsOfTime = {
  millisecond: 1,
  second: 60,
  hour: 60 * 60,
  day: 24 * 60 * 60,
  month: 30 * 24 * 60 * 60,
  year: 365 * 24 * 60 * 60
}

```

In my initial testing, I was using it like this: `unitsOfTime.day` and all was well. However, once I switch to something a bit more dynamic (`unitsOfTime[someParameter]`) the Typescript compiler started to complain about a missing _index signature_.

After a brief search, I was led to this [PR](https://github.com/Microsoft/TypeScript/pull/7029)[^1].

> With this PR an object literal type is assignable to a type with an index signature if all known properties in the object literal are assignable to that index signature. This makes it possible to pass a variable that was initialized with an object literal as a parameter to a function that expects a map or dictionary

In hindsight this makes sense. There is no guarantee this dictionary is going to return a number at this key[^2].

The fix is to supply a type signature to the dictionary: `{[unit: string] : number}`

Here is the full object:

```
const unitsOfTime : {[unit: string] : number} = {
  millisecond: 1,
  second: 60,
  hour: 60 * 60,
  day: 24 * 60 * 60,
  month: 30 * 24 * 60 * 60,
  year: 365 * 24 * 60 * 60
  }

```

[^1]: By Anders Hejlsberg! I have been out of the Microsoft ecosystem for quite a while, so it still blows my mind to see this both on Github and PR’s by Anders himself.

[^2]: This is much more interesting for a function that receives a dictionary as a parameter (as is in the PR description). In this specific case, it helps to call out what is expected, but it still does not guarantee `unitsOfTime` always returns a number (it could still return a null if the key is missing. Still, it is a step in the right direction.
The 7 Most Popular DEV Posts from the Past Week
Tags: top7
Published: 2019-04-29 13:18:28

---
title: The 7 Most Popular DEV Posts from the Past Week
published: true
description: A round up of the most-read and most-loved contributions from the community this past week.
tags: icymi
cover_image: https://thepracticaldev.s3.amazonaws.com/i/sfwcvweirpf2qka2lg2b.png
---
Every Monday we round up the previous week's top posts based on traffic, engagement, and a hint of editorial curation. The typical week starts on Monday and ends on Sunday, but don't worry, we take into account posts that are published later in the week. ❤️

#1. Take a Peek 👀

Have you ever how Python code is executed? Lachlan dives head-first in into Python bytecode in this post. 

{% link https://dev.to/lachlaneagling/a-peek-inside-python-the-how-what-and-why-of-bytecode-go1 %}

#2. Reduce Clutter

Tracy teaches us how to reduce clutter when designing anything visual (from your personal website to slides for a talk) and walks us through an example.

{% link https://dev.to/tracymakes/design-for-non-designers-part-1-28m2 %}

#3. Not a Trap!

If you're prone to growing your reading list without actually reading anything, you'll appreciate this short-list of machine learning books. 

{% link https://dev.to/strikingloo/3-machine-learning-books-that-helped-me-level-up-as-a-data-scientist-15lm %}


#4. Git is Great

Eyar put together a cheatsheet of useful git commands! Since git commands aren't the most intuitive, this list is good to have handy.

{% link https://dev.to/datreeio/10-insanely-useful-git-commands-you-wish-existed-and-their-alternatives-8e6 %}

#5. Begin your journey today!

A go-to list of resources for anyone starting their career as a developer, or contemplating it. Molly covers everything from bootcamps to how-to guides to brutal honesty.

{% link https://dev.to/molly_struve/if-you-are-a-new-developer-start-here-4b78 %}

#6. Fresh Slate

Have you ever been so fed up by your configs with an app that you just re-install it? That's what Aman did with VS Code. In this post, they share their new set up.

{% link https://dev.to/amanhimself/how-i-configure-vscode-for-everything-23c9 %}

#7. Google "Gantt"

^ That's what I had to do when I learned this post was all about Gantt charts 😂
Rick shares a few tricks on how to use Google Sheets for project management.

{% link https://dev.to/rick_viscomi/project-management-in-google-sheets-4h5c %}

_That's it for our weekly wrap up! Keep an eye on dev.to this week for daily content and discussions...and if you miss anything, we'll be sure to recap it next Monday!_
Announcing a new podcast: Developer Side Quests
Tags: podcast
Published: 2019-04-28 20:03:42

---
title: Announcing a new podcast: Developer Side Quests
published: true
description: Announcing my new podcast and looking for guests.
tags: #podcast 
---
Something we've all done at one point or...hundreds, is creating a side project to learn something, play with new technologies, or to build something we just want to exist. The point of this new show is to talk about what we do to level up our development skillset outside of our day jobs. So that's where this new podcast comes in, to highlight those stories. I hope you'll give it a listen and tell your friends and other player characters out there.

In addition to that, I'm always looking for guests. If you have a side project you're just starting, half-way through, previously finished, or only thinking about, I would love to have you on the show. You can send a direct message on Twitter to @DevSideQuests, or an email to DeveloperSideQuests@outlook.com. 

Don't feel self-conscious if you think no one will care about what you've done. Everyone levels up from somewhere. And everyone learns differently. So your perspective is unique to you and I want to tell other people about it.

I'm still trying to get all this pushed out to all podcast apps, but the big ones are already there with links on the site, DeveloperSideQuestsPodcast.com.
The Building an Indie Business Podcast- Dogs and Web Development
Tags: podcast
Published: 2019-04-29 12:57:34

---
title: The Building an Indie Business Podcast- Dogs and Web Development
published: true
description: 
tags: podcast
---

https://overcast.fm/+RG5g4p2UA

[Episode Page](https://baib-podcast.com)
[Revenue Research](https://revenueresearch.co/)
CSS & JS Camp 2019
Tags: vuild, css, javascript, conference
Published: 2019-05-08 12:15:31

---
title: CSS & JS Camp 2019
published: true
tags: Vuild, CSS, JS, Conference
canonical_url: https://vuild.com/css-camp
---

![CSS & JS Camp](https://vuild.com/wp-content/uploads/css-camp.jpg)

OK:
Check out the [HTML & CSS](https://vuild.com/css-camp)

Good:
Check out [CSS Camp](https://csscamp.tech) & [JS Camp](https://jscamp.tech) events.

Better:
Follow the founder [@davidpich](https://dev.to/davidpich) as he just signed up to dev.to.

Best: 
Go to the after party with secret special guests in Barcelona on July 17-18-19 of this year. 

David was worried I will spam you, I am worried this is not spammy enough (I made a CSS logo!) so meet at camp to decide. It will be the first one so you can hold it over people's head as authenticity points for a lifetime & Barcelona is a nice warm place to CSS & JS in + there will be party things. We can throw things at CSS in JS people too.

I am already working on getting them to give out swag & prizes stay tuned. If you would like to go but can't afford it, send a msg & we'll see what happens. No promises, I'm not a you-get-a-car person, but if you'd love to go but can't afford it, let's see if we can all work out how you can. 

Please share or tell anyone who may be interested. I am not being paid for this, I should be but David is just a person trying to help people. I am a person trying to help a person helping people.

If this annoys you, sorry. Leave a comment below to let me know (It'll help trigger the pop algos).
redux-saga without redux
Tags: redux, reduxsaga, react
Published: 2019-04-29 12:56:01

---
title: redux-saga without redux
published: true
description: 
tags: redux,redux-saga,react
---
This article is based on [the blog post](https://qiita.com/tqm1990/items/5e6cb017d4f6675636c7) that I wrote in Japanese.

This is my first tec article written in English.
I know my article is including a lot of grammar errors but It is one of my challenge. 

# Why ?

I wanted a concurrent processing like redux-saga but did not want depending on redux.
then, I tried to use redux-saga without redux.   

# How to do it
redux-saga has runSaga(options, saga, ...args) as a External API which anyone might not know.

The api is used to be called out of a context of redux-saga to run a saga.
see below:
https://redux-saga.js.org/docs/api/

Let's get started to write small code.

```javascript
// helper.js
const sagaOptionSingleton = (() => {                                                                                              

	let channelStd = stdChannel();
	let emitter = new EventEmitter();
 
 	emitter.on("action",channelStd.put);
 
 	return {
 	  	channel:channelStd,
 		dispatch:output => {
			emitter.emit("action",output);
 		},
 		getState:() => {}
 	};
 })();

export function runSagaWithFixedOpt(saga){                                                                                                            
  runSaga(sagaOptionSingleton,saga);
}
```
One of the important thing is that stdChannel has been given to the option.
I think the API doc does not describe that stdChannel is an interface that is buffering some actions put by a saga in a saga context.
It should be implemented by a singleton pattern.

Therefore, I wrote a self executing function to create the sagaOptionSingleton that is used to set to the option.
Finally, redux-saga did not depend on redux !
  
for that reason, "put" as a side effect of redux-saga, does not make any effects to the store of redux. 
If we want to write something to the store, 
we use store.dispatch() . 

I got a pure redux ! 

but, how to notify events from mapDispatchToProps in react-redux ?
It can not do it for that reason.
instead, I am going to write a wrapper function like below:
```javascript
// helper.js
export function sendToSaga(data){
    function* sendSomethingToSaga(){    
       yield put(data);
    }
    runSagaWithFixedOpt(sendSomethingToSaga);
}
```
It is trying to send an event by the way that running a saga out of saga context and doing put action.
then,
I wrote a code for mapDispatchToProps like below:

```javascript
const mapDispatchToProps = dispatch => {
  return {
    increment: () => {
      sendToSaga({ type: 'INCREMENT' });// Send a event to saga
    }
  }
}
``` 

# Conclusion

We can use redux-saga without redux.
How to Build a Dapp Like Cryptokitties ? 
Tags: dapp, dappdevelopment, cryptokitties
Published: 2019-04-29 12:30:32

---
title: How to Build a Dapp Like Cryptokitties ? 
published: true
description: Here we can discuss the list of steps to be followed to build a dapp like cryptokitties
tags: dapp,dappdevelopment,cryptokitties
---

Cryptokitties is an ethereum based dapp which is made up of a game nature, where anyone can buy, sell and breed charming virtual cats and kitties in exchange of ethereum. This dapp run on ethereum blockchain which is launched on November 28, 2017, by a Canada based software company Axiom Zen Inc.
##How to build a dapp like cryptokitties ?
You can create a dapp like cryptokitties in two ways. 
Using the open source code 
And by leveraging a blockchain like TRON Which favors creating entertainment-based dapps.
##Using Open Source Code:
You must have some basic development skill to understand the cryptography algorithm and must have the basic knowledge to develop a dapp in the blockchain.
##Skills required : 
Expertise to handle Development tools 
Must be capable of writing smart contracts and auditing it.
UI/UX Design
Testing skills
##Steps To Create A DApp In Ethereum 
Create an account on ethereum dapp
Setup dapp development tools
Review the smart contracts of cryptokitties
Code  your own smart contracts 
Test, and Run Your Smart Contracts
##Cryptokitties smart contracts can be divided into smaller as below
 **KittyAccessControl**  - This contract defines who is having full access control over a kitty
**KittyBase**- it defines the attributes of a kitty like a birth time, Gene Code.
 **Kittyownership** - This defines the kitties as tokens, these tokens are fungible tokens and are written on ERC721. The ownership of a kitten is tangible.
 **Kittybreeding** - This Contract used while the players breeding a kitten.
**Genescience**- the core concept of the crypto kitty hold by this smart contract. (i.e) The fun of the game is making a new breed. If the gene codes are open to everyone, then anyone can make a rare breed by comparing it with other kitty code. So the fun will get reduced, and will not excite the users. So the Creators made it a closed contract.
**KittyAuctions**: It has the detail of buying and selling of kittens through smart contracts.
**KttiyMinting**: This contract defines the opportunities of creating gen0 kittens.
**Kittycore**:This is the core contract, which combines everything together to work properly
##Why TRON Can Be A Better Option To Create A DApp Like Cryptokitties
We know the crypto kitty has been created on the ethereum blockchain, but the TRON is a blockchain just similar like ethereum which favors the developer to create entertainment-based dapp on TRON network. 
Source : [**Bitdeal**](https://www.bitdeal.net/how-to-build-a-dapp-like-cryptokitties)
UnityでDaydreamコントローラーのGesture C APIを使う
Tags: unity3d, daydream, miragesolo
Published: 2019-04-29 12:19:00

---
title: UnityでDaydreamコントローラーのGesture C APIを使う
published: true
tags: Unity, daydream, MirageSolo
date: 20190429T12:19Z
canonical_url: https://qiita.com/shiena/items/76ff6972f314b7bde2fc
---
# はじめに

Daydreamは[Gesture C API](https://developers.google.com/vr/reference/android-ndk/group/gesture)がありタッチパッドについて以下のような機能を使えます。
このAPIはAndroid NDKのみに提供されていているのでUnityから扱えるようにしました。

* スワイプ判定 (開始、スワイプ中、終了、スワイプ)
* スワイプ方向の判定(上下左右)
* スワイプ速度(X軸とY軸)
* スワイプ移動量(X軸とY軸)
* 長押し判定

# 使い方

**ソース**

https://gist.github.com/shiena/d2cbd2bd100cc9ed7db4b4dfd608feca から2つのソースをコピーしてUnityプロジェクトに入れます。

**使い方**

```cs
using UnityEngine;

public class GestureTest
{
	[SerializeField] private GvrGesture gvrGesture;

	void Update()
	{
		var gestures = gvrGesture.GetGesture();
		if (gestures.Count > 0)
		{
			foreach (var g in gestures)
			{
				Debug.Log($"{g.GestureType}, {g.GestureDirection}, {g.Displacement.x}, {g.Displacement.y}, {g.Velocity.x}, {g.Velocity.y}");
			}
		}

		if (gvrGesture.LongPressed())
		{
			Debug.Log("Long pressed");
		}
	}
}
```

| 機能 | メソッド |
|----|----|
| スワイプ判定 | GvrGesture::GetGesture() |
| 長押し判定 | GvrGesture::LongPressed() |

このAPIがなくてもUnityで同じ事を実現できるのですがあったらあったで便利です。
せっかくなのでUnity Package Managerに対応しようとしたのですが依存先にGoogle VR SDK for Unityを指定できないので断念しました。残念。


# リンク

* [Gesture C API](https://developers.google.com/vr/reference/android-ndk/group/gesture)
* https://gist.github.com/shiena/d2cbd2bd100cc9ed7db4b4dfd608feca
Terrible Interview Questions
Tags: discuss, fun, interview
Published: 2019-04-29 11:27:24

---
title: Terrible Interview Questions
published: true
description: Job interview questions which are so bad, that they are funny.
tags: discuss, fun, interview
cover_image: https://thepracticaldev.s3.amazonaws.com/i/6s7jj2wm2ttf9kiebqh0.jpg
---

Lets have some fun, and come up with the worst job interview question you can think of.

We have all heard about the job interview questions which are simply bad. Questions which test no practical skill, like asking people to write a quick sort implementation on a whiteboard. Or simply weird questions, which you have no idea about what they could imply, like "Are you a dog person or cat person?".

So let me hear the worst interview questions you can come up with. Which are so bad, that they become funny. (Bonus points if this was an actual question.)
Publishing Postman Collections FTW...literaly!
Tags: postman, collections, templates, competition
Published: 2019-04-29 10:12:47

---
title: Publishing Postman Collections FTW...literaly!  
published: true
description: It's a postman may mashup
tags: Postman,Collections,Templates,Competition
---

Fancy a trip to San Francisco and a ticket to POST/CON, the Postman user conference?? Of course, you do...

All that you need to do is share a collection, as a Postman template, to be in with a chance to win this awesome prize!

All the information and competition details can be found here: 

https://blog.getpostman.com/2019/04/15/its-a-postman-may-mashup/

We would love to see what cool and interesting mashups you can create!!
Design Principles for OOP Brief Summary
Tags: architecture, designpatterns, oop
Published: 2019-04-29 09:39:36

---
title: Design Principles for OOP Brief Summary
published: true
description: 
tags: architecture,designpatterns,oop
---

If you are developing software using object oriented programming, design principles help you a lot, by increasing flexibility and reusability.
All design patterns follow design principles below.

# Liskov Substitution Principle
- Description
	- An instance of superclass must be replaceable by an instance of subclass
	- Therefore, subclass's functionality should be general enough
- Benefit
	- It keeps client code away from being impacted
	- Open-Closed Principle can also be satisfied

# Open-Closed Principle
- Description
	- Class should be open to extension, and closed to change
	- Class is recognized to be closed when design and implementation is completed in the following cases
		- It is tested to function properly
		- All the attributes and behaviors are encapsulated
		- Class and instance do not block the system, and they are confirmed to be stable
- Benefit
	- It keeps stability by preventing unexpected change
	- It allows adding functionality (e.g. by inheritance)

# Dependency Inversion Principle
- Description
	- Access high level generalization
	- Do not directly access low level concrete class
- Example
	- Create an interface which generalizes the concrete class
	- Client accesses only the interface
- Benefit
	- It looses coupling, and realizes flexibility and reusability

# Composing Object Principle (Composition over inheritance)
- Description
	- Extend functionality by composition(aggregation) rather than by inheritance
- Example
	- When you want to use some class's functionality, add a property of its instance, rather than inheriting it
- Benefit
	- It looses coupling, by avoiding inheriting all the properties and methods of the superclass

# Interface Segregation Principle
- Description
	- Separate interface, and avoid enforcing to implement unwanted methods
- Benefit
	- It avoids unnecessary dependency, and looses coupling

# Principle of Least Knowledge (Law of Demeter)
- Description
	- Method can only call other methods of the following
		- In the same object
		- Method parameter
		- Object instantiated within the method
		- Instance variable in the same object
- Benefit
	- It looses coupling, by avoiding unnecessary interaction over classes

# Reference
[Coursera Design Patterns](https://www.coursera.org/learn/design-patterns)
[UPDATE] Network Upgrade: Rainforest v.2
Tags: blockchain, opensource, microbitcoin, node
Published: 2019-04-29 08:31:40

---
title: [UPDATE] Network Upgrade: Rainforest v.2
published: true
description: A new update for RFv2 has been added and the activation date has been delayed to block height 915,000
tags: Blockchain,opensource,MicroBitcoin,node
---

A new update for RFv2 has been added and the activation date has been delayed to block height 915,000. Estimated to happen on 5/07 (Tues) at 00:42 UTC

The devs initially added some complexity based on floation point math so that it will make the algo harder to implement on FPGAs/ASICs hardware. However, a bug was found that created different hashes on different architectures. This new update is for resolving that bug and to fully implement Rainforest v2 algorithm.
Check out more details on the fix [here](https://mbc.wiki/d/27-rfv2-upgrade-notes). 

Node Update
[NEWEST Rainforest v2 Release](https://github.com/MicroBitcoinOrg/MicroBitcoin/releases/tag/0.16.7)

Update Countdown
[Rainforest v2 Tracker](https://upgrade.microbitcoin.org/)

---