Skip to content

Instantly share code, notes, and snippets.

View gourneau's full-sized avatar

Joshua Gourneau gourneau

View GitHub Profile
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
from twisted.internet import reactor
from twisted.web.websocket import WebSocketHandler, WebSocketResource
from twisted.web.server import Site
from twisted.web.static import File
class Echohandler(WebSocketHandler):
def frameReceived(self, frame):
self.sendFrame(frame)
<html>
<body>
<script>
var myWebSocket = new WebSocket("ws://127.0.0.1:8080/ws/echo");
myWebSocket.onopen = function(evt) {
alert("Connection open ...");
};
myWebSocket.onmessage = function(evt) {
@gourneau
gourneau / imagemagick_php_thumbnail.php
Created November 29, 2010 02:47
Create a thumbnail or resize an image with Imagemagick in PHP
<?php
//Dynamically resize images
function thumb_create($file, $width , $height ) {
try
{
/*** the image file ***/
$image = $file;
/*** a new imagick object ***/
@gourneau
gourneau / hosted-path.php
Created November 29, 2010 06:34
Find the full URL that a PHP script is running at , minus the name of the file
//Find the full url to the site we are at
$protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
$address = $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$currentFile = $_SERVER["SCRIPT_NAME"];
$parts = Explode('/', $currentFile);
$currentFile = $parts[count($parts) - 1];
$site_path = str_replace($currentFile,'',$address);
# this way is best if you want to stay up to date
# or submit patches to node or npm
mkdir ~/local
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.profile
# could also fork, and then clone your own fork instead of ry's
git clone git://github.com/ry/node.git
cd node
@gourneau
gourneau / tasty_put.py
Created April 8, 2011 20:56
PUT to a tastypie API
#This is a little example of how to make a PUT request (see http://microformats.org/wiki/rest/urls )
#To a API written with tastypie (https://github.com/toastdriven/django-tastypie )
# import the standard JSON parser
import json
# import the REST library (from http://code.google.com/p/python-rest-client/)
from restful_lib import Connection
#site url
base_url = "http://IP/api/v1"
@gourneau
gourneau / python-pil-image-sprite.py
Created April 24, 2011 02:45
Make sprites of images using Python and PIL
#!/usr/bin/python
# This work is licensed under the Creative Commons Attribution 3.0 United
# States License. To view a copy of this license, visit
# http://creativecommons.org/licenses/by/3.0/us/ or send a letter to Creative
# Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
# from http://oranlooney.com/make-css-sprites-python-image-library/
# Orignial Author Oran Looney <olooney@gmail.com>
<html>
<head>
<title>Checkbox</title>
<style>
input[type=checkbox] {
display:none;
}
input[type=checkbox] + label
{
@gourneau
gourneau / launch.sh
Created October 24, 2011 23:36
Ion Torrent - Recursive plugin call
#!/bin/bash
VERSION="0.1"
#Set the URL for the API requests
plugin_url=http://127.0.0.1/rundb/api/v1/results/${RUNINFO__PK}/plugin/
#Set the HTTP Headers
api_header="Content-Type: application/json;Accept: application/json"