Skip to content

Instantly share code, notes, and snippets.

View loverdos's full-sized avatar

Christos KK Loverdos loverdos

View GitHub Profile
@loverdos
loverdos / mvn-project-version.sh
Created May 20, 2015 10:07
Get maven project version from the shell
mvn help:evaluate -Dexpression=project.version | grep -e '^[^\[]'
trait TypeContainer {
type A
type B
type ABPlus
type C
}
trait TypeProjector[TC <: TypeContainer] {
type A = TC#A
type B = TC#B
@loverdos
loverdos / jvm-crasher.scala
Created December 30, 2014 09:10
JVM crasher
{ val u = classOf[sun.misc.Unsafe].getDeclaredField("theUnsafe")
u.setAccessible(true)
u.get(null).asInstanceOf[sun.misc.Unsafe]
} freeMemory 1024
@loverdos
loverdos / enhanced-match.scala
Created October 14, 2014 10:50
Enhanced Scala match with exception handling
// Inspired by latest OCaml
eval() match {
case v1 =>
case v2 =>
case _ =>
case catch e: Exception =>
case catch _ =>
case finally =>
implicit class GoodLord(val Good: Int) extends AnyVal {
def Lord = Good
}
// and then in a Scala prompt:
// scala> 1.Good.Lord
// res0: Int = 1
// Also:
// scala> 1.Good.Lord.Good.Lord.Good.Lord
@loverdos
loverdos / gist:e8bc5d264dc1524f011a
Created April 30, 2014 14:38
Enable mosh ports on a server
iptables -I INPUT 1 -p udp --dport 60000:61000 -j ACCEPT
service iptables save
git log --since=2012-10-01 --until=2012-10-31 --author=loverdos --reverse --pretty=format:"%H%x09%ae%x09%ad%x09%s" --date=short
@loverdos
loverdos / pipe.ml
Last active December 18, 2015 03:59
external (|>) : 'a -> ('a -> 'b) -> 'b = "%revapply"
@loverdos
loverdos / gist:5584254
Created May 15, 2013 14:10
Recursive file path construction of a single user for Old Pithos filesystem. PostgreSQL 8.4
-- All files (and the folders they belong to) recursively
with recursive q as (
select folder,
1 as level,
'' || folder.name as folder_path,
'' || folder.name || '/' || file.name as file_path,
folder.id as folder_id,
folder.parent_id as parent_folder_id,
file.id as file_id
from folder,
@loverdos
loverdos / par-port-scanner.scala
Created April 2, 2013 09:50
Parallel port scanner in Scala
// Parallel port scanner using parallel collections (just for the side-effect)
// @author = @loverdos
(1 to 65536).par.map { case port ⇒
try {
val socket = new java.net.Socket("127.0.0.1", port)
socket.close()
println(port)
port
} catch {