Skip to content

Instantly share code, notes, and snippets.

View soldair's full-sized avatar

Ryan Day soldair

  • Google
  • San Jose CA
View GitHub Profile
@soldair
soldair / gist:4988801
Created February 19, 2013 19:01
email rfc compliant regex php
/*
* Method: email_rfc
* Validate email, RFC compliant version
*
* Originally by Cal Henderson, modified to fit Kohana syntax standards:
* - http://www.iamcal.com/publish/articles/php/parsing_email/
* - http://www.w3.org/Protocols/rfc822/
*
* Parameters:
* email - email address
@soldair
soldair / gist:4950965
Created February 14, 2013 06:27
my ssh public key
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6L/Y30hj/CJ/WehbUuSrTb9qTFkX/uHya8copfyg4T0+VexzGhZV7dp5VZISVnk8B0N4ZOlBp5y15pRKR9OIK1q2JjMq5uyGRIkiF62kkvo8PQ/OpMBk/glV0WJ73AZdgYV9HRS8Zr/cnPsw2Lp4hjrMwvj9Tv+Q5l+dl3HQ7O3xfIAdxSe2y62Sn/tg3vp+d6tEtEz8HFc0+YoCbRnhAuXA9R8sEW3nuyLXnITGSZ6SEHcPBkqtEqdshXHRbg8cTu5TenA9jfbyIsF2+hc/kYnek8YUzscUXGYjjg5ItRsoVtBTKf51KPx23ZJGX7VGTmVPsFfC8byj/De2S2GjUw== soldair@host
@soldair
soldair / pauseresume_walkdir.js
Created September 8, 2012 21:37
pause node walkdir, read a file into a write stream, then resume
// walkdir ~0.0.5
var fs = require('fs')
, walkdir = require('../walkdir')
// write all logs to the logs.cat file
, ws = fs.createWriteStream('logs.cat')
;
var em = walkdir('./');
em.on('file',function(path,stat){
@soldair
soldair / nodejs_passwd_reverse.sh
Created August 22, 2012 22:12
nodejs oneliner to reverse text on all lines of /etc/passwd from stdin to stdout
cat /etc/passwd | node -e "var buf ='',rev=function(lines){lines.forEach(function(l,k){process.stdout.write(l.split('').reverse().join('')+'\n')})};process.stdin.on('data',function(b){buf+=b.toString();b = buf.split('\n');buf = b.shift();rev(b)}); process.stdin.resume();"
@soldair
soldair / _require.php
Created June 30, 2012 14:47
nodejs style require for php
/*
* nodejs style require for php
* */
function _require($file){
static $requireCache = array();
if(isset($requireCache[$file])) return $requireCache[$file];
//todo support namespaces? evil eval? copy the file... all sad solutions
$module = array();
$module['exports'] = array();
@soldair
soldair / gist:2495387
Created April 26, 2012 03:02
us format strtotime benchmark with mktime
<?php
function _strtotime_us2($str,$now=null) {
if ($now === null) {
$now = time();
}
$strp = explode('-',$str);
@soldair
soldair / install_node.sh
Created October 27, 2011 23:29
install nodejs shell script
if [ "node-v0.5.10" !-d ]; then
curl http://nodejs.org/dist/v0.5.10/node-v0.5.10.tar.gz
tar -xvf node-v0.5.10.tar.gz
fi
cd node-v0.5.10
./configure
if [ $? != 0 ]; then
echo "configure failed =("
exit 1;
@soldair
soldair / gist:1321164
Created October 27, 2011 23:07
js is object
//is not array object
var isObject = function(o){
return new Object(o) === o && !(o instanceof Array)
}
@soldair
soldair / arraycopyutil.js
Created October 25, 2011 01:45
copy, appendTo and appendToCopy for js arrays
var cpy = function(a){return Array.prototype.slice.call(a)}
,appendTo = function(b,a){var c = cpy(b);c.unshift(a.length,0);a.splice.apply(a,c);return a}
,appendToCopy = function(b,a){return appendTo(b,cpy(a))}
module.exports = {copy:cpy,appendTo:appendTo,appendToCopy:appendToCopy};
@soldair
soldair / bench.php
Created June 28, 2011 21:26
fastest way to get a hash based on the githash in php
<?php
/*
~>php bench.php
md5_file 634.3932 ms
hash_file/md5 714.4802 ms
parse contents 911.6130 ms
parse contents substr 852.8361 ms
contents first chunk 590.0660 ms
all ran with 30000 itterations