Skip to content

Instantly share code, notes, and snippets.

Yang Wei yang-wei

Block or report user

Report or block yang-wei

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@yang-wei
yang-wei / BarChart.jsx
Created Aug 7, 2016
react d3 (v4.0) stacked bar chart using rd3
View BarChart.jsx
'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
Porting FixedDataTable to Reagent
View fixed-data-table.cljs
(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))
View note.md
  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 Apr 11, 2016
Clojure fetch url
View fetch.clj
(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")
@yang-wei
yang-wei / decode.md
Last active Sep 24, 2019
Elm Json.Decode tutorial and cheatsheet
View decode.md

When receiving JSON data from other resources(server API etc), we need Json.Decode to convert the JSON values into Elm values. This gist let you quickly learn how to do that.

I like to follow working example code so this is how the boilerplate will look like:

import Graphics.Element exposing (Element, show)
import Task exposing (Task, andThen)
import Json.Decode exposing (Decoder, int, string, object3, (:=))

import Http
@yang-wei
yang-wei / keyValuePairs.elm
Last active May 1, 2019
Json.Decode example
View keyValuePairs.elm
import Graphics.Element exposing (Element, show)
import Task exposing (Task, andThen)
import Json.Decode exposing (Decoder, int, string, object3, (:=), at, keyValuePairs)
import Http
type alias Languages =
List (String, Int)
mailbox =
@yang-wei
yang-wei / bmi.cljs
Created Feb 29, 2016
ClojureScript BMI Calculator
View bmi.cljs
;; -------------------------
;; BMI Calculator
(def bmi-data
(reagent/atom {:height 180
:weight 60}))
(defn slider [min max val param]
[:input {:type "range"
:value val
:min min
@yang-wei
yang-wei / destructuring.md
Last active Dec 13, 2019
Elm Destructuring (or Pattern Matching) cheatsheet
View destructuring.md

Should be work with 0.18

Destructuring(or pattern matching) is a way used to extract data from a data structure(tuple, list, record) that mirros the construction. Compare to other languages, Elm support much less destructuring but let's see what it got !

Tuple

myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))
@yang-wei
yang-wei / README.md
Last active Sep 19, 2019
ES6 destructing (and rest parameter)
View README.md

We will first discussed how destructing and rest parameters can be used in ES6 - in arrays and objects. Then we will look at a few examples and also discuss some quiz.

arrays

var array = [1, 2, 3, 4];
var nestedArray = [1, 2, 3, 4, [7, 8, 9]];

var [a, b, c, d] = array;
console.log(a, b, c, d)
You can’t perform that action at this time.