Skip to content

Instantly share code, notes, and snippets.

package models
import java.util.{Date}
import play.db.sql._
import play.db.sql.SqlParser._
// User
case class User(id: Pk[Long],
@timothyklim
timothyklim / ip.scala
Created August 3, 2012 21:34
IP to long and reverse on Scala
import collection.mutable.ListBuffer
object NetworkUtils {
def ip2Long(ip: String): Long = {
val atoms: Array[Long] = ip.split("\\.").map(java.lang.Long.parseLong(_))
val result: Long = (3 to 0 by -1).foldLeft(0L)(
(result, position) => result | (atoms(3 - position) << position * 8))
result & 0xFFFFFFFF
}
@timothyklim
timothyklim / cookie_jar_fix.gemspec
Created August 29, 2012 09:32 — forked from jodosha/cookie_jar_fix.gemspec
Support cookie jar options for all cookie stores
@timothyklim
timothyklim / gist:3539522
Created August 30, 2012 20:04
meta tags
<meta property="og:site_name" content="Boomstarter" />
<meta property="fb:app_id" content="423149071041361"/>
<meta property="twitter:site:id" content="boomstarterru"/>
<meta property="vk:app_id" content="2998311" />
<meta name="video_height" content="420"/>
<meta name="video_width" content="560"/>
@timothyklim
timothyklim / package.json
Created October 22, 2012 06:36
Stream live web cam video using Node.js and Gstreamer
{
"name": "streamingtest",
"version": "0.0.1",
"engines": {
"node": ">=0.6.0"
},
"dependencies": {
"express": "2.5.x",
"coffee-script": "1.2.x"
},
@timothyklim
timothyklim / run.sql
Created November 5, 2012 13:27
PLV8 base52 implementation
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE EXTENSION IF NOT EXISTS plv8;
DROP FUNCTION IF EXISTS to_base52(digit_number bigint);
DROP FUNCTION IF EXISTS to_base52(digit_number text, base integer);
CREATE FUNCTION to_base52(digit_number bigint) RETURNS text AS
$$
var codeset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
var base = codeset.length
tr ng-repeat="chunksetsBuf in splitChunksetsArray[for_id]"
td.group ng-repeat="(index, col) in chunksetsBuf"
@timothyklim
timothyklim / awesome_ad.rb
Created December 3, 2012 13:35
Rails and PostgreSQL inheritance
class AwesomeAd < ActiveRecord::Base;end
@timothyklim
timothyklim / asynchbase.scala
Created December 5, 2012 15:16 — forked from groundwater/asynchbase.scala
Demo Adapting asynchbase to Scala
package ca.underflow.hbase
import org.hbase.async._
import com.stumbleupon.async._
object Demo extends App {
// This let's us pass inline functions to the deferred
// object returned by most asynchbase methods
@timothyklim
timothyklim / aggregate_hstore_with_plv8.sql
Last active October 13, 2015 19:30
Aggregate hstore column in PostgreSQL 9.2 with PLV8
DROP FUNCTION IF EXISTS hstore_from_agg(hstores hstore[]);
CREATE FUNCTION hstore_from_agg(hstores hstore[]) RETURNS hstore AS
$$
var result = {}
hstores.forEach(function (sHash) {
sHash.split(/,\s*/).forEach(function(expression) {
var parsedValues = expression.match(/"(\d+)"=>"(\d+)"/),
key = parsedValues[1],