Skip to content

Instantly share code, notes, and snippets.

View codejoust's full-sized avatar

Iain codejoust

View GitHub Profile
@codejoust
codejoust / ss_clean_db.php
Created March 2, 2012 04:31
Silverstripe Database Cleanup Script
<?php
class Director { public function set_dev_servers($arg){} };
class SSViewer { public function set_theme($arg){} };
include_once('../public_html/mpt/_config.php');
$sql = "DELETE FROM SiteTree_versions
WHERE CONCAT_WS('_', RecordID, Version) NOT IN
@codejoust
codejoust / recurse.c
Created February 28, 2012 14:24
tricky recursion
// in c
#include <stdio.h>
void loopz(int num){
num += 1;
if (num < 10) {
loopz(num);
puts("Cannot Compute");
} else {
puts("Stopping");
}
@codejoust
codejoust / compile_site.js
Created February 15, 2012 04:13
Nodejs Static Site Builder / Watcher - Jade/Styl -> HTML/CSS
var stylus = require('stylus'),
jade = require('jade'),
fs = require('fs');
function compile_jade(){
console.log('compiling html index');
var fn = jade.compile(fs.readFileSync('index.jade', 'utf8'), {pretty: true});
if (fn){
fs.writeFileSync('index.html', fn());
} else {
@codejoust
codejoust / basic_vectors.rb
Created January 27, 2012 20:50
Some Basic Vector Classes and Functions
# encoding: utf-8
#require 'rubygems'
#require 'fraction'
class Base3D
attr_accessor :x, :y, :z
def initialize(x, y, z)
@x = x; @y = y; @z = z
end
@codejoust
codejoust / serial_py.py
Created December 15, 2011 15:59
serial_py
import serial, cwiid, time, sys
print('Place wiimote in discoverable mode now')
wiimote = cwiid.Wiimote()
if not wiimote:
print('cannot find wiimote')
sys.exit()
@codejoust
codejoust / arduino_wii.pde
Created December 15, 2011 15:58
arduino_wii
#include <Servo.h>
Servo drive1;
Servo drive2;
void setup(){
Serial.begin(9600);
drive1.attach(5);
drive2.attach(6);
}
@codejoust
codejoust / char_test_reader.c
Created December 14, 2011 02:05
Char Test Reader (Arduino C)
// Arduino Char -> Number over serial. For testing, etc.
// @author Iain Nash iain.in
// @date 12/13/11
//#define PWM_DEMO 1
// ^ uncomment for pwm demo
#define PWM_DEMO 0
// ^ and comment this
int get_serial_num(){
@codejoust
codejoust / import_db.py
Created August 25, 2011 15:40
import_db
import MySQLdb, re
conn = MySQLdb.connect(host = "localhost", user = "testuser", passwd = "testpass", db = "test")
cursor = db.cursor()
datafile = open('taxes.txt')
line = ''
while(line = datafile.readline()):
fields = re.split(r'\|+', line)
@codejoust
codejoust / api-callback.js
Created August 24, 2011 18:39
JSONP middleware callback.
module.exports = function(opts){
return function(req, res, next){
if ('callback' in req.query){
var callback = req.query.callback.replace(/[^A-Z0-9\.a-z_\$]/g, '');
if (callback.length == 0){
res.setHeader('X-Callback', 'Invalid');
next();
return;
}
var origHead = res.writeHead,
<?php
/**
* The Template for displaying all single product posts.
*/
?>
<?php get_header(); ?>
<div id="content">
<div class="wrap">
<div id="leftcol">