Skip to content

Instantly share code, notes, and snippets.

View nonkr's full-sized avatar
🎯
Focusing

Nonkr nonkr

🎯
Focusing
  • Hangzhou, China
View GitHub Profile
@nonkr
nonkr / deepExtend.js
Last active December 21, 2015 12:08
Javascript Object deepExtend
Object.deepExtend = function(destination, source) {
for (var property in source) {
if (source[property] && source[property].constructor && source[property].constructor === Object) {
destination[property] = destination[property] || {};
arguments.callee(destination[property], source[property]);
} else {
destination[property] = source[property];
}
}
return destination;
@nonkr
nonkr / document.ready.js
Created August 23, 2013 02:44
自己写 document.ready
(function () {
var ie = !!(window.attachEvent && !window.opera);
var wk = /webkit\/(\d+)/i.test(navigator.userAgent) && (RegExp.$1 < 525);
var fn = [];
var run = function () { for (var i = 0; i < fn.length; i++) fn[i](); };
var d = document;
d.ready = function (f) {
if (!ie && !wk && d.addEventListener)
return d.addEventListener('DOMContentLoaded', f, false);
if (fn.push(f) > 1) return;
@nonkr
nonkr / local.language.js
Created August 27, 2013 02:54
判断浏览器使用的语言
var language = navigator.userLanguage?navigator.userLanguage:(navigator.browserLanguage?navigator.browserLanguage:(navigator.systemLanguage?navigator.systemLanguage:(navigator.language?navigator.language:"")));
language = language.toLowerCase();
if (language.length!=5) {
language = "zh-cn";
} else {
if (language === "zh-hk" || language === "zh-mo") {
language = "zh-tw";
} else if (language !== "zh-cn") {
language = "en-us";
} else {
@nonkr
nonkr / get_real_ip.php
Created September 28, 2013 13:48
获得用户的真实IP地址
/**
* 获得用户的真实IP地址
*
* @access public
* @return string
*/
function real_ip()
{
static $realip = NULL;
@nonkr
nonkr / adv.pl
Last active December 27, 2015 20:59
Perl进阶笔记
#在package中定义私有函数
#方法一
sub p_func
{
caller eq __PACKAGE__ or die;
print "test\n";
}
#方法二
my $p_func = sub {
print "test\n";
@nonkr
nonkr / mysql2sqlite.sh
Last active December 30, 2015 06:49 — forked from esperlu/mysql2sqlite.sh
从mysql导出数据到sqlite 使用方法:./mysql2sqlite.sh -h host -u Username -pPasswd dbname | sqlite3 sqlite.db
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@nonkr
nonkr / md5.pl
Last active January 3, 2016 06:19
MD5 in 8 lines of perl5
#!/usr/bin/perl -iH9T4C`>_-JXF8NMS^$#)4=@<,$18%"0X4!`L0%P8*#Q4``04``04#!P``
@A=unpack N4C24,unpack u,$^I;@K=map{int abs 2**32*sin$_}1..64;sub L{($x=pop)
<<($n=pop)|2**$n-1&$x>>32-$n}sub M{($x=pop)-($m=1+~0)*int$x/$m}do{$l+=$r=read
STDIN,$_,64;$r++,$_.="\x80"if$r<64&&!$p++;@W=unpack V16,$_."\0"x7;$W[14]=$l*8
if$r<57;($a,$b,$c,$d)=@A;for(0..63){$a=M$b+L$A[4+4*($_>>4)+$_%4],M&{(sub{$b&$c
|$d&~$b},sub{$b&$d|$c&~$d},sub{$b^$c^$d},sub{$c^($b|~$d)})[$z=$_/16]}+$W[($A[
20+$z]+$A[24+$z]*($_%16))%16]+$K[$_]+$a;($a,$b,$c,$d)=($d,$a,$b,$c)}$v=a;for(
@A[0..3]){$_=M$_+${$v++}}}while$r>56;print unpack(H32,pack V4,@A),"\n"
@nonkr
nonkr / sha.pl
Created January 14, 2014 17:12
SHA in 8 lines of perl5
#!/usr/bin/perl -iD9T4C`>_-JXF8NMS^$#)4=L/2X?!:@GF9;MGKH8\;O-S*8L'6
@A=unpack"N*",unpack u,$^I;@K=splice@A,5,4;sub M{($x=pop)-($m=1+~0)*int$x/$m};
sub L{$n=pop;($x=pop)<<$n|2**$n-1&$x>>32-$n}@F=(sub{$b&($c^$d)^$d},$S=sub{$b^$c
^$d},sub{($b|$c)&$d|$b&$c},$S);do{$l+=$r=read STDIN,$_,64;$r++,$_.="\x80"if$r<
64&&!$p++;@W=unpack N16,$_."\0"x7;$W[15]=$l*8 if$r<57;for(16..79){push@W,L$W[$_
-3]^$W[$_-8]^$W[$_-14]^$W[$_-16],1}($a,$b,$c,$d,$e)=@A;for(0..79){$t=M&{$F[$_/
20]}+$e+$W[$_]+$K[$_/20]+L$a,5;$e=$d;$d=$c;$c=L$b,30;$b=$a;$a=$t}$v='a';@A=map{
M$_+${$v++}}@A}while$r>56;printf'%.8x'x5 ."\n",@A
<key>GDI Commands</key>
<dict>
<key>GDI Duplicate Selected Line</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
<key>GDI Delete Selected Line</key>
<string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToEndOfLine:</string>
<key>GDI Move Selected Line Up</key>
<string>selectLine:, cut:, moveUp:, moveToBeginningOfLine:, insertNewLine:, paste:, moveBackward:</string>
<key>GDI Move Selected Line Down</key>
<string>selectLine:, cut:, moveDown:, moveToBeginningOfLine:, insertNewLine:, paste:, moveBackward:</string>
<?php
/**
* UUID class
*
* The following class generates VALID RFC 4122 COMPLIANT
* Universally Unique IDentifiers (UUID) version 3, 4 and 5.
*
* UUIDs generated validates using OSSP UUID Tool, and output
* for named-based UUIDs are exactly the same. This is a pure
* PHP implementation.