Skip to content

Instantly share code, notes, and snippets.

{
"auto_find_in_selection": true,
"color_scheme": "Packages/Boxy Theme/schemes/Boxy Solarized Dark.tmTheme",
"font_face": "Ubuntu Mono",
"font_size": 13,
"ignored_packages":
[
"Vintage"
],
"show_encoding": true,
@HopefulLlama
HopefulLlama / NestedTry.java
Last active September 7, 2016 14:16
Exploration of the behaviour of nested try blocks
public class NestedTry {
public static void main(String[] args) {
try {
try {
Long one = Long.parseLong("1");
} catch(NumberFormatException e) {
System.out.println("First block!");
}
Long two = Long.parseLong("2");
@HopefulLlama
HopefulLlama / max-subarray-problem.js
Created August 4, 2016 10:14
Finds the largest sum of sub-arrays, given an array of integers (Not allowing for zero length sub-arrays).
function maxContiguousSubArray(array) {
var maxEndingHere = array[0];
var maxSoFar = array[0];
for(var i = 1; i < array.length; i++) {
maxEndingHere = Math.max(array[i], maxEndingHere + array[i]);
maxSoFar = Math.max(maxSoFar, maxEndingHere);
}
return maxSoFar;
}
@HopefulLlama
HopefulLlama / least-common-multiple-2-inputs.js
Last active August 3, 2016 10:50
Finds the Least Common Multiple for two numbers.
function getGreatestCommonDivisor(x, y) {
while(x !== 0 && y !== 0) {
if(x > y) {
x %= y;
} else {
y %= x;
}
}
return Math.max(x, y);
}
@HopefulLlama
HopefulLlama / euclids-greatest-common-divisor.js
Last active August 3, 2016 10:46
JavaScript implementation of Euclid's Algorithm (Modulus based); Tests whether two numbers are co-prime or not.
function getGreatestCommonDivisor(x, y) {
while(x !== 0 && y !== 0) {
if(x > y) {
x %= y;
} else {
y %= x;
}
}
return Math.max(x, y);
}
@HopefulLlama
HopefulLlama / properties.groovy
Last active December 6, 2022 12:18
Print all properties of a Groovy object
println object.properties
.sort{it.key}
.collect{it}
.findAll{!['class', 'active'].contains(it.key)}
.join('\n')
@HopefulLlama
HopefulLlama / tarjans.js
Last active November 15, 2022 23:18
JavaScript implementation of Tarjan's strongly connected components algorithm
function Vertex(name) {
this.name = name;
this.index = null;
this.lowlink = null;
this.onStack = false;
this.children = [];
}
function TarjanRunner() {