Skip to content

Instantly share code, notes, and snippets.

View broerjuang's full-sized avatar
🏠
Working from home

Juang Wiantoro broerjuang

🏠
Working from home
View GitHub Profile
@broerjuang
broerjuang / binaryTranslator.js
Last active September 11, 2016 19:23
Small Little Project
function stringInp(string) {
var stringSep = string.split("");
for (var i = 0; i < stringSep.length; i++ ) {
stringSep[i] = stringSep[i].charCodeAt(0).toString(2);
}
return stringSep;
}
stringInp("Bagus Juang").join(" ");
@broerjuang
broerjuang / recursion.js
Last active December 7, 2016 19:04
Learning about recursion using Javascript
// this function takes an array and double each component inside it
const double = (nums) => {
if(nums.length === 0) {
return []
} else {
return [2 * nums[0]].concat(double(nums.slice(1, nums.length)))
}
}
console.log(double([1,2,3,4]), "should be [ 2, 4, 6, 8 ]")
@broerjuang
broerjuang / Collection.js
Created January 23, 2017 09:25
Comparing between class and factory function when creating object
// @flow
type ItteratorFunction = (key: string, value: mixed) => void;
type DataItem = {
key: string;
value: mixed;
};
type Data = {
[key: string]: DataItem;
@broerjuang
broerjuang / git tutorials.md
Created July 4, 2017 16:24 — forked from jaseemabid/git tutorials.md
Awesome git tutorials I am finding here and there
@broerjuang
broerjuang / thinkingInReact.re
Created February 9, 2018 18:39
This is the implementation of thinking in react using reason
type product = {
category: string,
price: string,
stocked: bool,
name: string
};
type products = list(product);
let products = [
module Utils = {
let rec repeat = (whatToRepeat, howManyTimes) =>
switch howManyTimes {
| 0 => ""
| someNumber when howManyTimes > 0 => whatToRepeat ++ repeat(whatToRepeat, howManyTimes - 1)
| _ => ""
};
let rec makePairFromList = (xs) =>
switch xs {
| [] => []
@broerjuang
broerjuang / ReactNativeWeb.re
Created May 4, 2018 05:37
Binding of react native web
let option_map = (fn, opt_value) =>
switch (opt_value) {
| None => None
| Some(value) => Some(fn(value))
};
module View = {
[@bs.module "react-native-web"]
external _view : ReasonReact.reactClass = "View";
let make =
@broerjuang
broerjuang / simpleFractalRec.re
Created June 8, 2018 19:34
simple fractal 1
open Reprocessing;
let width = 640;
let height = 360;
let rec drawRec = (~x, ~y, ~dimension, env) => {
Draw.stroke(Constants.black, env);
Draw.strokeWeight(1, env);
Draw.noFill(env);
Draw.rect(~pos=(x, y), ~width=dimension, ~height=dimension, env);
@broerjuang
broerjuang / fractalsTree.re
Created June 9, 2018 08:56
Fractals Tree
open Reprocessing;
module Constants = {
module Window = {
let width = 600;
let height = 600;
};
module Color = {
let black = Constants.black;
@broerjuang
broerjuang / asyncAction.js
Last active September 13, 2018 19:23
Redux Context
async function getUsersAsync(dispatch) {
dispatch({ type: "FETCH_REQUESTED" });
try {
let data = await fetch("https://api.github.com/users").then(res =>
res.json()
);
dispatch({ type: "FETCH_SUCCEED", data });
} catch (error) {
dispatch({ type: "FETCH_FAILED", error: error });
}