Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View tobsn's full-sized avatar

Tobsn tobsn

  • US/EU/SEA
View GitHub Profile
@tobsn
tobsn / gist:963466
Created May 9, 2011 21:34
setting up a db template on rackspace cloud debian
1. system upgrade (lenny to squeeze)
================
apt-get update
apt-get upgrade
// keep old configs - hit [enter]
nano /etc/apt/source.list
// replace lenny with squeeze
apt-get update
apt-get upgrade
// keep old - keep hitting [enter]
@tobsn
tobsn / simple_request.js
Created May 20, 2011 01:10 — forked from chjj/simple_request.js
simple request
var parse = require('url').parse,
http = require('http'),
StringDecoder = require('string_decoder').StringDecoder;
var request = function(url, body, func) {
if (typeof url !== 'object') {
url = parse(url);
}
if (!func) {
var P={};(function(q,u,e,r,y){q=/\+/g;u=/([^&=]+)=?([^&]*)/g;e=function(s){return decodeURIComponent(s.replace(q,' '));};r=window.location.search.substring(1);while(y=u.exec(r)){P[e(y[1])]=e(y[2]);}})();
@tobsn
tobsn / pastebin.class.php
Created May 29, 2011 09:04
pastebin scraper
<?php
class pastebin {
private $folder = './pastebins';
public $pastes = array();
function __construct( $folder = false ) {
if( $folder ) {
$this->folder = $folder;
}
$this->folder = rtrim( $this->folder, '/' );
@tobsn
tobsn / pastebin.sort.class.php
Created May 29, 2011 09:05
pastebin scraper - sorting
<?php
class pastebin {
private $folder = './pastebins';
public $pastes = array();
public $count = 0;
function __construct( $folder = false ) {
if( $folder ) {
$this->folder = $folder;
}
@tobsn
tobsn / mon.class.php
Created June 14, 2011 21:29
mini mongodb class
class mon {
public $mongoobj = null;
public $db;
function __construct( $db ) {
$this->db = $db;
return;
}
function con() {
if( $this->mongoobj === null ) {
$this->mongoobj = new Mongo();
@tobsn
tobsn / fancytime.js
Created June 19, 2011 09:16
seconds to fancy time
function s2t(s){
var u=[{n:'now',l:5},{n:'second',l:60,is:1},{n:'minute',l:3600,is:60},{n:'hour',l:86400,is:3600},{n:'yesterday',l:172800,po:true},{n:'tomorrow',l:172800,fo:true},{n:'day',l:604800,is:86400},{n:'week',l:2629743,is:604800},{n:'month',l:31556926,is:2629743},{n:'year',l:Infinity,is:31556926}],
l={'future_format':'%s %t','past_format':'%t %s','second':'second','seconds':'seconds','minute':'minute','minutes':'minutes','hour':'hour','hours':'hours','day':'day','days':'days','week':'week','weeks':'weeks','month':'month','months':'months','year':'year','years':'years','yesterday':'yesterday','tomorrow':'tomorrow','now':'justnow','ago':'ago','in':'in'},
_=function(s,v){if(!isNaN(v)&&v!=1){s=s+'s';}log(l[s]);return l[s]||s;},
m=s.match(/(\d{4,})(?:-(\d{1,2})(?:-(\d{1,2})(?:[T ](\d{1,2}):(\d{1,2})(?::(\d{1,2})(?:\.(\d+))?)?(?:(Z)|([+-])(\d{1,2})(?::(\d{1,2}))?)?)?)?)?/),
a=Date.UTC(m[1],parseInt(m[2]),parseInt(m[3]),parseInt(m[4]),parseInt(m[5]),parseInt(m[6]),0),
d=new Date(),lt=d.getTime(),l
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// HTML
<form action="" method="post" id="enter_number">
<p>Enter your phone number:</p>
<p><input type="text" name="phone_number" id="phone_number" /></p>
<p><input type="submit" name="submit" value="Verify" /></p>
</form>
<div id="verify_code" style="display:none;">
@tobsn
tobsn / simple_request.js
Created May 4, 2012 20:47 — forked from chjj/simple_request.js
simple request
var http = require('http')
, parse = require('url').parse
, StringDecoder = require('string_decoder').StringDecoder;
var LIMIT = 10 * 1024;
var request = function(url, body, func) {
if (typeof url !== 'object') {
url = parse(url);
}
@tobsn
tobsn / taffydb.capping.js
Created May 5, 2012 10:19
capping taffydb
TAFFY.extend( 'capped', function( i, runInsert, runRemove ) {
var c = this.getDBI().cap || false;
if( c && ( c < ( this.count() + 1 ) ) ) {
while( c < ( this.count() + 1 ) ) {
this.getDBI().remove( this.context().results[0].___id );
this.context({
run: null
});
this.getDBI().removeCommit( runRemove );
}