Skip to content

Instantly share code, notes, and snippets.

View ruyaoyao's full-sized avatar
❣️

Shiny ruyaoyao

❣️
View GitHub Profile
@ruyaoyao
ruyaoyao / js-get-fn-name.js
Created April 3, 2016 05:13 — forked from dfkaye/js-get-fn-name.js
get a javascript function name
function getFnName(fn) {
var f = typeof fn == 'function';
var s = f && ((fn.name && ['', fn.name]) || fn.toString().match(/function ([^\(]+)/));
return (!f && 'not a function') || (s && s[1] || 'anonymous');
}
console.log(getFnName(String)); // 'String'
console.log(getFnName(function test(){})); // 'test'
console.log(getFnName(function (){})); // 'anonymous'
@ruyaoyao
ruyaoyao / for-loops.js
Created April 1, 2016 07:39 — forked from juliocesar/for-loops.js
ES6 - for loops
// ES6 for loops
// =============
// Things in ES6 can be "iterable". Arrays are iterable by default.
var fruits = ['Apple', 'Banana', 'Grape'];
for (var fruit of fruits)
console.log('Fruit: ' + fruit);
function whichTransitionEvent(){
var t;
var el = document.createElement('fakeelement');
var transitions = {
'transition':'transitionend',
'MSTransition':'msTransitionEnd',
'MozTransition':'transitionend',
'WebkitTransition':'webkitTransitionEnd'
}
@ruyaoyao
ruyaoyao / leftPad.js
Last active March 25, 2016 16:01
leftPad implementation
// ES6 leftPad by Guillermo Rauch
// https://twitter.com/rauchg/status/712799807073419264
export default (v, n, c = '0') => String(v).length >= n ? '' + v : (String(c).repeat(n) + v).slice(-n);
// for ES6 less
function leftPad(v, n, c){
c = c ? '0' : c;
return String(v).length >= n ? '' + v : (String(c).repeat(n) + v).slice(-n);
}
@ruyaoyao
ruyaoyao / udid.sh
Created March 22, 2016 05:38 — forked from x43x61x69/udid.sh
Get UDID / serial number and hardware version of all connected Apple device in OS X.
system_profiler SPUSBDataType | awk '/:$/{sub(/^ */,"");name=$0}/Vendor ID:/{$1=$2=$3="";vender=$0}/Version:/{version=$2}/Serial Number:/{id=$3;print name,version,id,vender}' | grep 'Apple Inc.'
@ruyaoyao
ruyaoyao / invert.js
Created March 9, 2016 07:00 — forked from sofish/invert.js
invert binary tree
function invert(tree) {
if (!tree instanceof Array || tree.length === 1) return tree;
var ret = [];
var inverted = tree.reverse();
for(var cur in inverted) {
if(!inverted.hasOwnProperty(cur)) continue;
ret.push(inverted[cur] instanceof Array ? invert(inverted[cur]) : inverted[cur]);
}
@ruyaoyao
ruyaoyao / gist:041be714455c915a6d0f
Created February 26, 2016 10:01 — forked from wojons/gist:6154645
nginx dont retry next upstream on post or put when timeout error
upstream mash {
ip_hash;
server 127.0.0.1:8081;
server 192.168.0.11:8081;
}
server {
location / {
if ($request_method = POST ) {
@ruyaoyao
ruyaoyao / .bashrc
Created February 22, 2016 06:39 — forked from mapsi/.bashrc
My .bashrc for Mac OSX 10.9.1
## Colorize the ls output ##
alias ls='ls -G'
## Use a long listing format ##
alias ll='ls -la'
## Show hidden files ##
alias l.='ls -d .*'
## Colorize the grep command output for ease of use (good for log files)##
@ruyaoyao
ruyaoyao / Application.scala
Created February 18, 2016 08:21 — forked from jeantil/Application.scala
Playframework 2.2 configurable cors filter
/**
The MIT License (MIT)
Copyright (c) 2013 Jean Helou
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@ruyaoyao
ruyaoyao / CollectionsPredicateFilterSample.java
Created December 9, 2015 07:34 — forked from jackrabb1t/CollectionsPredicateFilterSample.java
a snippet to filter a list - using apache commons collections Predicate class
import static java.lang.System.out;
import static java.util.Arrays.asList;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
public class ListTests {
public static void main( String[] args ) {
List<String> names = asList( "Ted", "Fred", "Jed", "Ned" );