Skip to content

Instantly share code, notes, and snippets.

View ramn's full-sized avatar

ramn ramn

View GitHub Profile
@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 / 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 / scala_as_script.bash
Created April 10, 2015 15:14
Scala as script (shebang header)
#!/bin/bash
CP="$(find $HOME/.ivy2 -path '*myorg/*util_2.11-*.jar' | tail -1)"
exec scala -savecompiled -cp "$CP" $0 $@
!#
import com.myorg.MyClass
io.Source.stdin
.getLines
.map { line =>
@ramn
ramn / socat_http_echo_server.sh
Last active September 26, 2023 12:22
Socat HTTP echo server
#!/bin/bash
socat -v -T0.05 tcp-l:8081,reuseaddr,fork system:"echo 'HTTP/1.1 200 OK'; echo 'Connection: close'; echo; cat"
@ramn
ramn / backup_all_gists_for_a_user.sh
Last active July 21, 2023 13:46
Backup all Gists
#!/bin/bash
# Depends on git, curl, jq
BAK_DIR=$(date +"%y%m%d-%H%M")
GISTS_URL="https://api.github.com/users/$USER/gists?per_page=1000&access_token=$GITHUB_ACCESS_TOKEN"
mkdir "$BAK_DIR" && cd "$BAK_DIR" && curl -s "$GISTS_URL" | jq ".[] | .git_pull_url" | xargs -n1 git clone
@ramn
ramn / DerbyDbExample.scala
Created March 16, 2015 23:30
Start / connect to Derby example
// scala -cp $HOME/lib/derby-10.11.1.1.jar:$HOME/lib/derbyclient-10.11.1.1.jar:$HOME/lib/derbynet-10.11.1.1.jar
import org.apache.derby.drda.NetworkServerControl
import java.net.InetAddress
import java.sql.DriverManager
val server = new NetworkServerControl(InetAddress.getByName("localhost"),1527)
server.start(new java.io.PrintWriter(Console.out)) // here we direct logging to stdout
// To create and connect to a db in the same jvm:
@ramn
ramn / GetUnsafeClass.scala
Created November 20, 2014 22:02
sun.misc.Unsafe use in Scala
def getUnsafeInstance: sun.misc.Unsafe = {
val f = classOf[sun.misc.Unsafe].getDeclaredField("theUnsafe")
f.setAccessible(true)
val unsafe = f.get(null).asInstanceOf[sun.misc.Unsafe]
unsafe
}
@ramn
ramn / serve_file_over_http.sh
Last active May 19, 2023 14:25
Serve file over HTTP with Socat
#!/bin/bash
FILE="$1"
PORT=${PORT:-9999}
MIME_TYPE=$(mimetype "$FILE")
SIZE_BYTES=$(du -b "$FILE" | cut -f1)
FILE_NAME=$(basename "$FILE")
HEADER="\
HTTP/1.1 200 OK
@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 / slugify.sh
Last active August 29, 2015 14:04
Slugify string
#!/bin/bash
rlwrap tr -d '\n\r' | tr -sc [:alnum:] '_' | tr [:upper:] [:lower:]