Skip to content

Instantly share code, notes, and snippets.

View blankyao's full-sized avatar
🎉
Happy Writing

Blank Yao blankyao

🎉
Happy Writing
View GitHub Profile

Keybase proof

I hereby claim:

  • I am blankyao on github.
  • I am blankyao (https://keybase.io/blankyao) on keybase.
  • I have a public key ASAdIcPHym9drp9AG9Y2BpTTx3Lbc41UrdHJ7yT3JbWwNAo

To claim this, I am signing this object:

@blankyao
blankyao / gist:10537580
Created April 12, 2014 14:11
get global variables in window
(function(global){
var i = document.createElement('iframe');
document.body.appendChild(i);
for(var k in global) {
if(!(k in i.contentWindow)) {
console.log(k);
}
}
document.body.removeChild(i);
})(window);
@blankyao
blankyao / firewall.sh
Created December 10, 2013 01:04 — forked from x1a0/firewall.sh
#! /bin/bash
# Set the default policies to allow everything while we set up new rules.
# Prevents cutting yourself off when running from remote SSH.
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
# Flush any existing rules, leaving just the defaults
iptables -F
//
// PSPDFThreadSafeMutableDictionary.m
//
// Copyright (c) 2013 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
//
// 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
@blankyao
blankyao / gethostbyname
Last active December 10, 2015 20:58
get ip address by hostname from iOS
struct hostent *host = gethostbyname(@"localhost".UTF8String);
char addr[32];
inet_ntop(host->h_addrtype, host->h_addr, addr, sizeof(addr));
NSString *result=[[NSString alloc] initWithUTF8String:addr];
# -*- coding:utf-8 -*-
'写了一个简单的支持中文的正向最大匹配的机械分词,其它不用解释了,就几十行代码'
'搜狗词库下载地址:http://vdisk.weibo.com/s/7RlE5'
import string
__dict = {}
def load_dict(dict_file='words.dic'):
'加载词库,把词库加载成一个key为首字符,value为相关词的列表的字典'
@blankyao
blankyao / uitableviewDelegateWithReturn.m
Created February 23, 2012 04:21
在UITextView里面响应return键
#pragma -
#pragma UITextViewDelegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if (range.length != 1 && [text isEqualToString:@"\n"]) {//按下return键
//TODO 做你想做的
return NO;
} else {
return YES;
}
@blankyao
blankyao / bindWithDelay.js
Created August 9, 2011 02:31
It prevents a function call from happening EVERY time an event is fired from the browser.
/*
bindWithDelay jQuery plugin
Author: Brian Grinstead
MIT license: http://www.opensource.org/licenses/mit-license.php
http://github.com/bgrins/bindWithDelay
http://briangrinstead.com/files/bindWithDelay
Usage:
@blankyao
blankyao / Partial.js
Created August 9, 2011 02:22
Currying is an expressive and compact alternative to manually wrapping anonymous functions. I use it a lot. But sometimes its not enough – the problem is you can only pre-assign the first n arguments. What if we wanted to make a function and pre-assign th
//from http://javascriptweblog.wordpress.com/2010/05/17/partial-currys-flashy-cousin/
window.___ = {}; //argument placeholder
Function.prototype.partial = function() {
if (arguments.length<1) {
return this; //nothing to pre-assign - return the function as is
}
var __method = this;
var args = arguments;
@blankyao
blankyao / nextpow2.c
Created July 22, 2011 07:30
返回不小于num的最小2的幂指数
static unsigned int nextpow2(unsigned int num) {
--num;
num |= num >> 1;
num |= num >> 2;
num |= num >> 4;
num |= num >> 8;
num |= num >> 16;
return ++num;
}