Skip to content

Instantly share code, notes, and snippets.

View chrisyco's full-sized avatar

Chris Wong chrisyco

View GitHub Profile
@chrisyco
chrisyco / gist:972805
Created May 15, 2011 01:23
Epic Example From Java Specification
interface Fish { int getNumberOfScales(); }
interface Piano { int getNumberOfScales(); }
class Tuna implements Fish, Piano {
// You can tune a piano, but can you tuna fish?
int getNumberOfScales() { return 91; }
}
@chrisyco
chrisyco / fixext.py
Created May 23, 2011 04:05
Recursively rename UPPERCASE filename extensions to lowercase
#!/usr/bin/env python
"""Epic script to rename scary uppercase extensions (like .JPG) to
more friendly lowercase (like .jpg).
How to use
==========
Recursively rename all files in the current directory::
fixext
@chrisyco
chrisyco / power.sh
Created May 24, 2011 03:38
Suspend, hibernate, restart or shutdown the computer without sudo!
#!/bin/sh
# Suspend, hibernate, restart or shutdown the computer without sudo!
# by Chris Wong
# Released to the public domain.
NAME=$0
usage() {
echo "Usage: $NAME suspend|hibernate|restart|shutdown"
@chrisyco
chrisyco / Frangipani.scala
Created September 10, 2011 06:18
LWJGL test
object Frangipani {
// Add path to native libraries
val jarName = getClass.getProtectionDomain.getCodeSource.getLocation.getPath
val nativeDir = new File(new File(jarName).getParent, "natives").getPath
System.setProperty("org.lwjgl.librarypath", nativeDir)
def start() {
// Initialize the display
try {
Display.setDisplayMode(new DisplayMode(800, 600))
@chrisyco
chrisyco / interactive_sort.py
Created October 2, 2011 00:38
Sort a list of items interactively
yes_letters = set('yt')
no_letters = set('nf')
def read_bool(prompt):
'''Read a boolean value from standard input.'''
answer = None
while answer not in yes_letters and answer not in no_letters:
answer = raw_input(prompt).strip()[0].lower()
return answer in yes_letters
@chrisyco
chrisyco / gist:1276918
Created October 11, 2011 00:01
Autoboxing is not foolproof
// Duck.java
class Duck {
public static void quack(Integer num) {
System.out.println(num);
}
}
// Main.java
class Main {
public static void main(String[] args) {
@chrisyco
chrisyco / desmume-compiling.md
Created December 13, 2011 05:01
How to compile DeSmuME on Debian or Ubuntu

How to compile DeSmuME on Debian or Ubuntu

(with a mildly condescending tone)

Step 0 (optional)

You can enable fancy optimizations by creating a config.site file. To do this, open your favorite text editor and type:

@chrisyco
chrisyco / BirdTree.hs
Created January 1, 2012 05:05
Bird tree solution
module BirdTree where
import Control.Monad.Maybe
import Control.Monad.State
import Data.ByteString.Char8 ( ByteString )
import qualified Data.ByteString.Char8 as B
import Data.Char ( isSpace )
import Data.Functor ( (<$>) )
@chrisyco
chrisyco / BirdTree.hs
Created January 17, 2012 01:39
Bird tree solution (simplified)
import Data.ByteString.Char8 ( ByteString )
import qualified Data.ByteString.Char8 as B
import Data.Char ( isSpace )
import Data.Functor ( (<$>) )
import Data.List ( intercalate, unfoldr )
import Data.Maybe ( fromJust )
import Data.Ratio ( (%) )
{-
@chrisyco
chrisyco / BirdTree.hs
Created January 19, 2012 04:16
Bird tree solution in linear time
import Data.ByteString.Char8 ( ByteString )
import qualified Data.ByteString.Char8 as B
import Control.Applicative ( (<$>), (<*>) )
import Data.Char ( isSpace )
import Data.List ( intercalate )
import Data.Maybe ( catMaybes )
import Data.Ratio ( (%), numerator, denominator )
{-