Skip to content

Instantly share code, notes, and snippets.

View adam-singer's full-sized avatar
👾

Adam Singer adam-singer

👾
View GitHub Profile
@banksean
banksean / mersenne-twister.js
Created February 10, 2010 16:24
a Mersenne Twister implementation in javascript. Makes up for Math.random() not letting you specify a seed value.
/*
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
so it's better encapsulated. Now you can have multiple random number generators
and they won't stomp all over eachother's state.
If you want to use this as a substitute for Math.random(), use the random()
method like so:
var m = new MersenneTwister();
@criminy
criminy / AbstractMockitoMultipartHttpServletRequestUnitTest.java
Created July 21, 2011 14:02
Abstract Unit test for a @controller with MultipartHttpServletRequest
import static org.mockito.Mockito.*;
/**
* Boostraps a MultipartHttpServletRequest using mockito.
* To add a request parameter, define a method called 'parameterName', where request attribute is 'name'.
* To add a multipart file, define a method called 'fileName', where the multipart file is called 'name'.
* Class is very limited but works as it should providing you use a specific subset of the methods on {@link MultipartHttpServletRequest}.
* Subset:
* MultipartHttpServletRequest.getParameter
* MultipartHttpServletRequest.getFileMap
@olov
olov / gist:1320163
Created October 27, 2011 17:10
Pygments DartLexer for syntax highlighting. Example and installation instructions: <http://blog.lassus.se/2011/10/dart-syntax-highlighting.html>
class DartLexer(RegexLexer):
"""
For `Dart <http://dartlang.org/>`_ source code.
"""
name = 'Dart'
aliases = ['dart']
filenames = ['*.dart']
mimetypes = ['text/x-dart']
@ltackmann
ltackmann / SVGSamples.dart
Created December 29, 2011 04:09
SVG in Dart
#import('dart:html');
class SVGSamples {
void run() {
drawlines();
}
void drawlines() {
final int maxY = 250;
@kencoba
kencoba / Bridge.scala
Created February 21, 2012 10:49
Bridge pattern (Design Patterns in Scala)
// http://en.wikipedia.org/wiki/Bridge_pattern
trait DrawingAPI {
def drawCircle(x:Double, y: Double, radius:Double)
}
class DrawingAPI1 extends DrawingAPI {
override def drawCircle(x: Double, y: Double, radius: Double) = {
printf("API1.circle at %f:%f radius %f\n", x, y, radius)
}
@sethladd
sethladd / IndexedDBSample.dart
Created February 23, 2012 01:46
Dart IndexedDB sample
#import('dart:dom', prefix:'dom');
#import('dart:html');
String VERSION = "1";
String TODOS_STORE = 'todos';
initDb(db) {
if (VERSION != db.version) {
dom.IDBVersionChangeRequest versionChange = db.setVersion(VERSION);
versionChange.addEventListener('success', (e) {
@d2m
d2m / gist:1935339
Created February 28, 2012 21:42
dart document.cookie lib
/*
* dart document.cookie lib
*
* ported from
* http://www.quirksmode.org/js/cookies.html
*
*/
void createCookie(String name, String value, int days) {
String expires;
@pjako
pjako / docsGen.dart
Created April 3, 2012 13:05
Dart Docs generation Script
#import('dart:io');
final String PATH_TO_DARTSDK = "/Users/XYZ/dart-sdk";
final String SUBDIRECTORY = "";
final String LIBRARY_DARTFILE = "XYZ.dart";
@atebitftw
atebitftw / Dart_Singleton_Maybe
Created April 26, 2012 20:54
Dart Singleton?
class MyClass{
static MyClass _ref;
static MyClass get context() => _ref == null ? new MyClass() : _ref;
factory MyClass(){
if (_ref != null) return _ref;
_ref = new MyClass._internal();
@greenido
greenido / DartCrawlerExample.dart
Created April 28, 2012 08:00
Dart Crawler (server side example)
#import('dart:io');
#import('dart:uri');
#import('dart:json');
// Dart Hackathon TLV 2012
//
// A simple example to fetch JSON and parse it on the server side
// This is a good start for a crawler and/or any other web service
// we wish to create using dart on the server side.
//