Skip to content

Instantly share code, notes, and snippets.

@psema4
psema4 / client.js
Created December 14, 2010 17:56
Simple Node.JS web server & client
// Modified from Node.JS documentation: http://nodejs.org/docs/v0.2.5/api.html#http-client-183
var http = require('http');
var server = http.createClient(8124, '127.0.0.1');
var request = server.request('GET', '/', {'host': '127.0.0.1'});
request.end();
request.on('response', function (response) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.setEncoding('utf8');
@psema4
psema4 / altermeta.html
Created May 27, 2011 14:54
Altering Metatags With JS
<!doctype html>
<html lang="en">
<head>
<title>Altering Metatags At Runtime</title>
<meta id="meta-test" name="Copyright" content="(C)2011 Some User" />
</head>
<body>
<h1>Altering Metatags At Runtime</h1>
<p id="output">(Click "Check Metatag")</p>
@psema4
psema4 / table-update-notifications.js
Created June 9, 2011 16:08
Notifications of dynamic changes to HTML tables
<script>
// Inspired by http://stackoverflow.com/questions/6293495/
myTable = document.getElementsByTagName('table')[0];
if (document.implementation.hasFeature('MutationEvents','2.0')
|| window.MutationEvent) {
myTable.addEventListener('DOMNodeInserted', function(e) {
@psema4
psema4 / bookmarklet.js
Created June 11, 2011 20:18 — forked from kn0ll/bookmarklet.js
advanced bookmarklet template
javascript:(function() {
if(!window.your_bookmarklet) {
var doc = document,
js = doc.createElement('script');
js.type = 'text/javascript';
js.src = 'loader.js';
js.async = true;
# wget --header='Accept-Encoding: gzip' -O root.bin.gz http://bellard.org/jslinux/root.bin
# gunzip root.bin.gz
# mkdir mnt
# mkdir files
# sudo mount -t ext2 -o loop root.bin mnt
# dd if=/dev/zero of=files/root.bin bs=1k count=4096
# sudo mke2fs -m 0 -i 2000 files/root.bin
# mkdir mnt2
# sudo mount -t ext2 -o loop files/root.bin mnt2
# sudo cp -dpR mnt/* mnt2/
@psema4
psema4 / server.js
Created July 4, 2011 21:47
A Static Web Server in Node.js with simple Access Control
#!/usr/bin/env node
var http = require('http'),
url = require('url'),
fs = require('fs'),
util = require('util'),
host = '127.0.0.1',
port = 8080,
useBAC = true,
@psema4
psema4 / JSONSimple.pm
Created July 5, 2011 18:55
Braindead JSON encoder/decoder for Perl
package JSONSimple;
use strict;
sub new {
my $class = shift;
my $self = {};
bless($self, $class);
return $self;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>
MobileSafari Live Click Bug
</title>
<script src='http://code.jquery.com/jquery-git.js' type='text/javascript'></script>
<script src='http://media.lib.byu.edu/js/jquery/plugins/jquery.livequery-1.0.3.js' type='text/javascript'></script>
</head>
<body style='font-family: Helvetica;'>
@psema4
psema4 / gist:5365829
Created April 11, 2013 18:17
ES6 Classes Polyfill (via public-webapps, A Wirfs-Brock)
// ES6
class Sub extends Super {
constructor() {/*constructor body */ }
method1 () {}
static method2 {}
}
// ES3/5
function Sub() {/*constructor body */ }
Sub.__proto__ = Super;
@psema4
psema4 / minidb
Created November 14, 2013 17:02
A simple utility to read all .sql files in the current directory, create an in-memory database from them and start a sqlite3 shell
#!/usr/bin/env bash
# A simple utility to read all .sql files in the current directory, create an
# in-memory database from them and start a sqlite3 shell
if [ -f mini.db ]; then
echo "found existing database, removing"
rm mini.db;
fi