Skip to content

Instantly share code, notes, and snippets.

View steos's full-sized avatar

Stefan Oestreicher steos

View GitHub Profile
@steos
steos / Kepler.java
Created December 18, 2010 01:40
calculate orbital satellite position using Kepler's laws
import static java.lang.Math.*;
public class Kepler
{
public static class Point2d
{
public double x;
public double y;
public Point2d(double x, double y)
@steos
steos / CountCharFrequency.java
Created December 18, 2010 19:33
example of how to count the character frequency in a string
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
public class CountCharFrequency {
private static final int ASCII_LC_ALPHA_OFFSET = 97;
private static final int NUM_ASCII_CHARS = 26;
private static final char[] extra = new char[] { 'ä', 'ö', 'ü', 'ß' };
@steos
steos / PolarFunctionPlotter.java
Created January 1, 2011 21:48
example of how to plot polar functions including a cool formula for describing spiral arms of galaxies
import static java.lang.Math.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
@steos
steos / gist:779746
Created January 14, 2011 15:37
install git from source (with working git-svn) on debian distros
aptitude install git-core build-essential autoconf libdigest-sha1-perl liberror-perl libsvn-perl
git clone git://git.kernel.org/pub/scm/git/git.git
cd git
make configure
./configure
make
aptitude purge git-core
make install
@steos
steos / gist:805992
Created February 1, 2011 15:17
jgit: walk tree at specific revision
RevWalk rw = new RevWalk(repo);
RevCommit rev = rw.parseCommit(repo.resolve("HEAD"));
RevTree rt = rev.getTree();
TreeWalk tw = new TreeWalk(repo);
tw.addTree(rt);
tw.setRecursive(true);
while (tw.next()) {
System.out.println(tw.getPathString());
@steos
steos / curry.js
Created March 29, 2011 13:28
naive currying in javascript and php (yes! really!)
// this is a helper for the curry function which does partial
// function application; given the function fn, an optional scope
// self and a variable number of arguments this function returns
// a new function which is bound to self with all arguments applied.
// example:
// function add(a, b) {
// return a + b;
// }
// var inc = partial(add, null, 1);
// assert(inc(4) == 5);
@steos
steos / timer.hs
Created August 1, 2011 20:07
haskell timer
import System.Environment
import System.Directory
import Control.Monad
import Database.HDBC
import Database.HDBC.Sqlite3
import Data.Time.Calendar
import Data.Time.Clock
import Data.Time.Format
import System.Locale
import Text.Printf
@steos
steos / TreeFiltering.java
Created November 2, 2011 16:41
Java/Swing/JTree quick'n'dirty filter example
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
@steos
steos / TableFilterHilite.java
Created November 3, 2011 22:53
Java/Swing/JTable quick'n'dirty filter highlighting
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultRowSorter;
import javax.swing.JFrame;
import javax.swing.JPanel;
@steos
steos / MinimalActiveMQPeerProtocolSample.java
Created November 4, 2011 12:57
minimal/naive sample on how to use activemq peer protocol
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;