Skip to content

Instantly share code, notes, and snippets.

View tk3369's full-sized avatar
🐶
Published! Hands on design patterns and best practices with Julia.

Tom Kwong tk3369

🐶
Published! Hands on design patterns and best practices with Julia.
View GitHub Profile
anonymous
anonymous / main.dart
Created October 8, 2016 20:51
fatdragon-dart
// fib seq
// 1 1 2 3 5 8 13 21 ...
num fibonacci(num n) {
if (n == 1 || n == 2) {
return 1;
} else {
return fibonacci(n-1) + fibonacci(n-2);
}
}
anonymous
anonymous / main.dart
Created October 8, 2016 18:36
fatdragon-dart
// Estimate PI using monte carlo simulation
// See http://www.davidrobles.net/blog/2014/06/22/estimating-pi-using-monte-carlo-simulations/
import 'dart:math';
Random rnd = new Random();
// Return a random point within [-1, 1] coordinate plane
class UnitPoint {
double x;
anonymous
anonymous / main.dart
Created October 8, 2016 18:14
fatdragon-dart
void main() {
var v = [ 1,2,3,4,5,6,7,8,9,10 ];
print(v);
print(v.contains(5));
print(v.where((x) => x % 2 == 0));
print(v.any((x) => x > 10));
print(v.map((x) => x * x));
print(v.length);
}
anonymous
anonymous / main.dart
Created October 8, 2016 18:04
fatdragon-dart
import 'dart:math';
List values(int length) {
List v = [];
Random r = new Random();
for (int i = 0; i < length; i++) {
v.add(r.nextInt(100));
}
return v;
}
anonymous
anonymous / main.dart
Created October 8, 2016 17:55
fatdragon-dart
// shows how to use cascade method calls in Dart
class Cat {
String color;
Cat(this.color);
meow() { print("meow"); }
yawn() { print("yawn"); }
show() { print("furry ${color} hair"); }
}
anonymous
anonymous / main.dart
Created October 8, 2016 17:44
jolly-boat-2677
// positional parameters by fatdragon2
say({String from,
String msg : "good morning america",
String device,
String version : '7'})
{
var result = '$from says $msg';
if (device != null) {
result = '$result with a $device ${version != null ? version : ""}';
@aflaxman
aflaxman / mpl_cfaces.py
Created November 9, 2012 01:12
Chernoff Faces in Python with Matplotlib
from pylab import *
def cface(ax, x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18):
# x1 = height of upper face
# x2 = overlap of lower face
# x3 = half of vertical size of face
# x4 = width of upper face
# x5 = width of lower face
# x6 = length of nose
# x7 = vertical position of mouth