Skip to content

Instantly share code, notes, and snippets.

View vishaltelangre's full-sized avatar

Vishal Telangre vishaltelangre

View GitHub Profile
@vishaltelangre
vishaltelangre / serveHTTPInterfaceExample.go
Created May 24, 2014 19:03
implementing #ServeHTTP method of #Handler #interface #go #Go
package main
import (
"fmt"
"net/http"
)
type String string
type Struct struct {
@vishaltelangre
vishaltelangre / route_dsl.rb
Created August 28, 2014 13:47
example of building DSL off blocks in Ruby
class RouteBase
@@routes = {}
def self.routes=r
@@routes = r
end
def self.routes
@@routes
end
@vishaltelangre
vishaltelangre / mongo-schema-notes.md
Last active August 29, 2015 14:06
Notes on modelling data schema in MongoDB #mongo

Main choices for structuring the data are:

  • For "one-to-few", you can use an array of embedded documents
  • For "one-to-many?, or on occasions when the "N" side must stand alone, you should use an array of references. You can also use a "parent-reference" in the "N" side if it optimizes your data access pattern.
  • For "one-to-squillions", you should use a "parent-reference" in the document storing the "N" side.

Once you've decided on the overall structure of the data, then you can, if you choose, denormalize data across multiple documents, by either denormalizing data from the "One" side into the "N" side, or from the "N" side into the "One" side. You'd do this only for fields that are frequently read, get read much more often than they get updated, and where you don't require strong consistency, since updating a denormalized value is slower, more expensive, and is not atomic.

Reference: http://blog.mongodb.org/post/87200945828/6-rules-of-thumb-for-mongodb-schema-design-part-1

@vishaltelangre
vishaltelangre / nginx_proxy
Last active August 29, 2015 14:08
nginx proxy pass (e.g. from port 80 to 8080)
upstream http_backend {
server 127.0.0.1:8080;
keepalive 32;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
@vishaltelangre
vishaltelangre / bit_manipulation.md
Last active August 29, 2015 14:10
bit manipulation technique

^ is the XOR operator - given two numbers it "lines up" their places and flips the place only if only one of the two numbers has that place:

// All of these are binary
111 ^ 111 === 000
110 ^ 111 === 001
110 ^ 110 === 000

This means that changed will be a number with only those places set that are set in prev_state or state but not both.

(ns storm.starter.clj.word-count-kafka
(:import ;[backtype.storm StormSubmitter LocalCluster]
[storm.kafka KafkaConfig HostPort KafkaSpout SpoutConfig StringScheme])
(:use [backtype.storm clojure config])
(:gen-class))
(def ^{:private true}
host (list "localhost:9092"))
(def ^{:private true
Count All Open File Handles
lsof | wc -l
List File Descriptors in Kernel Memory
sysctl fs.file-nr
@vishaltelangre
vishaltelangre / slack_rss
Created June 18, 2015 14:43
Slack is a deveoper's slave, abusing it to this extent! Subscribe to engineering blogs of popular companies.
/feed subscribe http://tech.adroll.com/feed.xml
/feed subscribe http://adzerk.com/tech/feed.xml
/feed subscribe https://www.airpair.com/rss
/feed subscribe https://blog.algolia.com/feed/
/feed subscribe http://allegrotech.io/feed.xml
/feed subscribe http://artsy.github.io/atom.xml
/feed subscribe https://eng.asana.com/feed/
/feed subscribe https://developer.atlassian.com/blog/feed.xml
/feed subscribe http://feeds.feedburner.com/auth0
/feed subscribe http://engineering.aweber.com/feed/
@vishaltelangre
vishaltelangre / hello.asm
Last active August 29, 2015 14:26
Hello NASM on x86_64 Mac OSX
;; BUILD AS:
; nasm -f macho64 -o hello.o 1.asm && ld -macosx_version_min 10.7.0 -lSystem -o hello hello.o && ./hello
; ^ ^ ^
; [generate object file from assembly] [link object file] [execute]
%define SYSCALL_WRITE 0x2000004
%define SYSCALL_EXIT 0x2000001
;; initialised data section
section .data
@vishaltelangre
vishaltelangre / aprc
Created February 1, 2013 09:49
My ~/.aprc (awesome_print) file at office
AwesomePrint.defaults = {
:indent => 2,
:sort_keys => true,
:color => {
:args => :greenish,
:array => :pale,
:bigdecimal => :blue,
:class => :yellow,
:date => :greenish,
:falseclass => :red,