Skip to content

Instantly share code, notes, and snippets.

@viksit
viksit / clojure-font-lock-setup.el
Created April 1, 2010 21:23 — forked from michalmarczyk/clojure-font-lock-setup.el
Integrating clojure-mode indentation and colors into slime
;;; all code in this function lifted from the clojure-mode function
;;; from clojure-mode.el
(defun clojure-font-lock-setup ()
(interactive)
(set (make-local-variable 'lisp-indent-function)
'clojure-indent-function)
(set (make-local-variable 'lisp-doc-string-elt-property)
'clojure-doc-string-elt)
(set (make-local-variable 'font-lock-multiline) t)
(def bt {:left {:value 3}
:value 5
:right {:left {:value 2}
:value :foo
:right {:left {:value :bar}
:value :quux
:right {:value 10}}}})
(loop [bt bt
q (clojure.lang.PersistentQueue/EMPTY)]
(defn level-order [f tree]
(loop [to-do [tree]]
(if (empty? to-do)
:done
(do (dorun (map (comp f :value) to-do))
(recur (mapcat (fn [{:keys [left right]}] (remove nil? [left right]))
to-do))))))
(level-order println
{:value 1

Setting up Flume NG, listening to syslog over UDP, with an S3 Sink

My goal was to set up Flume on my web instances, and write all events into s3, so I could easily use other tools like Amazon Elastic Map Reduce, and Amazon Red Shift.

I didn't want to have to deal with log rotation myself, so I setup Flume to read from a syslog UDP source. In this case, Flume NG acts as a syslog server, so as long as Flume is running, my web application can simply write to it in syslog format on the specified port. Most languages have plugins for this.

At the time of this writing, I've been able to get Flume NG up and running on 3 ec2 instances, and all writing to the same bucket.

Install Flume NG on instances

@viksit
viksit / latency.txt
Created January 28, 2014 00:37 — forked from jboner/latency.txt
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
(ns ncdoffice.macros
(:require [clojure.java.io :as io])
(:require [kioo.core :as kioo])
(:require [kioo.om :refer [deftemplate]]))
(defmacro filecomponent [path transforms]
(let [file (io/file (str "build/client/" path))]
`(kioo/component ~file ~transforms)
))
@viksit
viksit / seq2seqRNN.py
Last active March 21, 2022 15:10
Simple Keras recurrent neural network skeleton for sequence-to-sequence mapping
__author__ = 'Conan'
import numpy as np
import random
from keras.models import Sequential
from keras.layers.recurrent import SimpleRNN
# Toy dictionary of 1000 indices to random length 10 vectors
@viksit
viksit / min-char-rnn.py
Last active September 11, 2015 20:58 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@viksit
viksit / theano_word_embeddings.py
Created December 5, 2015 02:30 — forked from matpalm/theano_word_embeddings.py
trivial word embeddings eg
#!/usr/bin/env python
# see http://matpalm.com/blog/2015/03/28/theano_word_embeddings/
import theano
import theano.tensor as T
import numpy as np
import random
E = np.asarray(np.random.randn(6, 2), dtype='float32')
t_E = theano.shared(E)
t_idxs = T.ivector()
@viksit
viksit / async_flask.py
Created March 28, 2016 20:01 — forked from sergray/async_flask.py
Asynchronous requests in Flask with gevent
"""Asynchronous requests in Flask with gevent"""
from time import time
from flask import Flask, Response
from gevent.pywsgi import WSGIServer
from gevent import monkey
import requests