Skip to content

Instantly share code, notes, and snippets.

View christianchristensen's full-sized avatar

Chris Christensen christianchristensen

View GitHub Profile
@creationix
creationix / simpleobj.js
Created August 12, 2010 00:15
An experience in making an object library.
Object.defineProperty(Object.prototype, "extend", {value: function (obj) {
obj.__proto__ = this;
return obj;
}});
Object.defineProperty(Object.prototype, "new", {value: function () {
var obj = Object.create(this);
if (obj.initialize) obj.initialize.apply(obj, arguments);
return obj;
}});
$('select.jump_list').change(function() {
if (!this.value) {
return;
}
var url, url_len, last_char;
if (this.value.match('://')) {
window.top.location = this.value;
}
<?php
class MinSplPriorityQueue extends SplPriorityQueue
{
public function compare($priority1, $priority2)
{
if ($priority1 === $priority2) return 0;
return $priority1 > $priority2 ? -1 : 1;
}
}
@creationix
creationix / scraper.js
Created August 23, 2010 05:12
Simple scraper tool
var http = require('http'),
Url = require('url'),
htmlparser = require('node-htmlparser'),
dom = require('jsdom/level1/core').dom.level1.core,
index = require('jsdom/browser/index'),
sizzleInit = require('sizzle').sizzleInit;
// Simple wrapper around node's http client, htmlparser, jsdom, and sizzle
function fetch(url, callback) {
var uri = Url.parse(url);
anonymous
anonymous / gist:578029
Created September 13, 2010 20:52
<?php
function apci_groups_user_is_groupmate($op, $user = NULL) {
switch ($op) {
case 'cache' :
// insert code here to return the cache_id name
if (arg(0) == 'user' && is_numeric(arg(1))) {
$uid = arg(1);
}
elseif (arg(0) == 'node' && is_numeric(arg(1))) {
@glacjay
glacjay / tun-ping-linux.py
Created September 18, 2010 04:49
Reading/writing Linux's TUN/TAP device using Python.
import fcntl
import os
import struct
import subprocess
# Some constants used to ioctl the device file. I got them by a simple C
# program.
TUNSETIFF = 0x400454ca
TUNSETOWNER = TUNSETIFF + 2
#!/custom/ree/bin/ruby
# USAGE:
#
# echo "|/path/to/core_helper.rb %p %s %u %g" > /proc/sys/kernel/core_pattern
#
require 'etc'
require 'net/smtp'
@rcrowley
rcrowley / config.ru
Created September 29, 2010 15:16
Puppet master Rack middleware
$0 = "master"
ARGV << "--rack"
ARGV << "--certname=#{File.read("/etc/puppet/certname").chomp}"
require 'puppet/application/master'
require 'base64'
require 'json'
require 'rack/utils'
require 'yaml'
@seven1m
seven1m / gitcal
Created September 30, 2010 20:53
Creates iCalendar (ical) format output containing commits from a Git repo.
#!/usr/bin/env ruby
# Creates iCalendar (ical) format output containing commits from a Git repo.
# Save as a file and import into Google Calendar or iCal on Mac.
# Publish on a webserver and link to Google Calendar directly.
# Install & Use:
# gem install grit icalendar
# chmod +x gitcal
# ./gitcal /path/to/repo > commits.ical
$fullred: #ff0000;
body {
font-family: Helvetica, Verdana
}
p {
padding: 7px 10px;
}
#demo {
border: 1px solid $fullred;
}