Skip to content

Instantly share code, notes, and snippets.

@pthrasher
pthrasher / simplate.php
Created February 14, 2012 04:00
wtf.php
<?php
class Simplate {
private template_vars = array();
private template_include = '404';
/*
* Sets include file name, and sanitizes vars.
*/
function __contruct($template_name = '404', $vars = array()) {
@pthrasher
pthrasher / pointers_unmasked.c
Created February 24, 2012 19:11
Shows why pointers are unreadable to the uninitiated, and shows how to read them.
/*
* For those who don't understand pointers fully:
* Variables have addresses in memory. In C, you
* define an integer like so:
*/
int my_int;
my_int = 13;
// -or in one line-
int my_int = 13;
library =
'name':'My Library'
'@open': '2007-17-7'
'address':
'city': 'Springfield'
'zip': '12345'
'state': 'MI'
'street': 'Mockingbird Lane'
'books':[
{
###
jPath - xpath-esque query tool for json.
Also comes with backbone.js mixins
###
query = (query, data) ->
"""
Takes xpath-esque input, and converts it to a path list for the
@pthrasher
pthrasher / deck.md
Created May 29, 2012 18:24
GistDeck for Charlotte Python Meetup

Who am I?

Philip Thrasher

Web hacker at a private cyber security company.

What I Do

@pthrasher
pthrasher / oir.coffee
Created June 14, 2012 14:48
onImagesReady
# Will only run for a max of 20 seconds
# 2000 iterations.
onImagesLoaded: (callback, runs=0) ->
return unless runs <= 2000
#convenience method
wait = (ms, fn) -> setTimeout fn, ms
images = document.getElementsByTagName 'img'
unless images?
@pthrasher
pthrasher / up.shim.js
Created June 19, 2012 15:14
Javascript Shim to allow use of LearnBoost/up with CoffeeScript.
/*
* Allows using `up` on your coffeescript apps. To use, place this file in the
* same directory as your app.coffee (or whatever file is exporting your http
* server instance) and then run:
* $ up [options] shim.js
*/
require('coffee-script');
exports = module.exports = require('./app');
@pthrasher
pthrasher / stringUtil.coffee
Created June 26, 2012 16:48
Must faster than regex, and simple enough.
startsWith = (needle, haystack) ->
haystack.indexOf(needle) is 0
istartsWith = (needle, haystack) ->
needle = needle.toLowerCase()
haystack = haystack.toLowerCase()
startsWith needle, haystack
endsWith = (needle, haystack) ->
haystack.indexOf(needle) is haystack.length - needle.length
<div>
    <div id="myScrollableArea">

    </div>
</div>
#myScrollableArea {
@pthrasher
pthrasher / nextTick.js
Created July 13, 2012 15:26
window.nextTick for the browser. ;-)
/*
* setTimeout(fn, 0) for realz, for modern browsers.
* AKA nextTick from node.
* Ripped from http://dbaron.org/log/20100309-faster-timeouts
* Most browsers don't actually let you specify timeouts of 0, so the below
* method is a better way of achieving this.
* Philip Thrasher, 2012
*/
(function(){