Skip to content

Instantly share code, notes, and snippets.

View oshimayoan's full-sized avatar

Yoan Pratama Putra oshimayoan

View GitHub Profile
@oshimayoan
oshimayoan / machine.js
Last active November 3, 2020 06:10
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine({
id: 'prefetchWebView',
initial: 'idle',
context: {
},
states: {
idle: {
on: {
RERENDER: 'isFileExists',
}
@oshimayoan
oshimayoan / machine.js
Created September 28, 2020 06:55
Generated by XState Viz: https://xstate.js.org/viz
// Tallio saved post library
function toggle(action) {
return assign({
posts: (context) => {
let index = context.posts.findIndex((post) => post.id === '1');
let updatedPost = {
...context.posts[index],
saved: action === 'save',
};
@oshimayoan
oshimayoan / machine.js
Last active September 28, 2020 09:39
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@oshimayoan
oshimayoan / machine.js
Last active September 25, 2020 08:10
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@oshimayoan
oshimayoan / config.yml
Created May 11, 2020 09:14
CircleCI config.yml for mirroring a sub-directory from Github repo
version: 2.1
jobs:
mirror:
docker:
- image: circleci/node:lts
steps:
- checkout
@oshimayoan
oshimayoan / config.yml
Created February 1, 2020 03:31
CircleCI config.yml for mirroring Github repo
version: 2.1
jobs:
mirror:
docker:
- image: circleci/node:lts
steps:
- add_ssh_keys:
fingerprints:
@oshimayoan
oshimayoan / mockStorage.js
Created May 3, 2019 08:24
Mocking AsyncStorage
export default class MockStorage {
constructor(cache = {}) {
this.storageCache = cache;
}
setItem = jest.fn((key, value) => {
return new Promise((resolve, reject) => {
return typeof key !== 'string' || typeof value !== 'string'
? reject(new Error('key and value must be string'))
: resolve((this.storageCache[key] = value));
@oshimayoan
oshimayoan / asyncAwait.js
Last active February 21, 2017 09:21
Fetching github users, orgs, and repos and print it.
// @flow
// import fetch from 'node-fetch';
async function fetchUsers(userNames: Array<string>): Promise<*> {
console.log('Start fetching');
console.log('--------------');
for (let userName of userNames) {
let orgs: Array<Object> = await fetch(`https://api.github.com/users/${userName}/orgs`).then((res: Response) => res.json()); // eslint-disable-line
console.log('Fetching user..');
// @flow
function combinedStyles(defaultStyle: Object, newStyle: ?Object) {
if (newStyle) {
return {...defaultStyle, ...newStyle};
}
return defaultStyle;
}
export default combinedStyles;