Skip to content

Instantly share code, notes, and snippets.

View ramn's full-sized avatar

ramn ramn

View GitHub Profile
@ramn
ramn / XmlSchemaValidator.scala
Created December 2, 2010 11:02
XML Schema validator in Scala
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.Schema
import javax.xml.validation.SchemaFactory
import javax.xml.validation.{Validator=>JValidator}
import org.xml.sax.SAXException
object Validator {
def main(args: Array[String]) {
require(args.size >= 2, "Params: xmlFile, xsdFile")
val result =
@ramn
ramn / emacs_uniq-lines.el
Created January 26, 2011 10:29
Emacs function that removes duplicate rows in a region
;; uniq-lines
;; ----------
;; This is something of a companion to the built-in sort-lines function.
;; Like the uniq utility, this removes duplicate lines from the region. It
;; is best used after sorting a region.
;;
(defun uniq-lines (start end)
"Removes duplicate lines from the selected region."
(interactive "*r")
(goto-char start)
@ramn
ramn / MinimalSoapServer.scala
Created February 4, 2011 11:06 — forked from kings13y/MinimalSoapServer.scala
Soap server in Scala
/*
CHANGELOG
- add annotation for param names
*/
import javax.jws.{WebService, WebParam}
import javax.jws.soap.SOAPBinding
import SOAPBinding.Style
import javax.xml.ws.Endpoint
@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 / shutdownHook.scala
Created August 21, 2011 23:14
Register ShutdownHook (Scala)
object ShutDown {
def main(args: Array[String]) {
sys.ShutdownHookThread {
println("exiting")
}
println("begin sleep")
Thread.sleep(5000L)
println("done sleeping")
@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()}})();
@ramn
ramn / autocompile.sh
Created November 21, 2011 14:41
autocompile: inotifywait loop that autocompiles using given command and file pattern
if [ -z $1 ] || [ -z $2 ]
then
echo "Usage: autocompile <compiler-command> <pattern>"
echo "Examaple: autocompile fsc *.scala"
exit
fi
while true
do
inotifywait -q -e modify,attrib --format='%w' --fromfile <( find . -iname "$2") | while read FILE