Skip to content

Instantly share code, notes, and snippets.

View zhuangya's full-sized avatar
🧛‍♂️
only silver bullet is silver bullet.

Ya Zhuang zhuangya

🧛‍♂️
only silver bullet is silver bullet.
View GitHub Profile
@zhuangya
zhuangya / gist:1619581
Created January 16, 2012 07:26
weibo.com 301 loop.
Last login: Mon Jan 16 15:15:42 on ttys000
curl% [ 3:23下午 ] [ nos@NosMacbookPro:~() ]
$ curl -i weibo.com
HTTP/1.1 301 Moved Permanently
Date: Mon, 16 Jan 2012 07:24:00 GMT
Server: Apache
Location: http://www.weibo.com/
Cache-Control: max-age=60
Expires: Mon, 16 Jan 2012 07:25:00 GMT
Vary: Accept-Encoding
function checkDate(date) {
"use strict";
if (/\d{4}-\d{2}-\d{2}/.test(date)) {
var _date = new Date(date).toString();
if (_date === "NaN" || _date === "Invalid Date") {
return "Invalid Date";
} else {
return true;
}
function id_card_verify(id_card) {
var mask = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
var verify_code = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
var product = 0;
if (/\d{17}[\dx]/i.test(id_card)) {
for(i = 0; i < 17; i++) {
product += (parseInt(id_card[i], 10) * parseInt(mask[i]));
}
(function() {
var verify;
verify = function(idcard) {
var factor, i, mask, x;
factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
mask = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
return idcard[idcard.length - 1] === mask[(((function() {
var _len, _ref, _results;
_ref = idcard.slice(0, (idcard.length - 1));
@zhuangya
zhuangya / id.coffee
Created March 26, 2012 05:35
ID card verify
verify = (idcard) ->
factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
mask = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]
idcard[idcard.length - 1] is mask[((x * factor[i] for x, i in idcard[0...idcard.length - 1]).reduce (x, y) -> x + y) % mask.length].toString()
<!DOCTYPE html>
<!-- nothing around here, just a simple demo for odvt. so, ignore me :) -->
<html>
<head>
<meta charset="utf-8">
<title>mouse move demo</title>
<style>
body {
background-color: #F5F5F5;
color: #333;
[ 12:42AM ] [ nos@NosMacbookPro:~() ]
$ curl ifconfig.me/ip
117.79.233.219
[ 12:42AM ] [ nos@NosMacbookPro:~() ]
$ curl -vvv http://tp1.sinaimg.cn/1460234684/50/1294316630/1
* About to connect() to tp1.sinaimg.cn port 80 (#0)
* Trying 203.69.138.10... connected
* Connected to tp1.sinaimg.cn (203.69.138.10) port 80 (#0)
> GET /1460234684/50/1294316630/1 HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
<?php
$string = "hello, 你好我是, 测试, 测试, Mike, 测试, John ";
echo preg_replace('/([^ ,\x{4e00}-\x{9fa5}]+)/u', '<span class="byline-cn">$1</span>', $string);
<?php
$string = "Michael Jackson, 你好我是, 测试, 测试, Mike, 测试, John ";
//echo preg_replace('/([^ ,\x{4e00}-\x{9fa5}]+)/u', '<span class="byline-en">$1</span>', $string);
//
$pattern_head = '/^(?=[^\x{4e00}-\x{9fa5}]+)|, (?=[^\x{4e00}-\x{9fa5}]+)/u';
$replacement_head = '<span class="byline-en">';
@zhuangya
zhuangya / tmuxrc
Created May 6, 2012 06:08 — forked from eculver/tmuxrc
tmuxrc
# basic settings
set-window-option -g mode-keys vi # vi key
set-option -g status-keys vi
set-window-option -g utf8 on # utf8 support
set-window-option -g mode-mouse off # disable mouse
# copy mode to escape key
unbind [
bind Escape copy-mode