Skip to content

Instantly share code, notes, and snippets.

View jl2's full-sized avatar

Jeremiah LaRocco jl2

View GitHub Profile
@jl2
jl2 / jrepl.py
Created December 9, 2011 01:43
A Javascript REPL using PyQt's QtScript
#!/usr/bin/python3
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4 import QtScript
from PyQt4.QtScript import QScriptEngine, QScriptValue
def my_exit(context, eng):
@jl2
jl2 / javascript.py
Created December 9, 2011 18:31
Command line Javascript REPL using QtScript. If given a filename argument, runs the file and exits.
#!/usr/bin/env python3
import sys
from PyQt4 import QtCore
from PyQt4.QtScript import QScriptEngine, QScriptValue
def my_exit(context, eng):
exit(0)
@jl2
jl2 / gisthtml.py
Created December 23, 2011 04:59
Create static HTML from a Gist ID. See http://jlarocco.com/2011/12/22/static-gist-creator/ for more info.
#!/usr/bin/env python3
import urllib.request
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtScript import QScriptEngine, QScriptValue
@jl2
jl2 / ptmap.py
Created December 30, 2011 21:26
Map points between rectangles.
#!/usr/bin/env python3
import sys
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
class Mapper:
def __init__(self, old_ul, old_lr, new_ul, new_lr):
self.old_ul = old_ul
@jl2
jl2 / readaudio.c
Created January 26, 2012 06:33
Use ffmpeg's libavcodec and libavformat to decode an audio file into an output buffer.
/*
readmp3.c
Copyright (c) 2012, Jeremiah LaRocco [email protected]
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
@jl2
jl2 / gen_stl.py
Created April 19, 2012 00:02
Simple code to generate a binary .STL file
#!/usr/bin/env python3
import sys
import struct
import math
class Vertex:
def __init__(self, x,y,z):
self.val = [x,y,z]
@jl2
jl2 / mkhelix.py
Created May 15, 2012 19:31
Python script using CATIA's COM interface to create a product structure containing 200 cubes arranged in a helix.
#!/usr/bin/env python3
import sys
import array
import math
import random
import os.path
import win32com.client
def get_catia():
@jl2
jl2 / chromeup.hs
Created June 14, 2012 23:38
Haskell code to download and install the latest Chromium continuous build on Windows.
module Main (main) where
import System.Cmd
import Network.Socket
import System.Environment
import Network.HTTP.Conduit
import qualified Data.ByteString.Lazy.Char8 as C8
main = do
let versionUrl = "http://commondatastorage.googleapis.com/chromium-browser-continuous/Win/LAST_CHANGE"
@jl2
jl2 / dts.adb
Created July 20, 2012 23:59
Calculate the approximate number of days till Arapahoe Basin opens
-- Calculate the approximate number of days till Arapahoe Basin opens
with Ada.Text_Io;
use Ada.Text_Io;
with Ada.Calendar;
use Ada.Calendar;
procedure dts is
tod : Time := Clock;
OpeningDay : Time := Time_Of(Day=>25,
Month=>10,
@jl2
jl2 / loadmixin.cpp
Created July 26, 2012 22:48
An interesting mixin "pattern" using inheritance from a template base class.
#include <iostream>
// A templated abstract base class indicating that all subclasses will have a "load" method, but the parameter type will vary
template <class T> class Loadable {
public:
virtual bool load(const T &ival)=0;
};
// A subclass that's loadable from an integer
class SubOne : public Loadable<int> {