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 / _tryget.js
Last active August 19, 2019 08:43
tryget javascript
function _tryget(o,path,v){
if(typeof(o)==="undefined")return v;
var props = path.split(".");
if(props.length===0)return v[path];
for(var t = o,i = 0;i<props.length;++i){
t = t[props[i]]
if(typeof(t)==="undefined")return v;
}
return t;
}
@aztack
aztack / validate_ipv6.rb
Created June 7, 2012 08:29 — forked from cpetschnig/validate_ipv6.rb
Regular Expression Validation for IPv6 Addresses in Ruby
# Regular Expression Validation for IPv6 addresses in Ruby
#
# Inspired by (if not to say copied from): http://forums.dartware.com/viewtopic.php?t=452
# Thanks, Dartware!
IPV6_REGEX = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f
@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){