Skip to content

Instantly share code, notes, and snippets.

View gilankpam's full-sized avatar
🏸
Focusing

Gilang gilankpam

🏸
Focusing
View GitHub Profile
const actionRequest = actionName + '_REQUEST'
const actionSuccess = actionName + '_SUCCESS'
const actionFailure = actionName + '_FAILURE'
const initialState = {
data: null,
loading: false,
error: null
}
// we are not using arrow function, because there no arguments binding
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions
function action() {
const args = arguments
return dispatch => {
dispatch({
type: actionRequest
})
try {
const result = fn.apply(this, args)
function middleware({dispatch}) {
return next => action => {
if (typeof action === 'function') {
return action(dispatch)
}
return next(action)
}
}
export const { loginAction, loginActionTypes, loginReducer } = reduxHelper('login', function(username, password) {
return api.login('username', 'password')
})
import loginReducer from './login'
import registerReducer from './register'
import productReducer from './product'
import { combineReducers } from 'redux'
export default combineReducers ({
login: loginReducer,
register: registerReducer,
product: productReducer
import { createStore, applyMiddleware } from 'redux'
import reducers from './reducers'
import myMiddleware from './middleware'
const store = createStore(reducers, applyMiddleware(myMiddleware))
@gilankpam
gilankpam / deep-merge.js
Last active August 15, 2017 09:35
Javascript Deep Merge (Recursive)
// Merge multiple objects
function deepMerges(...objs) {
return objs.reduce((a, b) => deepMerge(a,b), {})
}
// Merge two objects
function deepMerge (one, two) {
if (Array.isArray(one) && Array.isArray(two)) {
return one.concat(two)
}
@gilankpam
gilankpam / clojure.md
Last active July 13, 2017 09:35
LEARNING CLOJURE
  1. Clojure is homophonic language, it means the program structure is similar to its syntax

  2. Every statement evaluate to one value ex (+ 1 2) => 3

  3. ( ) is a list

  4. Lists are call, first element is operator the rest is arguments

  5. No call expression use infix or postfix position

@gilankpam
gilankpam / update_elb.sh
Last active July 11, 2018 09:00
acme.sh hook script for AWS ELB
#!/bin/bash
set -e
# FOR DEBUG
# print all env var
env
ELB_LISTENER_ARN=arn:......
ACME_PATH=~/.acme.sh
@gilankpam
gilankpam / tail.py
Created October 8, 2018 10:54
Tail implementation in python
import io, sys, itertools
def tail(file, line_count):
BUFFER_SIZE = 1024
pos = -BUFFER_SIZE
offset = 0
result_lines = []
result_line_count = 0
while result_line_count < line_count:
file.seek(pos, io.SEEK_END)