Skip to content

Instantly share code, notes, and snippets.

View christianchristensen's full-sized avatar

Chris Christensen christianchristensen

View GitHub Profile
@msonnabaum
msonnabaum / strip_inline_styles.php
Created December 14, 2010 21:46
Strips out inline styles like '<span style="font-family:arial;font-size:13px">'. Arguments work similarly to strip_tags().
<?php
function strip_inline_styles($string, $allowed_styles = array()) {
$pattern = '/style="([^"\']+)"/';
$parsed = preg_replace_callback($pattern, function($match = NULL) use($allowed_styles) {
// Get style attribute values
$styles = $match[1];
// Parse each sytle out
$pattern2 = "/(?:([\w-]+?):([\w-]+);?)/";
$parsed_styles = preg_replace_callback($pattern2, function($match2 = NULL) use($allowed_styles, $styles) {
@creationix
creationix / inspect.js
Created December 23, 2010 06:51
a custom object inspector to help me understand JavaScript
function escapeString(string) {
string = string.replace(/\\/g, "\\\\").
replace(/\n/g, "\\n").
replace(/\r/g, "\\r").
replace(/\t/g, "\\t");
if (string.indexOf("'") < 0) {
return "'" + string + "'";
}
string = string.replace(/"/g, "\\\"");
return '"' + string + '"';
@creationix
creationix / find.js
Created December 24, 2010 23:49
Find all references to an object.
function find(root, obj) {
var seen = [];
function search(root, name, depth) {
if (root === obj) {
console.log(name);
return;
}
if (!depth) { return; }
if (seen.indexOf(root) >= 0) { return; }
if (typeof root !== "object") { return; }
@waxpancake
waxpancake / ThinkUp on EC2 Ubuntu User-Data Script
Created January 4, 2011 04:29
Install script for non-interactively installing ThinkUp and prerequisites
#!/bin/bash -ex
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
# install ThinkUp on EC2 Ubuntu instance:
#
# @spara 12/23/10
# @waxpancake 1/3/11
# install required packages
sudo apt-get update
Vagrant::Config.run do |global_config|
aptdir = (ENV['APTCACHE'] or "#{ENV['HOME']}/aptcache/")
checkout = (ENV['COOKBOOKS'] or "#{ENV['HOME']}/openstack-cookbooks")
ip_prefix = (ENV['IP_PREFIX'] or "192.168.76.")
mac_prefix = (ENV['MAC_PREFIX'] or "080027076")
fixed = (ENV['FIXED'] or "10.0.76.0/24")
global_config.vm.define :chef do |config|
suffix = "100"
ip = "#{ip_prefix}#{suffix}"
config.vm.box = "base"
@progrium
progrium / urlfetch_intercept.py
Created February 9, 2011 06:15
wsgi_intercept for app engine's urlfetch
""" Monkey patch to hit wsgi apps when using urlfetch
This will monkey patch App Engine's urlfetch.fetch with a fetch that hits a local
wsgi app registered with add_intercept. This module is inspired by and borrows
code from the wsgi-intercept project, which doesn't work with App Engine.
This is intended only for the local SDK environment for unit tests.
Usage:
#!/bin/bash
apt-get update
apt-get install -y ruby ruby-dev rubygems libopenssl-ruby
echo "gem: --bindir /usr/local/bin" >> ~/.gemrc
gem install chef
@creationix
creationix / coorspin.html
Created March 6, 2011 22:54
A re-implementation of ColorSpin from iOS to webOS.
<!doctype html>
<html>
<head>
<title>ColorSpin</title>
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,user-scalable=no"/>
<style>
html { height: 100%; }
body {
height: 100%;
margin: 0;
@collegeman
collegeman / setup-statsd.sh
Created March 9, 2011 16:12
Turn an Ubuntu 10.04 linode into a StatsD/Graphite server
# install git
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
# download the Node source, compile and install it
git clone https://github.com/joyent/node.git
cd node
./configure
make
sudo make install
# install the Node package manager for later use
#!/usr/bin/env ruby
#
# Originally written by http://redartisan.com/tags/csv
# Added and minor changes by Gavin Laking
# Rewritten by Andrew Bennett for Ruby 1.9
#
# Usage: ruby csv_to_fixture.rb file.csv [--json]
#
# "id","name","mime_type","extensions","icon_url"
# "1","unknown","unknown/unknown","||","/images/icon/file_unknown.gif"