This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Pool | |
from functools import partial | |
def _pickle_method(method): | |
func_name = method.im_func.__name__ | |
obj = method.im_self | |
cls = method.im_class | |
if func_name.startswith('__') and not func_name.endswith('__'): #deal with mangled names | |
cls_name = cls.__name__.lstrip('_') | |
func_name = '_' + cls_name + func_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.RandomAccessFile; | |
import java.lang.reflect.Field; | |
import java.lang.reflect.Method; | |
import java.nio.channels.FileChannel; | |
import sun.nio.ch.FileChannelImpl; | |
import sun.misc.Unsafe; | |
@SuppressWarnings("restriction") | |
public class MMapper { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"runtime" | |
"sync" | |
) | |
type UpgradableLock struct { | |
uglMutex sync.RWMutex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(comment Add [org.clojure/java.jdbc "0.1.1"] to project dependencies) | |
(ns myproject.core | |
(:use [clojure.java.jdbc :only [with-connection, with-query-results]])) | |
(let [db-host "MyHost" | |
db-port 10000 | |
db-name "default"] | |
(def db {:classname "org.apache.hadoop.hive.jdbc.HiveDriver" ; must be in classpath | |
:subname (str "//" db-host ":" db-port "/" db-name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
OpenCL code for a geospatial recommender. The underlying algorithm is: | |
- Each user has a set of XY points | |
- Similarity between user A and user B is defined as the inverse mean minimum distance to each of user A's points, from any of user B's points. This is not symmetric. E.g., if user A has points at (0,0) and (10,10), and user B has a point at (4,4), similarity of B to A will be 1 / ((sqrt(4^2 + 4^2) + sqrt(6^2 + 6^2)) / 2), and similarity of A to B will be 1 / (sqrt(4^2 + 4^2)). It is possible to define other similarity measures along the same lines (e.g. inverse mean minimum squared distance) that will give different results. We're all about the heuristics. | |
- For evaluating the predicted strength at a new XY location for a given main user, | |
- Calculate an inverse-square dropoff from every point (as if one was calculating gravity in an N-body simulation). Again, one could use some other exponent with better empirical foundation. This can be optimized by excluding points beyond a certa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns myproject.core | |
(:use compojure.core) | |
(:require [compojure.route :as route] | |
[compojure.handler :as handler] | |
[ring.adapter.jetty :as ring-jetty]) | |
(:gen-class)) | |
(defroutes my-routes | |
(GET "/" [] "<h1>Hello World</h1>") | |
(route/not-found "<h1>Page not found</h1>")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
import java.util.concurrent.atomic.AtomicIntegerArray; | |
public class RandomElementProvider { | |
//Flag value - not valid as an element of the backing array. | |
public static final int INVALID = Integer.MIN_VALUE; | |
//After this many failed random selections, devolve to a scan. | |
//Corresponds to being able to handle on average (1 - 1/RETRY_THRESHOLD) of elements | |
//being selected already before scanning | |
public static final int RETRY_THRESHOLD = 4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro hinttype | |
[type-name & hint-symbols] | |
`(deftype ~type-name | |
[~@(for [s hint-symbols] | |
(with-meta (gensym "a") | |
{:tag (case s | |
:int 'int | |
:long 'long | |
:float 'float | |
:double 'double |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A simpler method than reflection-based traversal, using Unsafe | |
public static Unsafe getUnsafe() { | |
Field f = Unsafe.class.getDeclaredField("theUnsafe"); | |
f.setAccessible(true); | |
return (Unsafe) f.get(null); | |
} | |
public static long sizeOf(Object o) { | |
Unsafe u = getUnsafe(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.security.InvalidAlgorithmParameterException; | |
import java.security.InvalidKeyException; | |
import java.security.NoSuchAlgorithmException; | |
import java.security.SecureRandom; | |
import java.security.spec.InvalidKeySpecException; | |
import java.security.spec.KeySpec; |
NewerOlder