Skip to content

Instantly share code, notes, and snippets.

@sivagao
sivagao / jQueryAudit.js
Last active January 2, 2016 22:09
jQuery Audit Chrme Plugin , show how to create a sidebar panel & jQuery inner data.
/* jslint browser: true */
/* global chrome, $0 */
var getPanelContents = function () {
if (!$0) return;
// In case we're in an <iframe>
var document = $0.ownerDocument;
var window = document.defaultView;
@sivagao
sivagao / example.js
Last active December 27, 2015 18:39 — forked from domenic/example.js
// `promise` is some operation that may succeed (fulfill) or fail (reject)
var newPromise = promise.then(
function () {
return delay(1000);
},
writeError
);
// If `promise` fulfills, `newPromise` will fulfill in 1000 ms.
// If `promise` rejects and writing to the error log succeeds,
@sivagao
sivagao / httpretry.coffee
Last active December 27, 2015 18:39 — forked from kriskowal/gist:593052
httpretry.coffee
Q = require 'q'
HTTP = require 'q-http'
httpReadRetry = (url, timeout, times) ->
HTTP.read(url).then(
(content) ->
{content}
,(error) ->
if times is 0
throw new Error 'Cant read #{JSON.stringify(url)}'
function throttle( fn, time ) {
var t = 0;
return function() {
var args = arguments, ctx = this;
clearTimeout(t);
t = setTimeout( function() {
fn.apply( ctx, args );
}, time );
};
@sivagao
sivagao / fan.py
Created October 21, 2013 05:35 — forked from c4pt0r/fan.py
#!/usr/bin/env python
#encoding=utf-8
# Hacker Need Food!
import json
import os
import sys
from optparse import OptionParser
import urllib, urllib2, cookielib
@sivagao
sivagao / agents.py
Created September 2, 2013 03:13
change ip(proxy) and useragent for crawler or autoposter!
AGENTS = [
"Avant Browser/1.2.789rel1 (http://www.avantbrowser.com)",
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.0 Safari/532.5",
"Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.310.0 Safari/532.9",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.514.0 Safari/534.7",
"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/534.14 (KHTML, like Gecko) Chrome/9.0.601.0 Safari/534.14",
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.14 (KHTML, like Gecko) Chrome/10.0.601.0 Safari/534.14",
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.20 (KHTML, like Gecko) Chrome/11.0.672.2 Safari/534.20",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.27 (KHTML, like Gecko) Chrome/12.0.712.0 Safari/534.27",
"Mozilla/5.0 (
function getJSON(aUrl,sheetname) {
//var sheetname = "test";
//var aUrl = "http://pipes.yahoo.com/pipes/pipe.run?_id=286bbb1d8d30f65b54173b3b752fa4d9&_render=json";
var response = UrlFetchApp.fetch(aUrl); // get feed
var dataAll = Utilities.jsonParse(response.getContentText()); //
var data = dataAll.value.items;
for (i in data){
data[i].pubDate = new Date(data[i].pubDate);
data[i].start = data[i].pubDate;
}
@sivagao
sivagao / harlem-shake.css
Created August 2, 2013 16:21
http://weibo.com/1784501333/A2UEADnfw 有时候不得不佩服360在产品上的微创新,360导航确确实实是把传统导航站颠覆了。不信可以点击红框处看看 http://t.cn/hxMyP
.dance-normal {
animation: wobble 1s ease-in-out infinite;
-moz-animation: wobble 1s ease-in-out infinite;
-webkit-animation: wobble 1s ease-in-out infinite;
-o-animation: wobble 1s ease-in-out infinite;
-ms-animation: wobble 1s ease-in-out infinite
}
.dance-slow {
@sivagao
sivagao / changelog.md
Created July 19, 2013 06:34
jQuery changes log since version 1.4

http://blog.jquery.com/2011/01/31/jquery-15-released/ ajax rewrite: a call to jQuery.ajax (or jQuery.get, jQuery.post, etc.) now returns a jqXHR object that provides consistency to the XMLHttpRequest object across platforms much more extensible – allowing you to attach all sort of data handlers, filters, and transports.

deferred objects: to work with return values that may not be immediately present (such as the return result from an asynchronous Ajax request).

@sivagao
sivagao / mediator.js
Last active December 19, 2015 23:49
javascript & jQuery patterns text from book jQuery patterns<essential javascript design patterns for beginners> <javascript patterns><javascript design patterns><Learning.JavaScript.Design.Patterns>
/*
applications are made up of separate objects, which need a way to communicate among themselves.
when objects know too much about each other, and communicate directly.. means, too tight coupling.
in this pattern
independent objects(colleagues) dont communicate directly. but through a mediator object
*/
function Player(name){