Skip to content

Instantly share code, notes, and snippets.

View ramn's full-sized avatar

ramn ramn

View GitHub Profile
@ramn
ramn / git_difflog_over_rebase.sh
Created January 11, 2013 11:15
Show commits that are in feature123_rebased_on_master but not in feature123, even though they have aquired new commit ids due to rebase.
# Show commits that are in feature123_rebased_on_master but not in feature123, even though they have aquired new commit ids due to rebase.
git log --cherry-pick --left-right feature123...feature123_rebased_on_master ^master
@ramn
ramn / generate_completions.sh
Created December 20, 2012 13:01
Generate tab completions for shell command
function _build_completions_helper {
local current_word
COMPREPLY=()
current_word=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -W "${PROGRAM_COMMANDS}" -- $current_word))
return 0
}
# param 1: command to build completions for. Ex: fab
#
@ramn
ramn / FizzBuzz.scala
Created November 25, 2012 16:15
FizzBuzz in scala, somewhat functional
object Main {
def main(args: Array[String]) = {
def m3(x: Int) = x % 3 == 0
def m5(x: Int) = x % 5 == 0
val checks = List((m3 _, "Fizz"), (m5 _, "Buzz"))
Stream.from(1) map { n =>
checks filter (_._1(n)) map (_._2) reduceOption (_ + _) getOrElse n
} take 100 foreach println
@ramn
ramn / PropertyUsage.scala
Last active October 11, 2015 18:17
Properties files with Scala
import java.util.Properties
val in = getClass.getClassLoader.getResourceAsStream("config_values.properties")
// The Classloader is not always available (sbt test runner), then use the current class instead:
// val in = getClass.getResourceAsStream("config_values.properties")
val props = new Properties()
props.load(in)
in.close
props.getProperty("my.property.name", "default-value")
@ramn
ramn / netcat_over_ssh.sh
Created September 27, 2012 14:27
Send a file with netcat over ssh tunnel
### Sending a file
# BSD nc syntax
cat myDocument.pdf | ssh me.myserver.com nc -l 20000
# Hobbit nc syntax - try this one if unsure!
cat myDocument.pdf | ssh me.myserver.com nc -l -p 20000
### Receiving a file
nc me.myserver.com 20000 > myDocument.pdf
@ramn
ramn / watch_and_notify_emr.sh
Created September 21, 2012 12:21
Monitor Amazon EMR and send XMPP message on completion
#! /bin/bash
# A script that watches the running status of Amazon EMR jobs, sending an XMPP
# message upon completion.
#
# A destination jabber account, where the messages are sent, should be supplied
# either as the first argument at invocation or in the environment variable
# JABBER_ACCOUNT.
#
# Dependencies:
@ramn
ramn / cgi.rb
Created September 1, 2012 10:51 — forked from kek/gist:3153275
Writing a CGI script with templates. For PHP programmers
#!/usr/bin/ruby
require 'cgi'
require 'erb'
cgi = CGI.new('html')
template = <<TEMPLATE
<html>
<head>
@ramn
ramn / webrick_and_erb.rb
Created September 1, 2012 10:50
Simple ruby webserver
require 'webrick'
require 'erb'
template = <<TEMPLATE
<html>
<head>
<title>Ruby as PHP</title>
</head>
<body>
<h1>Loop</h1>
@ramn
ramn / gnuplot_examples.sh
Last active October 9, 2015 17:57
Gnuplot examples
# Create svg graph file
cat plotdata_raw | gnuplot -e "set terminal svg; plot '-' using 2:1 with lines" > my_graph.svg
# where plotdata_raw is a file with data, 2 columns separated by whitespace.
# using 2:1 means: use column 2 as x, column 1 as y axis
# with lines: draw a line graph
# Parse time
cat plotdata_raw | gnuplot -e "set xdata time; set timefmt '%s'; plot '-' using 2:1 with lines" -p
@ramn
ramn / cartesianProduct.js
Created July 13, 2012 08:22
Produce cartesian product of a list of lists (javascript)
// Lives at: https://gist.github.com/3103615/
function cartesianProduct(xss) {
if (!xss || xss.length < 1)
return [];
else {
var head = xss[0];
var tail = xss.slice(1);
var result = [];
for (var i = 0; i < head.length; i++) {
var productOfTail = cartesianProduct(tail);