Skip to content

Instantly share code, notes, and snippets.

View ramn's full-sized avatar

ramn ramn

View GitHub Profile
@ramn
ramn / calc_and_plot_durations_from_log_file.sh
Created July 21, 2014 08:15
Calc and plot durations from log file
#!/bin/bash
# Given a logfile with pairwise loglines when an event starts, and when it finishes,
# this script plots the duration for the events.
# Feed me a log file with rows like these:
# 2014-07-21 07:50:03,440 INFO Begin job
# 2014-07-21 07:52:50,530 INFO End job
# 2014-07-21 08:00:03,044 INFO Begin job
# 2014-07-21 08:02:02,548 INFO End job
@ramn
ramn / slugify.sh
Last active August 29, 2015 14:04
Slugify string
#!/bin/bash
rlwrap tr -d '\n\r' | tr -sc [:alnum:] '_' | tr [:upper:] [:lower:]
@ramn
ramn / png_from_dot_file.scala
Created November 3, 2014 21:52
Scala sys.process example, reading bytes back (create png from Dot)
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import scala.sys.process._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.concurrent.blocking
import scala.concurrent.Await
import scala.concurrent.duration._
@ramn
ramn / jdbc_connection_string_for_postgres.txt
Created June 26, 2015 14:23
JDBC connection string for Postgresql
jdbc:postgresql://<host>:<port>/<dbname>?user=<username>&password=<password>
@ramn
ramn / normalize_bookmarklet.js
Last active August 29, 2015 14:27
normalize bookmarklet
// Create a bookmarklet with the following line:
// javascript:(function(){document.body.appendChild(document.createElement('script')).src='https://gist.githubusercontent.com/ramn/fa7f13b736f872e6f506/raw/normalize_bookmarklet.js';})();
var s=document.body.style;
s.fontFamily='"Optima", "ubuntu light", "lucida grande", verdana';
s.background='#EEEEEE';
s.color='black';
for (i=0; i<document.links.length; i++) {
document.links[i].style.color='blue';
@ramn
ramn / delicious_post_bookmarklet.js
Created June 10, 2011 08:40
Delicious Save Bookmarklet, stripping utm_*
javascript:(function(){f='http://www.delicious.com/save?url='+encodeURIComponent(window.location.href.replace(/utm_source=[^&]+&?|utm_medium=[^&]+&?|utm_campaign=[^&]+&?|utm_content=[^&]+&?/g, "").replace(/[?&]+$/, ""))+'&title='+encodeURIComponent(document.title)+'&notes='+encodeURIComponent(''+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text))+'&v=6&';a=function(){if(!window.open(f+'noui=1&jump=doclose'))location.href=f+'jump=yes'};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()
@ramn
ramn / delicious_post_bookmarklet_original.js
Created June 12, 2011 00:04
Delicious Save Bookmarklet Original
javascript:(function(){f='http://www.delicious.com/save?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'&notes='+encodeURIComponent(''+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text))+'&v=6&';a=function(){if(!window.open(f+'noui=1&jump=doclose','deliciousuiv6','location=yes,links=no,scrollbars=no,toolbar=no,width=550,height=550'))location.href=f+'jump=yes'};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()
@ramn
ramn / print_delicious_rss_feed.scala
Created August 21, 2011 18:28
Print rss feed (Scala)
val feed = xml.XML.load(new java.net.URL("http://feeds.delicious.com/v2/rss/some_user/some_tag"))
for (item <- feed \\ "item") {
println(item \\ "title" text)
println(item \\ "link" text)
}
@ramn
ramn / simple_template.scala
Created September 12, 2011 20:09
Simple Template (Scala)
val varPattern = """\$\{([^}]*)}""".r
def template(text: String, vars: Map[String, String]) =
varPattern replaceSomeIn (text, m => vars get (m group 1))
@ramn
ramn / pinboard_save_bookmarklet.js
Created October 3, 2011 19:32
Pinboard save bookmarklet, stripping utm_*
javascript:(function(){q=location.href.replace(/utm_source=[^&]+&?|utm_medium=[^&]+&?|utm_campaign=[^&]+&?|utm_content=[^&]+&?/g, "").replace(/[?&]+$/, "");if(document.getSelection){d=document.getSelection();}else{d='';};p=document.title;full_url='https://pinboard.in/add?url='+encodeURIComponent(q)+'&description='+encodeURIComponent(d)+'&title='+encodeURIComponent(p); a=function(){if(!window.open(full_url))location.href=full_url};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})();