Skip to content

Instantly share code, notes, and snippets.

View mofas's full-sized avatar

Chung Yen Li mofas

View GitHub Profile
@mofas
mofas / test.js
Last active March 26, 2016 12:37
CodeMod: Insert import react-addons-pure-render-mixin after import react
import React from 'react';
import Immutable from 'immutable';
import classnames from 'classnames';
@mofas
mofas / test.js
Last active March 26, 2016 12:29
CodeMod: remove const {PureRenderMixin} = React.addons;
let React = {};
React.addons = {
PureRenderMixin: null,
};
const {PureRenderMixin} = React.addons;
const {a, b} = React.addons;
@mofas
mofas / test.js
Created March 26, 2016 09:37
CodeMod: remove refs.getDOMNode() expression
var getDOMNode = 123;
const getDOMNode = () => {
return this.refs;
}
var test = getDOMNode();
getOffset(this.refs.root.getDOMNode());
this.refs.presetMenu.getDOMNode();
@mofas
mofas / codemod_example_1.js
Last active May 1, 2016 13:01
Change all var to const
//Example: https://astexplorer.net/#/E25QuXone4
//test_1.js
var var1 = 'var';
//we want to change it to
//const var1 = 'var';
//start template
export default function transformer(file, api) {
const j = api.jscodeshift;
@mofas
mofas / constructor
Last active September 24, 2017 18:21
sublime snippet for react
<snippet>
<content><![CDATA[
constructor(props) {
super(props);
this.state = {
${1}
}
}
]]></content>
<tabTrigger>con</tabTrigger>
@mofas
mofas / checkgit.sh
Created August 29, 2016 06:49
checkgit.sh
#
# This script determines if current git state is the up to date master. If so
# it exits normally. If not it prompts for an explicit continue. This script
# intends to protect from versioning for NPM without first pushing changes
# and including any changes on master.
#
# First fetch to ensure git is up to date. Fail-fast if this fails.
git fetch;
if [[ $? -ne 0 ]]; then exit 1; fi;
@mofas
mofas / decode_json_to_html.elm
Last active October 28, 2016 14:29
decode json to html
import Html exposing (..)
import Debug exposing (..)
import List exposing (..)
import Json.Decode exposing (..)
jsonStr : String
jsonStr = """
[
{
@mofas
mofas / point-free.expression.rewrite.js
Last active September 18, 2016 06:02
FP practice
const id = 'archie_is_good_guy';
// you may change listSetting for testing.
const listSetting = [];
//original function.
const targetListSetting = listSetting.filter(dd=>{
return id === dd.bfid || id === dd.name_list_id;
})[0];
//point-free experssion rewrite
@mofas
mofas / .vimrc
Created September 20, 2016 09:09
call plug#begin('~/.vim/plugged')
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'scrooloose/nerdtree'
Plug 'tpope/vim-repeat'
Plug 'jiangmiao/auto-pairs'
Plug 'airblade/vim-gitgutter'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'itchyny/lightline.vim'
//immutable_fractal_updater
state = [
{
key: 'key1'
value: true,
children: [
{
key: 'key4'
value: true,