Skip to content

Instantly share code, notes, and snippets.

@scotttam
scotttam / Decrypter.java
Created March 17, 2011 14:37
encrypt and decrypt with PBKDF2/SHA1 and AES
import javax.crypto.Cipher;
import java.security.spec.KeySpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.SecretKeyFactory;
import java.security.AlgorithmParameters;
import javax.crypto.spec.IvParameterSpec;
public class Decrypter {
@rednaxelafx
rednaxelafx / demo.groovy
Created April 6, 2011 08:51
get properties from an object in Groovy, even when the object has an getProperties() method
def getPropertiesFrom(obj) {
obj.metaClass.properties.findAll { it.name != 'class' && it.name != 'metaClass' }.inject([:]) { acc, e -> acc[e.name] = e.getProperty(obj); acc }
}
class Foo {
int getBar() { 42; }
List getProperties() { [] }
}
def foo = new Foo();
foo.properties; //=> []
@takumakei
takumakei / JSONEntity.java
Created April 11, 2011 04:53
An utility class to POST json(optionally gzipped) with Apache HttpClient.
/* JSONEntity.java
* An utility class to POST json(optionally gzipped) with Apache HttpClient.
*
* Copyright (C) 2011 TAKUMAKei
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@nissuk
nissuk / gist:922817
Created April 16, 2011 02:58
MySQL: ストアドプロシージャでINSERTする例 (+ 定義名→内部IDの変換)
-- ユーザーを追加するストアドプロシージャを定義します。
-- 氏名と性別名('male', 'female')を入力し、
-- プロシージャ内部で性別名から性別idを引き出して追加します。
DROP PROCEDURE IF EXISTS insert_user;
DELIMITER $$
CREATE PROCEDURE insert_user(IN name TEXT, IN gender_name TEXT)
COMMENT "ユーザーを追加します。"
BEGIN
-- カーソルの値を受け取る変数とカーソルを定義します。
@atbradley
atbradley / stripTags.groovy
Created April 28, 2011 14:22
Very simplistically remove HTML tags from strings.
public static String stripTags(String input) {
return input.replaceAll("\\<.*?>","");
}
@raulbajales
raulbajales / CompareMD5AndMurmur.java
Created May 2, 2011 14:51
MD5 and Murmur hashing algorithms performance comparison -> Murmur WIN
package com.hashcomparisons;
import java.security.MessageDigest;
import java.util.Random;
import org.apache.commons.lang.RandomStringUtils;
public class CompareMD5AndMurmur {
public static void main(String[] args) {
String[] strings = generateRandomStrings(300, 50, 500);
@jordansissel
jordansissel / Why JRuby.md
Created May 18, 2011 16:38
logstash, why jruby?

Long story, short: I'm totally open to supporting more rubies if possible. Details follow.

Related issue: http://code.google.com/p/logstash/issues/detail?id=37

Summary:

  • core and stdlib ruby changes violently and without notice and without backwards compatibility. I want nothing of that.
  • need a cross-ruby date library that isn't part of stdlib (see previous point) and is also good.
  • need an easy way to use multiple cpus that is cross-ruby (threads are not it)
// cf. http://www.ne.jp/asahi/hishidama/home/tech/java/swing/DropTarget.html
import groovy.swing.SwingBuilder
import javax.swing.JFrame
import java.awt.dnd.DropTarget
import java.awt.dnd.DnDConstants
import java.awt.datatransfer.DataFlavor
import java.awt.datatransfer.Transferable
def swing = new SwingBuilder()
@marharrUK
marharrUK / Asset.java
Created July 21, 2011 09:30
Serializing an ArrayList using the Simple Framework for XML
package com.softsols.xmltest;
import org.simpleframework.xml.Default;
import org.simpleframework.xml.Root;
@Default
@Root(name="Job")
public class Job extends MessageType {
private String jobCode;
private String assetCode;
@jcasimir
jcasimir / filters.markdown
Created July 22, 2011 18:14
Controller Filters

Controller Filters

The Rails REST implementation dictates the default seven actions for your controllers, but frequently we want to share functionality across multiple actions or even across controllers. Controller filters are the easiest way to do that.

Before, After, and Around

There are three types of filters implemented in Rails:

  • a before_filter runs before the controller action
  • an after_filter runs after the controller action