This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fib_r(n) | |
if(n <= 1) | |
return 1 | |
else | |
return fib(n-1) + fib(n-2) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverse(s): | |
return s[::-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Foo { | |
private String name; | |
private String town; | |
private int age; | |
public Foo setName(String name) { | |
this.name = name; | |
return this; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config = {}; | |
var dns = gcloud.dns(config); | |
// - - - Zones - - - // | |
var query = { | |
maxResults: 2, | |
pageToken: 'blah' | |
}; | |
dns.getZones(query, function(err, zones, nextQuery, apiResponse) {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |