View Foo.java
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; | |
} |
View kill-port.sh
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
lsof -P | grep ':8080' | awk '{print $2}' | xargs kill -9 |
View gcloud-socket.js
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) | |
}); |
View utf8.js
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 |
View dns.js
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) {}); |
View random-nums.js
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); | |
} |
View accept-reject.js
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); | |
}; |
View poisson-packet.js
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) { |
View mailgun.php
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
<?php | |
function send_mailgun($email, $body) { | |
$domain = "YOUR_DOMAIN.COM"; | |
$config = array(); | |
$config['api_key'] = "YOUR_KEY_HERE"; | |
$config['api_url'] = "https://api.mailgun.net/v2/" . $domain . "/messages"; | |
$message = array(); | |
$message['from'] = "Mailgun <YOU@YOUR_ADDRESS_HERE.com>"; |
View reverse-decimal.js
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 reverseDecimal(num) { | |
var arr = num.toString().split('.'); | |
arr[1] = arr[1].split('').reverse().join(''); | |
return parseFloat(arr.join('.')); | |
} | |
var numbers = [0.24, 0.35, 0.76]; | |
console.log(numbers.map(reverseDecimal)); |
NewerOlder