Skip to content

Instantly share code, notes, and snippets.

View aztack's full-sized avatar
🎯
Focusing

Wang Weihua aztack

🎯
Focusing
View GitHub Profile
@aztack
aztack / OptionMenu.java
Created January 26, 2012 02:02
android: create option menu
public class OptionMenu extends Activity
{
private static final String TAG = "HelloAndroid";
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
}
@aztack
aztack / nginx.conf
Created April 22, 2013 05:35 — forked from hydra35/nginx.conf
grayscale
# 1. Make sure you have nginx sub module compiled in
# nginx -V 2>&1 | grep --color=always '\-\-with\-http_sub_module'
# 2. add two directives below at HTTP level
# nginx.conf
http {
# ......
sub_filter '</head>' '<style type="text/css">html{ filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); -webkit-filter: grayscale(100%); filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */
@aztack
aztack / Taming-Timer-Interval.js
Created April 22, 2013 08:50
Taming-Timer-Interval
(function(){
//helpers
function _(){
console.log.apply(console,arguments);
}
function timing(msg,callback){
var t1 = new Date();
_(msg);
return callback();
}
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
<?php
/**
* Identity function, returns its argument unmodified.
*
* This is useful almost exclusively as a workaround to an oddity in the PHP
* grammar -- this is a syntax error:
*
* COUNTEREXAMPLE
* new Thing()->doStuff();
@aztack
aztack / $format.js
Created June 19, 2013 02:17
$format(template,data)
function $format(template, data) {
return template.replace(/\{(\w+)\}/g, function (_, key) {
var value = data[key];
return typeof value == 'undefined' ? _ : value;
});
}
@aztack
aztack / EvengDelegate.java
Created July 2, 2013 07:18
EvengDelegate.java
package com.kaixin001.jiecao.common;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Delegator implements java.lang.reflect.InvocationHandler {
private Object obj;
private Method method;
@aztack
aztack / englishfy.js
Created August 1, 2013 03:13
englishfy.js
/**
* 将一个函数调分拆成多个函数调用,使形式上像是英文描述
* var $hi = englishfy('callMe.later',function(who,when){console.log(who+' will call me ' + when)});
* $hi('tom').callMe('1 hour').later();
* @param names
* @param done
* @param ctx
* @return {Function}
*/
function $englishfy(names,done,ctx){
#
# MIT License - (c) 2011 John Mettraux
#
require 'rubygems'
require 'parslet' # gem install parslet
module MyJson
@aztack
aztack / access-window.rb
Created December 5, 2013 08:06
find access of global object 'window' in javascript code with RKelly
#gem install rkelly-remix
require 'rkelly'
parser = RKelly::Parser.new
matches = parser.parse(open("sample.js")).pointcut(RKelly::Nodes::DotAccessorNode).matches
matches.each do |match|
resolve_node = matches.value
if resolve_node.value == 'window'
pos = resolve_node.range.from
$stderr.puts "found access of window at: line #{pos.line}, char #{pos.char}"
end