Skip to content

Instantly share code, notes, and snippets.

@ashayh
ashayh / faye.ru
Created October 24, 2012 17:34 — forked from ekorneeff/faye.ru
Faye online/offline status to Rails via Redis
# Run with: rackup faye.ru -s thin -E production
# For executor-customer chat
require "bundler/setup"
require "faye"
require 'redis'
require 'redis/objects'
Redis.current = Redis.new(:host => '127.0.0.1', :port => 6379)
Faye::WebSocket.load_adapter('thin')
@ashayh
ashayh / autobackupmongo.rb
Created November 10, 2012 01:38 — forked from lajunta/autobackupmongo.rb
auto backup mongo (ruby version and very concise)
#!/usr/local/ruby/bin/ruby -w
Dbpath = "/data/db" # database path
Backpath = "/data/dbbackup" # backup directory
Host = "" # mongo host to connect,empty is for local
Database = "" # database to use. empty is for all
Collection = "" # collection to use
User = ""
Passwd = ""
Now = Time.now
DATE = Now.strftime("%Y-%m-%d")
@ashayh
ashayh / latency.txt
Created November 14, 2012 04:58 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
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
@ashayh
ashayh / rails_http_auth_ssl
Created November 25, 2012 04:56
Rails HTTP Auth plus SSL
# in controller_name.rb :
before_filter :http_auth
# in application_controller.rb :
def http_auth
authenticate_or_request_with_http_basic do |username, password|
username == "user" && password == "password"
end
end
@ashayh
ashayh / bind_conf.treetop
Created December 3, 2012 22:41 — forked from mat813/bind_conf.treetop
simple named.conf parsing
require 'ip'
grammar BindConf
include IP
rule entries
(zone / key / server)* {
%w(zone key server).each do |i|
module_eval <<-eot, __FILE__, __LINE__+1
def each_#{i}(&block)
@ashayh
ashayh / .gitignore
Created December 20, 2012 22:39 — forked from karmi/.gitignore
.DS_Store
Gemfile.lock
*.pem
node.json
tmp/*
!tmp/.gitignore
@ashayh
ashayh / firedns.js
Created January 16, 2013 01:27 — forked from vikrum/firedns.js
var crypto = require('crypto');
var dns = require('native-dns');
var rest = require('restler');
var server = dns.createServer();
server.on('request', function (request, response) {
var domain = request.question[0].name;
if(domain == 'webutils.flourishworks.com') {
// Don't log this because it can't be uniquely identified and subsequently retrieved
@ashayh
ashayh / dnsd.rb
Created January 16, 2013 01:27 — forked from peterc/dnsd.rb
# Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# By Peter Cooper
#
# MIT license
#
# * Not advised to use in your production environment! ;-)
# * Requires Ruby 1.9
# * Supports A and CNAME records
# * See http://www.ietf.org/rfc/rfc1035.txt for protocol guidance
# * All records get the same TTL
@ashayh
ashayh / firedns.js
Created January 16, 2013 01:31 — forked from vikrum/firedns.js
var crypto = require('crypto');
var dns = require('native-dns');
var rest = require('restler');
var server = dns.createServer();
server.on('request', function (request, response) {
var domain = request.question[0].name;
if(domain == 'webutils.flourishworks.com') {
// Don't log this because it can't be uniquely identified and subsequently retrieved
@ashayh
ashayh / crtime.sh
Created January 19, 2013 01:53
Extract ext4 creation (crtime) of file
#!/bin/bash
# Author: ashay dot humane at gmail.com
# Given a file name, this script prints the file creation time,
# as ext4 records it
# Might error out on other filesystems
DEBUGFS="/sbin/debugfs"
[[ -f "$1" ]] || { echo "Invalid filename. Exiting" ; exit 1; }