Skip to content

Instantly share code, notes, and snippets.

View arikfr's full-sized avatar

Arik Fraimovich arikfr

View GitHub Profile
@arikfr
arikfr / logger.rb
Created August 20, 2011 16:28
Logger in a thread
require 'thread'
require 'singleton'
class Logger
include Singleton
def initialize
STDOUT.sync = true
@queue = ::Queue.new
create_thread
@arikfr
arikfr / proc_stub_sample.rb
Created October 2, 2011 07:58
ProcStub -- helper to test callbacks in specs
# Stuff this in spec/support/ :
class ProcStub
attr_accessor :called, :args
def initialize
@called = false
@args = nil
end
@arikfr
arikfr / with_morphine.rb
Created March 9, 2012 08:27
Trying to understand why would I use Morphine rather regular class with class methods
class Application
include Morphine
register :track_service do
KestrelTrackService.new(kestrel_client, config.tracking_queue)
end
register :track_processor do
KestrelTrackProcessor.new(blocking_kestrel_client, config.tracking_queue)
end
@arikfr
arikfr / install_graphite_statsd_ubuntu_precise.sh
Created August 11, 2012 09:05 — forked from bhang/install_graphite_statsd_ubuntu_precise.sh
Install Graphite and statsd on Ubuntu 12.04 LTS (Precise Pangolin)
#!/bin/bash
# node.js using PPA (for statsd)
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm
# Install git to get statsd
sudo apt-get install git
require 'sinatra'
require 'redis'
require 'json'
class ServerRepository
attr_reader :redis
def initialize
@redis = Redis.new
end
@arikfr
arikfr / gist:5480495
Last active December 16, 2015 18:49
import json
def json_object_parser(o):
"""
Default parser to be called by the JSON Encoder when all other options failed.
"""
if hasattr(o, 'as_json'):
return o.as_json()
raise TypeError(repr(o) + " is not JSON serializable (and doesn't support as_json)")
@arikfr
arikfr / example.go
Last active December 17, 2015 06:48
Safe shutdown in Go.
package main
import (
"log"
"shutdown"
)
func main() {
ch := shutdown.Add("test")
ch2 := shutdown.Add("test2")
from scribe.scribe import Processor
from scribe.ttypes import *
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TNonblockingServer
import socket
@arikfr
arikfr / .env
Last active August 29, 2015 13:56
Example configuration for re:dash
export REDASH_CONNECTION_ADAPTER=pg
export REDASH_CONNECTION_STRING="dbname=ubuntu"
export REDASH_STATIC_ASSETS_PATH="../rd_ui/dist/"
export REDASH_LOG_LEVEL="INFO"
export REDASH_WORKERS_COUNT=6
export REDASH_REDIS_URL=redis://localhost:6379/
export REDASH_DATABASE_URL="postgresql://ubuntu"
export REDASH_COOKIE_SECRET=
export REDASH_ADMINS=
export REDASH_GOOGLE_APPS_DOMAIN=
@arikfr
arikfr / gist:11362378
Last active August 29, 2015 14:00
Kata: Number to LCD
## Goal: write a program that displays LCD style numbers.
### Part 1
Write a program that given a number (with arbitrary number of digits), converts it into LCD style numbers using the following format:
_ _ _ _ _ _ _
| _| _||_||_ |_ ||_||_|
||_ _| | _||_| ||_| _|