Skip to content

Instantly share code, notes, and snippets.

View ryanseys's full-sized avatar
🌴

Ryan Seys ryanseys

🌴
View GitHub Profile
@ryanseys
ryanseys / fib_r.rb
Created January 20, 2013 18:51
Recursive Fibonacci solution
def fib_r(n)
if(n <= 1)
return 1
else
return fib(n-1) + fib(n-2)
end
end
@ryanseys
ryanseys / reverse.py
Created January 17, 2013 15:14
Reverse a string in Python
def reverse(s):
return s[::-1]
@ryanseys
ryanseys / installstuff.sh
Last active October 27, 2015 06:52
Install stuff
#!/bin/bash
# install homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# install brew-cask
brew install caskroom/cask/brew-cask
# install homebrew packages
brew install python
@ryanseys
ryanseys / Foo.java
Created October 10, 2015 19:54
Builder pattern without a Builder class
public class Foo {
private String name;
private String town;
private int age;
public Foo setName(String name) {
this.name = name;
return this;
}
@ryanseys
ryanseys / gcloud-socket.js
Last active August 29, 2015 14:20
Testing socket stuff
// before running, set pool: { maxSockets: 2 } in request defaults.
var projectId = process.env.PROJECT_ID;
var keyFile = process.env.GCLOUD_KEYFILE;
var fs = require('fs');
var gcloud = require('gcloud')({
projectId: projectId,
credentials: require(keyFile)
});
var range = Array.apply(null, Array(1000)).map(function (_, i) {return i;});
var str = '';
for (i in range) {
str += String.fromCharCode(i);
}
new Buffer(str).toString('utf8') == str
// returns true
@ryanseys
ryanseys / dns.js
Last active August 29, 2015 14:19
Cloud DNS
var config = {};
var dns = gcloud.dns(config);
// - - - Zones - - - //
var query = {
maxResults: 2,
pageToken: 'blah'
};
dns.getZones(query, function(err, zones, nextQuery, apiResponse) {});
function getUniformRandomNumber() {
return Math.random();
}
// Rate is the rate parameter of the exponential
// distribution. Typically denoted by lambda.
function getExponentialRandomNumber(rate) {
return Math.log(1 - Math.random()) / (−rate);
}
// Acceptance rejection technique
function AcceptReject() {}
AcceptReject.prototype.inverseG = function(x) {
return -1 * Math.log((1 - x) / 2.85);
};
AcceptReject.prototype.f = function(x) {
return 20 * x * Math.pow(1 - x, 3);
};
@ryanseys
ryanseys / poisson-packet.js
Created March 17, 2015 16:55
First N Packet Poisson Arrival Times
function firstNPacketPoissonArrivals(n, rate, t) {
n--;
t = t || 0;
var u, x;
var lambda = rate;
u = Math.random(); // random value between [0, 1]
x = (-1/lambda)*Math.log(1-u);
t = t + x;
console.log('Arrival of packet at time: ' + t);
if (n > 0) {