Skip to content

Instantly share code, notes, and snippets.

View jnrbsn's full-sized avatar

Jonathan Robson jnrbsn

View GitHub Profile
@jnrbsn
jnrbsn / httpd.php
Created December 19, 2012 03:41
The beginnings of a really simple web server written in PHP.
<?php
error_reporting(-1);
set_time_limit(0);
$host = '0.0.0.0';
$port = 12345;
$max_clients = 10;
// Create the socket.
@jnrbsn
jnrbsn / AtomicParsley.php
Created December 19, 2012 03:27
Wrapper class for AtomicParsley for setting iTunes style meta data on MPEG-4 files via PHP.
<?php
/**
* Wrapper class for AtomicParsley for setting iTunes style meta data on MPEG-4 files.
*
* Dependencies:
* - Bunsen <http://github.com/jnrbsn/bunsen>
* - AtomicParsley <http://atomicparsley.sourceforge.net/>
*/
class AtomicParsley
@jnrbsn
jnrbsn / squarize.php
Created December 19, 2012 03:12
Calculates the "busiest" square area of an image to use for a thumbnail.
<?php
/**
* An example of how to use the `squarize()` function below.
*/
$path_input = 'input.png';
$path_output = 'output.png';
$thumb_w = 100;
$thumb_h = 100;
@jnrbsn
jnrbsn / twitter-bitly-bookmarklet.js
Created September 14, 2010 00:48
Bit.ly + Twitter bookmarklet using pure JavaScript
javascript:(function(){var%20s=document.createElement('script'),l=location.href;s.type='text/javascript';s.src='http://bit.ly/javascript-api.js?version=latest&login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07';s.onload=function(){BitlyCB.f=function(d){location.href='http://twitter.com/home?status='+encodeURIComponent(document.title+'%20'+d.results[l]['shortUrl'])};BitlyClient.shorten(l,'BitlyCB.f')};document.body.appendChild(s)})()
@jnrbsn
jnrbsn / gist:3966886
Created October 27, 2012 23:43
Read a file line by line in Node.js
var fs = require('fs'),
EventEmitter = require('events').EventEmitter;
var createLineReader = function (filename) {
var stream = fs.createReadStream(filename),
em = new EventEmitter(),
buffer = '';
stream.on('error', function (error) {
throw error;
@jnrbsn
jnrbsn / jquery-mobile-test.html
Created June 6, 2012 18:56
Demonstration of jQuery Mobile issue for Stack Overflow question: http://stackoverflow.com/questions/10920495
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile Test</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css">
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
<script>
@jnrbsn
jnrbsn / httpserver.py
Created April 25, 2012 23:51
Serves up the current directory to localhost via an instant HTTP server.
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
try:
HandlerClass = SimpleHTTPRequestHandler
ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.0"
if sys.argv[1:]:
-- MySQL procedure for converting all MyISAM tables in a database to InnoDB.
--
-- Example usage:
--
-- $ mysql -N example_database < convert_innodb.sql
--
-- @author Jonathan Robson <jnrbsn@gmail.com>
-- @copyright 2011 Jonathan Robson
-- @license http://gist.github.com/802399 MIT License
-- @link http://gist.github.com/1144336
@jnrbsn
jnrbsn / MIT_License.md
Created January 30, 2011 01:17
The MIT License

THE MIT LICENSE

Copyright © <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is

@jnrbsn
jnrbsn / plus_business_hours.php
Created September 14, 2010 19:46
Adds a specified number of business hours to a unix timestamp.
<?php
/**
* Adds a specified number of business hours to a unix timestamp.
*
* @param int $time_start The timestamp at which to start
* @param int $plus_hours The number of business hours to add
*
* @return int The resulting timestamp
*/
function plus_business_hours($time_start, $plus_hours)