Skip to content

Instantly share code, notes, and snippets.

View terkhorn's full-sized avatar

Felix Terkhorn terkhorn

View GitHub Profile
@jneira
jneira / express-sample.cljs
Created August 25, 2011 20:07
Clojurescript / node.js basic examples
(ns express_sample
(:require [cljs.nodejs :as node]))
(def express (node/require "express"))
(def app (. express (createServer)))
(defn -main [& args]
(doto app
(.use (. express (logger)))
(.get "/" (fn [req res]
@opyate
opyate / ConsistentHash.scala
Last active July 18, 2022 06:33
Consistent Hashing in Scala
// scalac -unchecked -optimise ConsistentHash.scala && scala CHApp
import scala.collection.immutable.LinearSeq
import java.util.{TreeMap => JTreeMap}
import java.util.{SortedMap => JSortedMap}
/**
* Inspired by http://www.lexemetech.com/2007/11/consistent-hashing.html
*/
@catawbasam
catawbasam / pandas_dbms.py
Last active May 26, 2024 05:32
Python PANDAS : load and save Dataframes to sqlite, MySQL, Oracle, Postgres
# -*- coding: utf-8 -*-
"""
LICENSE: BSD (same as pandas)
example use of pandas with oracle mysql postgresql sqlite
- updated 9/18/2012 with better column name handling; couple of bug fixes.
- used ~20 times for various ETL jobs. Mostly MySQL, but some Oracle.
to do:
save/restore index (how to check table existence? just do select count(*)?),
finish odbc,
@subelsky
subelsky / casperjs_example.js
Created August 8, 2012 18:51
Webscraping with CasperJS, PhantomJS, jQuery, and XPath
var system = require('system');
if (system.args.length < 5) {
console.info("You need to pass in account name, username, password, and path to casperJS as arguments to this code.");
phantom.exit();
}
var account = system.args[1];
var username = system.args[2];
var password = system.args[3];
@shmert
shmert / ASCII.java
Created October 9, 2012 14:31
Convert images to ASCII text
package ascii;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
/*Copyright (c) 2011 Aravind Rao
@dragisak
dragisak / DateTimeMapper.scala
Created February 11, 2013 18:17
Joda DateTime mapper in Slick
import slick.lifted.MappedTypeMapper
import java.sql.Date
import org.joda.time.DateTime
import slick.lifted.TypeMapper.DateTypeMapper
object DateTimeMapper {
implicit def date2dateTime = MappedTypeMapper.base[DateTime, Date] (
dateTime => new Date(dateTime.getMillis),
date => new DateTime(date)
@nathanaschbacher
nathanaschbacher / Versioning, Soft Delete, and Restore.md
Last active December 14, 2015 07:39
One simple example of an implementation for a transaction/audit journal and restoring lost/deleted objects for a known key.

##Driver

Customers often request “versioning” or “restore/undo” functionality, as a means of data recovery from user error (as opposed to recovery from hardware failure or data loss errors, at which Riak already excels). If an object is changed or deleted by the end user, but later needs to be restored, is there a way to either look at a transaction log to undo the damage, or to explicitly restore the object to a previous version?

##Overview

This solution provides one simple example of an implementation for a transaction/audit journal and restoring lost/deleted objects for a known key. A separate global transaction/audit journal could also be built to provide an index to get an object key in the case where you don't know it beforehand, but that use case is outside the scope of this document.

The algorithm used here depends only on Riak's key/value functionality for two reasons. First, to show that a solution to the problem can be simply and efficiently implemented with a key/value pattern. Second, relyin

@seanparsons
seanparsons / KleisliEnhance.scala
Created July 31, 2013 16:35
Automatic tuple conversion powered by macros.
package myproject.util
import myproject.macros._
import scalaz._,Scalaz._,Kleisli._
object KleisliEnhance {
implicit class KleisliEnhancer[M[+_]: Monad, A, B](kleisli: Kleisli[M, A, B]) {
def localFrom[AA]: Kleisli[M, AA, B] = kleisli.local(TupleTransformer.tupleToFrom[A, AA]
}
}