Skip to content

Instantly share code, notes, and snippets.

View loverdos's full-sized avatar

Christos KK Loverdos loverdos

View GitHub Profile
@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
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 / 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 =>
@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
trait TypeContainer {
type A
type B
type ABPlus
type C
}
trait TypeProjector[TC <: TypeContainer] {
type A = TC#A
type B = TC#B
#!/usr/bin/env python
from os.path import expanduser
from ConfigParser import ConfigParser
from sys import argv
kamakirc = "%s/.kamakirc" % expanduser("~")
cfg=ConfigParser()
cfg.read(kamakirc)
if(2 != args.length) {
System.err.println("Usage: change-path-element in-elem out-elem")
System.exit(1)
}
val In = args(0)
val Out = args(1)
//println("In = " + In)
//println("Out = " + Out)
import java.lang.System
import java.io.File
import java.util.regex.Pattern
val Path = System.getenv("PATH")
val PathSep = File.pathSeparator
val pathFolders = Path.split(PathSep).toList.map(new File(_)).filter { file =>
if(file.isDirectory) {
(if(args.isEmpty) Array("build.xml") else args) foreach { file =>
try {
print(file + ": ")
println(scala.xml.XML.loadFile(file) \ "target" map (target => target \ "@name") filter (!_.isEmpty) mkString ", ")
} catch {
case e => println(e.getClass + ": " + e.getMessage)
}
}
$ curl -I http://www.gsis.gr/diagonismos_ELLAK.html
HTTP/1.0 404 Not Found
Date: Fri, 19 Mar 2010 17:34:11 GMT
Server: Apache
Last-Modified: Thu, 14 Apr 2005 10:53:27 GMT
ETag: "2ebe1-34cc-55dcf7c0"
Accept-Ranges: bytes
Content-Length: 13516
Content-Type: text/html; charset=ISO-8859-7