Skip to content

Instantly share code, notes, and snippets.

@zentrope
zentrope / transform.scala
Created December 4, 2010 08:23
Transforming XML using RewriteRule and RuleTransformer
// Import the magic libraries
import scala.xml._
import scala.xml.transform._
// Source xml. In Scala, xml is literal.
val xml =
<user>
<email>joe@example.com</email>
@RiANOl
RiANOl / gist:1077760
Last active April 13, 2024 06:17
AES128 / AES256 CBC with PKCS7Padding in Ruby
require "openssl"
require "digest"
def aes128_cbc_encrypt(key, data, iv)
key = Digest::MD5.digest(key) if(key.kind_of?(String) && 16 != key.bytesize)
iv = Digest::MD5.digest(iv) if(iv.kind_of?(String) && 16 != iv.bytesize)
aes = OpenSSL::Cipher.new('AES-128-CBC')
aes.encrypt
aes.key = key
aes.iv = iv
@jpoehls
jpoehls / node-cluster-messaging.js
Created March 29, 2012 01:48
Simple message passing between cluster master and workers in Node.js
var cluster = require('cluster');
if (cluster.isWorker) {
console.log('Worker ' + process.pid + ' has started.');
// Send message to master process.
process.send({msgFromWorker: 'This is from worker ' + process.pid + '.'})
// Receive messages from the master process.
@edeustace
edeustace / download_zip.ps1
Created May 15, 2012 08:47
powershell script to download zip and copy items from the zip to locations on destination file
# copy items
# if you have a zip here: http://myserver.com/my.zip and it contains myFile.txt and myFolder/myOtherFile.txt
# you can call this script like so:
# .\download_zip.ps1 http://myserver.com/my.zip "myFile.txt|c:\myFileDestination\myFileHere.txt" "myFolder/myOtherFile.txt|c:\myOtherDestination\myOtherFile.txt"
#
"download script -----------------------------------------"
"------"
"Downloads from the given url, unzips it then for each string arg, copies the file to the destination"
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active June 8, 2024 17:28
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@puffnfresh
puffnfresh / currying.js
Created September 7, 2012 07:13
Support for both curried and uncurried application in functional JavaScript
function curry(f) {
return function(x) {
var g = f.bind(this, x);
if(g.length == 0) return g();
if(arguments.length > 1) return curry(g).apply(this, [].slice.call(arguments, 1));
return curry(g);
};
}
var sum = curry(function(x, y) {
@uarun
uarun / scalac-options.md
Last active December 9, 2015 20:39
Useful scalac options (for scala 2.10)

Useful Scalac Options

-encoding "UTF-8"

-target:jvm-1.6

Uses the ASM Compiler backend to generate bytecode (Scala 2.10)

-deprecation

@nevang
nevang / JsBSONHandlers.scala
Last active March 8, 2016 22:29
Reader and writer in order to work with spray-json and reactivemongo. Based on https://github.com/zenexity/Play-ReactiveMongo.
import spray.json._
import reactivemongo.bson._
import reactivemongo.bson.handlers.{ BSONReader, BSONWriter, RawBSONWriter }
import scala.util.{ Try, Success, Failure }
import org.apache.commons.codec.binary.Hex
import org.joda.time.format.ISODateTimeFormat
import org.joda.time.{ DateTime, DateTimeZone }
import java.nio.ByteBuffer
import org.jboss.netty.buffer.ChannelBuffers
@doitian
doitian / MongoJson.scala
Created May 10, 2013 15:12
Convert play2.0 JsValue to mongodb DBObject provided by casbah
package module.db;
import com.mongodb.casbah.Imports._
import java.text.DateFormat
import java.util.Date
import play.api.data.validation.ValidationError
import play.api.libs.json._
object MongoJson {
def fromJson(json: JsValue) : JsResult[DBObject] = readDBObject.reads(json)
@leon
leon / Grunt.scala
Last active September 3, 2016 02:23
Playframework 2.2 Grunt Runner
import sbt._
import Keys._
import java.net._
import java.io.File
import play.PlayRunHook
/*
Grunt runner should be in project directory to be picked up by sbt
*/
object Grunt {