Skip to content

Instantly share code, notes, and snippets.

View andrewberls's full-sized avatar

Andrew Berls andrewberls

View GitHub Profile
@andrewberls
andrewberls / rotateMatrix.js
Created February 26, 2013 20:53
Function to rotate matrices
function rotateMatrix(matrix, numRot) {
var result = [],
buf = [];
if (numRot != 0) {
for (var i=0; i<matrix.length; i++) {
for (var j=0; j<matrix.length; j++) {
buf.push(matrix[j][i])
}
result.push(buf.reverse())
counts = Hash.new(0)
File.read("#{Dir.home}/.bash_history").each_line do |line|
cmd = line.split.first
if cmd == "git"
cmd = line.split.take(2).join("_") # git_push
end
counts[cmd] += 1
end
counts.sort_by { |key, value| value }.reverse.each do |cmd, count|
var x = 0;
function test() {
x = 1;
y = 2;
var z = 3;
}
test();
@andrewberls
andrewberls / dynamic_functions.js
Created May 30, 2013 22:43
Attempting to dynamically define methods in JS
var methods = ['one', 'two'],
test = {};
for (var i=0; i<methods.length; i++) {
var name = methods[i];
test[name] = function() { console.log(name); }
}
test.one() // 'two'
// JSON structure:
{
"countries" : [
{ "name": "CountryName", "alternatives": "One Two" },
{ ... }
]
}
@andrewberls
andrewberls / index.html
Last active December 20, 2015 08:39
d3 Impact Visualization
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 Page Template</title>
<style>
* { margin: 0; padding: 0; }
body { padding: 30px; }
@andrewberls
andrewberls / index.html
Last active December 20, 2015 09:49
Bash command visualization
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bash Command Visualization</title>
<style type="text/css">
* { margin: 0; padding: 0; }
#chart {
@andrewberls
andrewberls / cs.sh
Created July 31, 2013 06:44
cs bash alias
# Run git status if in git repo, else ls -la
function cs {
clear
if ! git ls-files >& /dev/null
then
ls -la
else
git status
fi
}
tracerColors = [
'#1B184F',
'#312c91',
'#423ac0',
'#9c4274'
]
class Tracer extends Kona.Entity