Skip to content

Instantly share code, notes, and snippets.

View pthrasher's full-sized avatar

Philip Thrasher pthrasher

View GitHub Profile
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
// ...
_window_focus: __bind(function(e)
{
Ti.API.info('window_focus - enter');
if (this.performedInitialFocus == false)
{
this.performedInitialFocus = true;
this._nearbyButton_click();
@pthrasher
pthrasher / fix_that_shit.js
Created January 25, 2012 16:41
how to fix js inheritance and class scope issues
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
function MyClass() {
this.my_method = __bind(this.my_method, this);
this.my_other_method = __bind(this.my_other_method, this);
}
MyClass.prototype.my_method = function(arg1) {
return arg1;
}
@pthrasher
pthrasher / a.js
Created January 31, 2012 02:55 — forked from tebriel/a.js
function formatJSONTime(jsonTime){
var matches = jsonTime.match(/date\((\d{13})\)/),
date = matches !== null ? formatTime(new Date(+matches[0])) : +new Date();
return date;
}
@pthrasher
pthrasher / formattime.js
Created January 31, 2012 03:20 — forked from tebriel/formattime.js
format time
function formatTime(e)
{
var _hour = e.getHours(),
_min = e.getMinutes(),
_ampm = +_hour >= 12 ? " PM" : " AM",
_nice_hour = ((+_hour % 12)+"").replace(/^0$/, "12");
return _nice_hour + ":" + _min + _ampm;
}
function IsNumeric(e)
return Object.prototype.toString.call(e) == '[object Number]';
}
@pthrasher
pthrasher / currency.js
Created January 31, 2012 03:35 — forked from tebriel/currency.js
currency!
function formatCurrency(amount)
{
var i = parseFloat(amount);
if (isNaN(i)) { i = 0.00; }
var minus = '';
if (i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + 0.005) * 100, 10);
i = i / 100;
s = '';
@pthrasher
pthrasher / simplate.php
Created February 2, 2012 17:23
A very very simple templating class for php... seriously... probably has too few features.
<?php
class Simplate {
/*
* Sets include file name, and sanitizes vars.
*/
function __contruct($template_name = '404', $vars = array()) {
// Escapt all values by default.
$this->template_vars = $this->sanitize_vars($vars);
@pthrasher
pthrasher / top1000.coffee
Created February 3, 2012 16:34
Fetches list of top 1000 companies using node, the jsdom module, and coffee-script.
jsdom = require 'jsdom'
dataz = []
listings = 1000
http_host = "http://www.stormscape.com"
path = "/inspiration/website-lists/global1000/"
# Build up the list of url's to visit.
urls = for page in [0..9]
class Testing123
contructor: ->
console.log "you're in the constructor."
my_unbound_method: ->
console.log "I don't have to be bound, because I don't do anything that needs `this`"
my_bound_method: =>
my_unbound_method()
@pthrasher
pthrasher / sprintf.coffee
Created February 5, 2012 04:47
just a short, fast string templater.
sprintf_re = /%\({1}([a-zA-Z0-9_]+)\){1}/
sprintf = (str, obj) ->
((if obj.hasOwnProperty(a) then obj[a] else a) for a in str.split sprintf_re).join("")
console.log(sprintf("%(quantity) @ %(weight)", {quantity: 13, weight: 42}))