Skip to content

Instantly share code, notes, and snippets.

View halfninja's full-sized avatar
🌶️
spicy code

Nick Howes halfninja

🌶️
spicy code
View GitHub Profile
@halfninja
halfninja / domstorage.js
Created April 28, 2009 20:12
sessionStorage wrapper
// Data stored in DOM Session Storage (on supported browsers).
// create the SessionObject with a unique key name, then put data
// in to the data property. It will be JSONified to and fro automatically
// between page loads.
var SessionObject = function(key) {
this.data = null;
this.key = key;
this.store = window.sessionStorage;
if (this.store[this.key])
{
@halfninja
halfninja / imce_upload_textfield.php
Created May 29, 2009 21:37
Drupal IMCE "Upload/choose file" link
<?php
/*
For Drupal, when using the IMCE file manager.
Decorates selected text fields with an "Upload/choose file" link next to them
that opens up the IMCE editor. $ids contains the array.
If I knew more about Drupal this would probably be a lot neater and require
less in-page Javascript.
@halfninja
halfninja / Quaternion.java
Created September 9, 2010 21:12
Quaternion and Vector3 classes for Java
package uk.co.halfninja.math;
/**
* Quaternions are data structures built from unicorn horns.
*
* I nabbed this implementation from The Internet.
*/
public final class Quaternion {
private double x;
private double y;
@halfninja
halfninja / Android.mk
Created February 15, 2011 20:57
Building FFMPEG+libx264 for Android NDK
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := videokit
FFMPEG_LIBS := $(shell find ffmpeg -name '*.a')
LOCAL_CFLAGS += -Iffmpeg
LOCAL_LDLIBS += -llog $(FFMPEG_LIBS)
LOCAL_SRC_FILES := jni_interface.c
include $(BUILD_SHARED_LIBRARY)
@halfninja
halfninja / likeruby.rb
Created February 27, 2011 10:41
Silly extension to Ruby grammar
%w(so like totally whatever whatever? um uh yeah stuff dude shit but no cos).each do |word|
instance_eval %{def #{word}(w=nil); w; end}
end
# now you can code like this:
so like x = 3 and shit
um yeah so puts x or whatever?
yeah but no but yeah but no cos x = 3 or whatever
@halfninja
halfninja / gist:1122949
Created August 3, 2011 15:44
Apache config for Jekyll sites in development (allows .html to be omitted, Alias should match the name of your project, or commented out if it's a user page that is served from root path)
We couldn’t find that file to show.
@halfninja
halfninja / JavaImports.scala
Created February 13, 2012 14:47
Simple way of exposing a bunch of type aliases in your Scala application
// extend your class with JavaImports to expose these types
trait JavaImports {
type JBoolean = java.lang.Boolean
type JList[V] = java.util.List[V]
type JMap[K,V] = java.util.Map[K,V]
type JSet[V] = java.util.Set[V]
// Add more types as desired
}
// or import JavaImports._
@halfninja
halfninja / deepgrep.sh
Created March 27, 2012 14:07
Recursive grep
#!/bin/bash
function usage() {
echo "Usage: deepgrep search-term file-pattern"
}
if [[ "$1" == "" || "$2" == "" ]]; then
usage
exit 1
fi
/*
* A selection of illustrative lines that describe a bit about how Scala does things
* and various parts of the language and/or library that you might find useful often.
*/
// val is similar to a final variable in Java - it can't be reassigned
val filename = "log.txt"
// var can be changed
var filename = "log.txt"
#!/bin/bash
## Encode a file to an MP4 that my TV can play.
## Assumes SD card is inserted at /media/NO_NAME,
## and Handbrake CLI is installed (apt-get install handbrake-cli).
## See "HandBrakeCLI -z" for list of presets.
SDCARD=/media/NO_NAME
HANDBRAKE_PRESET=Normal
function die() {
echo "$@" 1>&2