Skip to content

Instantly share code, notes, and snippets.

View yxkelan's full-sized avatar

Yuan Xie yxkelan

  • San Francisco, CA
View GitHub Profile
@yxkelan
yxkelan / client.js
Created April 20, 2015 02:36
Using google's JavaScript client library with custom search api.
var gapi=window.gapi=window.gapi||{};gapi._bs=new Date().getTime();(function(){var f=encodeURIComponent,g=window,k=decodeURIComponent,n="shift",p="replace",q="split",u="push",y="test",B="length",C="join";var D=g,E=document,aa=D.location,ba=function(){},ca=/\[native code\]/,G=function(a,b,c){return a[b]=a[b]||c},da=function(a){for(var b=0;b<this[B];b++)if(this[b]===a)return b;return-1},ea=function(a){a=a.sort();for(var b=[],c=void 0,d=0;d<a[B];d++){var e=a[d];e!=c&&b[u](e);c=e}return b},H=function(){var a;if((a=Object.create)&&ca[y](a))a=a(null);else{a={};for(var b in a)a[b]=void 0}return a},I=G(D,"gapi",{});var J;J=G(D,"___jsl",H());G(J,"I",0);G(J,"hel",10);var K=function(){var a=aa.href,b;if(J.dpo)b=J.h;else{b=J.h;var c=RegExp("([#].*&|[#])jsh=([^&#]*)","g"),d=RegExp("([?#].*&|[?#])jsh=([^&#]*)","g");if(a=a&&(c.exec(a)||d.exec(a)))try{b=k(a[2])}catch(e){}}return b},fa=function(a){var b=G(J,"PQ",[]);J.PQ=[];var c=b[B];if(0===c)a();else for(var d=0,e=function(){++d===c&&a()},h=0;h<c;h++)b[h](e)},L=function(a){
@yxkelan
yxkelan / get-geo-info.py
Last active August 29, 2015 14:19
Using google's geocode api to get latitude and longitude for given locations.
# Read location name from locations.txt
# Query location one by onE
import csv
from geopy.geocoders import GoogleV3
def add_geo_info(geolocator, location, writer):
try:
geoinfo = geolocator.geocode(query=location, components={'locality': 'SF'})
if geoinfo:
@yxkelan
yxkelan / jsbin.howaza.js
Last active August 29, 2015 14:17
JS Bin// source http://jsbin.com/howaza GET IE version.
var testCases = [
["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36", -1],
["Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Firefox/31.0", -1],
["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/600.1.17 (KHTML, like Gecko) Version/8.0 Safari/600.1.17", -1],
["Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36", -1],
["Mozilla/5.0 (Windows NT 6.2; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0", -1],
["Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)", 7],
["Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)", 10],
["Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)", 9],
["Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)", 8],
@yxkelan
yxkelan / 0_reuse_code.js
Last active August 29, 2015 14:17
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@yxkelan
yxkelan / Howto.md
Created December 30, 2013 03:03 — forked from n1k0/Howto.md

Put test1.js and test2.js into a tests/ directory, then run the suite:

$ casperjs test tests/ --pre=pre.js --includes=inc.js --post=post.js
Test file: /Users/nperriault/tmp/pre-inc/pre.js                                 
Hey, I'm executed before the suite.
Test file: /Users/nperriault/tmp/pre-inc/tests/test1.js                         
# this is test 1
Hi, I've been included.
PASS Subject is strictly true
@yxkelan
yxkelan / gauge.js
Created November 1, 2013 01:04 — forked from tomerd/gauge.js
function Gauge(placeholderName, configuration)
{
this.placeholderName = placeholderName;
var self = this; // for internal d3 functions
this.configure = function(configuration)
{
this.config = configuration;
@yxkelan
yxkelan / gist:6142799
Created August 2, 2013 19:39
#D3 Scatterplot update data
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<meta charset="utf-8">
<title>D3: Using each() to specify two transitions in sequence</title>
<style type="text/css">
.axis path,
.axis line {
@yxkelan
yxkelan / gist:6119466
Created July 31, 2013 05:12
#D3 Bar chart, from 'Interactive data visualization for web'
var dataset = [5, 10, 13, 19, 21, 25, 22, 18, 15, 14, 11, 12, 20, 18, 17, 16, 18, 23, 25];
var w = 600, h = 250;
var xScale = d3.scale.ordinal().domain(d3.range(dataset.length))
.rangeRoundBands([0, w], 0.05);
var yScale = d3.scale.linear().domain([0, d3.max(dataset)])
.range([0, h]);
@yxkelan
yxkelan / gist:5996954
Created July 15, 2013 01:41
Install jekyll, error "No developer directory found at /Developer. Run /usr/bin/xcode-select to update the developer directory path."
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
$ sudo gem install jekyll
This happens because from about Xcode 4.2 Apple started distributing it as an app, downloadable from the App Store. Consequently, all tools are installed in the Applications/Xcode.app package
@yxkelan
yxkelan / gist:5996877
Last active December 19, 2015 18:09
#JavaScript The safari has a pop-up blocker silencer not show when a link is blocked.
var link = $('<a></a>');
link.attr('target','_blank'); //Open a new tab
function newopen(newlink){
if(newlink){
var win = window.open(newlink, '_blank');
if (win == null || typeof(win) == undefined){
link.attr('href',newlink);
link[0].click();
}