Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am iande on github.
  • I am iande (https://keybase.io/iande) on keybase.
  • I have a public key ASAAZLXxLfI56JPzKX02tjCdOJwekL22WGsEiHzJyTU1LQo

To claim this, I am signing this object:

@iande
iande / NumberBox.java
Created May 11, 2012 20:40
Bounded Type Parameters
// The bounded type parameter dictates the kinds of Box instances we can create.
public class NumberBox<T extends Number> {
private T _number;
public NumberBox() { this(null); }
public NumberBox(T toStore) {
set(toStore);
}
public T get() { return _number; }
@iande
iande / Box.java
Created May 9, 2012 14:34
Why generic type checking is slightly different...
public class Box<T> {
private T whatsInTheBox;
// Creates a new box that holds nothing of value
public Box() { this(null); }
// Creates a new box that holds the given T instance.
public Box(T store) {
this.set(store);
}
@iande
iande / 01_without_boxing.java
Created April 19, 2012 13:20
Boxing and Unboxing example
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> myList = new ArrayList<Integer>();
myList.add(new Integer(10));
myList.add(new Integer(11));
myList.add(new Integer(12));
@iande
iande / Badness.java
Created April 17, 2012 20:51
Why instanceof Is the Devil.
public class Triangle {
public int width;
public int height;
}
public class Rectangle {
public int width;
public int height;
}
@iande
iande / Main.java
Created April 17, 2012 14:36
When there is no explicit constructor...
public static void main() {
// Java provides a "default" no-argument constructor for us.
MyCoolShit coolShit = new MyCoolShit();
// But, NEVER rely on it!
System.out.println("Bool: " + coolShit.aBool);
System.out.println("Int: " + coolShit.anInt);
System.out.println("Double: " + coolShit.aDouble);
System.out.println("Char: " + coolShit.aChar);
System.out.println("String: " + coolShit.aString);
@iande
iande / Rectangle.java
Created April 10, 2012 13:45
Rectangle Example
public class Rectangle {
public static int COUNTER = 0;
public int width;
public int height;
private int myX;
private int myY;
public Rectangle(int x, int y, int w, int h) {
// Position and dimensions were given, so we construct a rectangle at (x,y)
@iande
iande / pinkhair.rb
Created March 15, 2012 19:12
quick test of ircbgb
#!env ruby
require 'bundler'
Bundler.setup
require 'ircbgb'
bot = Ircbgb::Client.new do |c|
c.servers = 'irc://pinkhair.gudefrends.net'
c.nicks = ['iande', 'ian-2', 'ian-3']
@iande
iande / jcart-mods.js
Created March 10, 2012 23:42
jcart modification
// Line 174 of jcart v1.3
// Add an item to the cart
$('.jcart').submit(function(e) {
add($(this));
e.preventDefault();
});
// Try replacing or adding:
@iande
iande / gist:1779895
Created February 9, 2012 13:18
Wrapping class singleton (eigen) methods with a module
# Note: MyFinalApproach defines a block that takes a block,
# which only works with Ruby >= 1.9. To work with 1.8, you'll need
# to take that bit out.
# Also, I think 'eigen' contains more phonetic badassery than
# 'singleton', which is the real reason I prefer it.
require 'forwardable'
class SomeClass
def self.my_eigen_method; 42; end