Skip to content

Instantly share code, notes, and snippets.

View lerouxb's full-sized avatar

Le Roux Bodenstein lerouxb

View GitHub Profile
function getRGB(color) {
// http://plugins.jquery.com/files/jquery.color.js.txt
var result;
// Check if we're already dealing with an array of colors
if (color && color.constructor == Array && color.length == 3)
return color;
// Look for rgb(num,num,num)
if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
@lerouxb
lerouxb / head.py
Created October 26, 2010 08:46
Do a HEAD request on a URL and print status and headers
#!/usr/bin/env python
import httplib
import sys
from urlparse import urlparse
def head(url):
r = urlparse(url)
conn = httplib.HTTPConnection(r.netloc)
pathquery = r.path
@lerouxb
lerouxb / gist:646728
Created October 26, 2010 11:27
nginx config for caching urls with parameters ?v=xxxxx or ?r=xxxxx
server {
listen 80;
server_name static.ammo.dev;
access_log /var/log/nginx/ammostatic.access.log;
location / {
root /home/leroux/projects/ammo/static;
if ($args ~* "^[rv]=.*$") {
expires max;
break;
}
@lerouxb
lerouxb / gist:646738
Created October 26, 2010 11:29
get latest git commit hash/id/thingum for a file
git log -1 --format=%H FILENAME
@lerouxb
lerouxb / post.py
Created November 29, 2010 15:05
Do a POST request on a URL, print status, headers and response body.
#!/usr/bin/env python
import httplib
import sys
from urlparse import urlparse
def post(url, params):
r = urlparse(url)
conn = httplib.HTTPConnection(r.netloc)
pathquery = r.path
@lerouxb
lerouxb / logpost.js
Created November 29, 2010 15:07
Log all posted variables via a little nodejs server.
var http = require('http'),
querystring = require('querystring')
var PORT = 8124;
http.createServer(function(req, res) {
if (req.method == 'POST') {
req.rawpostdata = '';
req.addListener('data', function(chunk) {
req.rawpostdata += chunk.toString('ascii'); // I hope
/*
<style>
#detect.child > p,
#detect.firstchild p:first-child,
#detect.lastchild p:last-child,
#detect.nthchild p:nth-child(2n+1),
#detect.sibling b + b {display: block; width: 111px;}
</style>
*/
@lerouxb
lerouxb / gist:1056418
Created June 30, 2011 15:02
CodeMirror 2 overlay parser for beard
CodeMirror.defineMode("beard", function(config, parserConfig) {
var beardOverlay = {
token: function(stream, state) {
if (stream.match("{{")) {
while ((ch = stream.next()) != null) {
if (ch == "}" && stream.next() == "}") {
break;
}
}
return "beard";
@lerouxb
lerouxb / gist:1071705
Created July 8, 2011 12:16
A little node.js server for testing html5 ajax file uploads.
/*
A little node.js server for testing html5 ajax file uploads.
It serves up the current directory and receives uploads at /upload.
This is for use with xhr.send(file) where the entire request body is the file.
It just pauses one second between chunks so that client-side progress events
get a chance to fire. On my laptop it looks like the maximum chunk size is
around 40K, so you would still need images in the range of hundreds of kilobytes
to really be able to test it.
@lerouxb
lerouxb / gist:1175422
Created August 27, 2011 14:04
upgrouper theme test in jqtpl
<!doctype html>
<html>
<head>
<title>${account.twitter_screen_name} | upgrouper</title>
<link rel="stylesheet" type="text/css" href="${cssurl}">
<script src="${jsurl}"></script>
</head>
<body>
<h1>@${account.twitter_screen_name}</h1>