Skip to content

Instantly share code, notes, and snippets.

//create a factory that creates types within a scope
StuppScope scope = new StuppScope();
StuppType type = StuppType.getInstance(Book.class);
StuppFactory<Book, Long> factory = new StuppFactory(type, scope);
//then use it to create objects
Book book = factory.newInstance(1L);
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import javax.imageio.ImageIO;
package com.tomgibara.daisy.demo.provider;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
try {
FileOutputStream out = new FileOutputStream(file);
try {
bitmap.compress(CompressFormat.PNG, 100, out);
} finally {
try {
out.close();
} catch (IOException e) {
Log.w(DaisyGardenApp.LOG_TAG, "Failed to close file: " + file);
}
// some standard includes
#include "colors.inc"
#include "shapes.inc"
// this is the button...
object {
// ...it's a rounded box...
Round_Box(<-1,-1,-1>, <1,1,1>, 0.4, 0)
@tomgibara
tomgibara / NumberWriter.java
Created December 17, 2010 23:55
A small class for converting integers to their textual representation without creating any garbage.
package com.tomgibara.android.util;
/**
* <p>
* Writes ints into char array without generating any objects. This is typically
* useful in instances where numbers must be rendered within a game-loop or
* animation. Instances of this class are not safe for multithreaded use.
* </p>
*
* <p>
@tomgibara
tomgibara / trackersnippet.java
Created May 18, 2011 04:05
Example of using GoogleAnalyticsTracker wrapper
// example analytics
GoogleAnalyticsTracker gat = GoogleAnalyticsTracker.getInstance();
gat.start(/* your analytics parameters */);
// example config
Tracker tracker = new Tracker(gat);
tracker.setAsynchronous(true);
tracker.disable(Tracker.Category.NET);
//example usage
@tomgibara
tomgibara / PermutationSample.java
Created October 18, 2011 00:36
Crinch permutation package overview
// SIMPLE PERMUTATIONS
/**
* Let's start off by creating the simplest permutation: the identity
* permutation, in this case over 5 elements.
*/
Permutation identity = Permutation.identity(5);
/**
@tomgibara
tomgibara / CannyTest.java
Created October 18, 2011 16:21
Canny Edge Detection Test
import java.awt.Container;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
@tomgibara
tomgibara / BloomFilterIntro.java
Created December 14, 2011 00:36
Crinch BloomFilter introduction
/**
* This introduction assumes familiarity with the general concept of
* Bloom filters. If you don't have this try reading:
*
* http://en.wikipedia.org/wiki/Bloom_filter
*/
// HASHING
/**