Skip to content

Instantly share code, notes, and snippets.

@mookerji
mookerji / YCMemoizer.java
Created October 8, 2013 23:02
Issue of the day: If you're using purely Java (or heaven forbid, C++), how do you *generically* memoize/cache values for functions that make recursive function calls? Reflection or runtime-method dispatch is probably pretty messy. It seems an actual Y-Combinator is *great* for this.
package memoizer;
import memoizer.ConcurrentLRUCache;
class YCMemoizer {
interface F<R, A> {
R apply(A n);
}
interface F_F<R, A> {
@mookerji
mookerji / ConcurrentLRUCache.java
Created October 10, 2013 17:13
Concurrent write-order FIFO for caching: The cache uses a ConcurrentHashMap and a ConcurrentLinkedQueue; and atomic integers for timestamping accesses, writes, and the queue size. The map maintains the cached values, and the queue maintains an ordering of the elements in write-FIFO order. ConcurrentLRUCaches eschews locks in favor of lock-free d…
package memoizer;
import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicLong;
public class ConcurrentLRUCache {
private final int kCacheSize;
private final ConcurrentHashMap<Object, CachedValue> mMap;
; .emacs file
; Bhaskar Mookerji
;
; Started: Sunday, 3 October 2010
;;;
;;; Static configuration stuff
;;;
(winner-mode 1)
@mookerji
mookerji / rocksdb.clj
Last active March 5, 2020 10:12
Idiomatic Clojure bindings for the C++ RocksDB library, an embedded persistent key-value store for flash storage and server workloads based on LevelDB. This implementation is based partially on Factual's clj-leveldb and is up here for some early review. If I've shared it with you, please don't repost until merged into a public Github.
(ns org.flausenhaus.rocksdb
"Idiomatic Clojure bindings for the C++ RocksDB library, an embedded
persistent key-value store for flash storage and server workloads based on
LevelDB. More details about RocksDB are given at
https://github.com/facebook/rocksdb/wiki/Rocksdb-Architecture-Guide.
The implementation here borrows heavily from Factual's clj-leveldb.
This namespace provides a few things:
0. Protocols/type definitions: byte serialization (IByteSerializable),
closeable sequences (CloseableSeq), and mutable
### Keybase proof
I hereby claim:
* I am mookerji on github.
* I am mookerji (https://keybase.io/mookerji) on keybase.
* I have a public key whose fingerprint is E277 702B 9088 47A1 2228 5D2B A056 FAB1 7C28 EE91
To claim this, I am signing this object:
@mookerji
mookerji / extras_swift.i
Created May 4, 2015 17:22
Python C extensions
%typemap(in) float value[ANY] (float temp[$1_dim0]) {
int i;
if (!PySequence_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a sequence");
return NULL;
}
if (PySequence_Length($input) != $1_dim0) {
PyErr_SetString(PyExc_ValueError,"Size mismatch. Expected $1_dim0 elements");
return NULL;
}
function generateDish() {
var ADJ_PROB = 0.5;
var STRUCTURE_PROB = 0.5;
var adjs = ["chilled", "fried", "smoked", "brined", "cultured", "farmer's", "pressed", "cured", "charred", "dill", "sweet", "corned", "kefir", "paprika", "pickled", "truffled", "black", "rye", "sour cream", "preserved", "burnt", "seeded", "dried"];
var ingredients = ["cabbage", "chicken", "tongue", "cheese", "liver", "sturgeon", "chard", "tuna", "beef", "radish", "mushroom", "trout", "carrot", "yoghurt", "lard", "bone marrow", "tripe", "bottarga", "egg", "catfish", "ramp", "tendon", "greens", "fennel", "chicories", "bonito", "potato", "garlic", "mussel", "nettle", "herring", "sardine", "walnut", "plum"];
var structures = ["croquettes", "melt", "stew", "soup", "slab", "bread", "butter", "pickles", "dip", "dumplings", "broth", "tartare", "loin", "crackers", "cake", "steak", "flatbread", "toast"];
var dish = "";
if (_.random(0, 100) < ADJ_PROB * 100) {
dish += _.sample(adjs) + " ";
}
@mookerji
mookerji / quickcheck-file.hs
Last active December 17, 2015 05:04
Environmental fails
import Test.QuickCheck
import Test.QuickCheck.Instances.Maybe
import Test.QuickCheck.Monadic
instance Arbitrary LogLevel where
arbitrary = do
n <- choose (0, 4) :: Gen Int
return $ case n of
0 -> LevelDebug
1 -> LevelInfo
@mookerji
mookerji / async.py
Created February 25, 2017 01:09
ZMQ piksi client
# Copyright (C) 2015 Swift Navigation Inc.
# Contact: Engineering <engineering@swiftnav.com>
#
# This source is subject to the license found in the file 'LICENSE' which must
# be be distributed together with this source. All other rights reserved.
#
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
GST - GNSS Pseudorange Error Statistics
1 2 3 4 5 6 7 8
| | | | | | | |
$--GST,hhmmss.ss,x.x,x.x,x.x,x.x,x.x,x.x,x.x*hh<CR><LF>
1. UTC time of the GGA or GNS fix associated with this sentence.
2. RMS value of the standard deviation of the range inputs to
the navigation process. Range inputs include pseudoranges &
DGNSS corrections.
3. Standard deviation of semi-major axis of error ellipse (meters)
4. Standard deviation of semi-minor axis of error ellipse (meters)