Skip to content

Instantly share code, notes, and snippets.

View ruyaoyao's full-sized avatar
❣️

Shiny ruyaoyao

❣️
View GitHub Profile
@ruyaoyao
ruyaoyao / getparam.js
Last active August 29, 2015 14:23 — forked from varemenos/getparam.js
// Given a query string "?to=email&why=because&first=John&Last=smith"
// getUrlVar("to") will return "email"
// getUrlVar("last") will return "smith"
// Slightly more concise and improved version based on http://www.jquery4u.com/snippets/url-parameters-jquery/
function getUrlVar(key){
var result = new RegExp(key + "=([^&]*)", "i").exec(window.location.search);
return result && unescape(result[1]) || "";
}
#
# A CORS (Cross-Origin Resouce Sharing) config for nginx
#
# == Purpose
#
# This nginx configuration enables CORS requests in the following way:
# - enables CORS just for origins on a whitelist specified by a regular expression
# - CORS preflight request (OPTIONS) are responded immediately
# - Access-Control-Allow-Credentials=true for GET and POST requests
@ruyaoyao
ruyaoyao / gist:0394dc3b2eccb89fb30a
Last active September 9, 2015 01:11 — forked from peel/gist:ca8c5b25efbe3052fdb5
SJ4000 WIFI Protocol

#Base URL http://192.168.1.254

File Management Panel

GET / file management panel

Configuration options

all options follow the template: /?custom=1&cmd={Command}&par={Option} Command - setting/mode of the device

@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" );
@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 / .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 / 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 / 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 / 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.'
function whichTransitionEvent(){
var t;
var el = document.createElement('fakeelement');
var transitions = {
'transition':'transitionend',
'MSTransition':'msTransitionEnd',
'MozTransition':'transitionend',
'WebkitTransition':'webkitTransitionEnd'
}