Skip to content

Instantly share code, notes, and snippets.

@yang-wei
yang-wei / DatePeriodHelper.php
Created December 3, 2016 06:11
DateTime range overlapped ?
<?php
use DatePeriod;
class DatePeriodHelper
{
/**
* @param DatePeriod $datePeriod1
* @param DatePeriod $datePeriod2
@yang-wei
yang-wei / appdelete.m
Created November 28, 2016 13:31
react-native
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "AppDelegate.h"
@yang-wei
yang-wei / country.py
Last active August 18, 2016 01:39
List of country codes (ISO 3166-1 alpha-2)
("AF","AL","DZ","AS","AD","AO","AI","AQ","AG","AR","AM","AW","AU","AT","AZ","BS","BH","BD","BB","BY","BE","BZ","BJ","BM","BT","BO","BQ","BA","BW","BV","BR","IO","BN","BG","BF","BI","KH","CM","CA","CV","KY","CF","TD","CL","CN","CX","CC","CO","KM","CG","CD","CK","CR","CI","HR","CU","CW","CY","CZ","DK","DJ","DM","DO","EC","EG","SV","GQ","ER","EE","ET","FK","FO","FJ","FI","FR","GF","PF","TF","GA","GM","GE","DE","GH","GI","GR","GL","GD","GP","GU","GT","GG","GN","GW","GY","HT","HM","VA","HN","HK","HU","IS","IN","ID","IR","IQ","IE","IM","IL","IT","JM","JP","JE","JO","KZ","KE","KI","KP","KR","KW","KG","LA","LV","LB","LS","LR","LY","LI","LT","LU","MO","MK","MG","MW","MY","MV","ML","MT","MH","MQ","MR","MU","YT","MX","FM","MD","MC","MN","ME","MS","MA","MZ","MM","NA","NR","NP","NL","NC","NZ","NI","NE","NG","NU","NF","MP","NO","OM","PK","PW","PS","PA","PG","PY","PE","PH","PN","PL","PT","PR","QA","RE","RO","RU","RW","BL","SH","KN","LC","MF","PM","VC","WS","SM","ST","SA","SN","RS","SC","SL","SG","SX","SK","SI","SB","SO","ZA
@yang-wei
yang-wei / index.js
Created August 14, 2016 07:38
Gisty is coming
Gisty testing
@yang-wei
yang-wei / README.md
Last active August 14, 2016 07:38
What's so great about transducer ?

This is not a introduction post to Clojure transducer. Instead there are a lots of great introduction post out there. This post aims to clarify the greatness of transduer. In the introduction blog, this is how they describe:

Transducers are composable algorithmic transformations. They are independent from the context of their input and output sources and specify only the essence of the transformation in terms of an individual element. Because transducers are decoupled from input or output sources, they can be used in many different processes - collections, streams, channels, observables, etc. Transducers compose directly, without awareness of input or creation of intermediate aggregates.

This post will help you understand the above statement.

For me transducer does 2 great things

  • Parallel process
  • Independence input source, therefore reuseable
@yang-wei
yang-wei / decorators.js
Created August 7, 2016 14:17
Function decorators
const not = fn => x => !fn(x)
const some = x => x != null
const notAtAll = x => !some(x)
// or
const notAtAll = x => not(some)
@yang-wei
yang-wei / BarChart.jsx
Created August 7, 2016 10:41
react d3 (v4.0) stacked bar chart using rd3
'use strict';
import { scaleOrdinal, schemeCategory20c } from 'd3-scale';
import React from 'react';
module.exports = React.createClass({
displayName: 'BarChart',
propTypes: {
@yang-wei
yang-wei / fixed-data-table.cljs
Created May 4, 2016 15:02
Porting FixedDataTable to Reagent
(ns gannet.components.result-table
(:require [reagent.core :as r]
[gannet.style :as style]
[cljsjs.fixed-data-table]))
(enable-console-print!)
(def Table(r/adapt-react-class js/FixedDataTable.Table))
(def Column (r/adapt-react-class js/FixedDataTable.Column))
(def Cell (r/adapt-react-class js/FixedDataTable.Cell))
@yang-wei
yang-wei / note.md
Created April 27, 2016 10:40
Git tips
  1. git stash, then git stash pop

  2. git commit --amend

  3. git checkout -

  4. コンフリクトのとき動作がう? ====

  5. git add -p

@yang-wei
yang-wei / fetch.clj
Created April 11, 2016 01:07
Clojure fetch url
(defn fetch-url[address]
(with-open [stream (.openStream (java.net.URL. address))]
(let [buf (java.io.BufferedReader.
(java.io.InputStreamReader. stream))]
(apply str (line-seq buf)))))
(fetch-url "http://google.com")