Skip to content

Instantly share code, notes, and snippets.

View ramn's full-sized avatar

ramn ramn

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / S3ObjectUtil.scala
Last active December 11, 2015 15:18
S3 utils in Scala, for listing and fetching S3 objects.
/*
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@ramn
ramn / FuturesWithFixedThreadPool.scala
Last active February 19, 2016 09:21
Futures with fixed thread pool
import java.util.concurrent.Executors
import concurrent.ExecutionContext
import concurrent.Future
import concurrent.Await
import scala.concurrent.duration._
implicit val executionContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(2))
Await.ready(Future { println("sdf") }, 3.seconds)
@ramn
ramn / watch_bitcoin_last_price.sh
Created March 26, 2013 10:26
Watch Bitcoin last price (shell)
CMD='last=JSON.load(ARGF.read)["data"]["last"]["display"]; puts "#{Time.now}: #{last}"'; watch "curl https://data.mtgox.com/api/2/BTCUSD/money/ticker 2>/dev/null | ruby -r json -e '$CMD'"
@ramn
ramn / irc_from_bash.sh
Last active May 10, 2017 16:46
IRC client in Bash
# Communicate with an IRC channel from the shell
#
# Runs in background, writes messages to stdout in tty
# Depends on sic
TMPF=ircsession.tmp; CHAN='#testircfrombash'; ME=bot001; cat /dev/null > $TMPF; (tail -f $TMPF | sic -h irc.freenode.net -p 6667 -n $ME | while read MSG; do case "$MSG" in "$ME"*) echo ":j $CHAN" >> $TMPF;; "$CHAN"*) echo "$MSG";; esac; done;) &
# Then, to write to the channel:
echo "Hello all!" >> $TMPF
# or open a buffer to write many rows: