Skip to content

Instantly share code, notes, and snippets.

@manveru
manveru / iin_check.rb
Created July 25, 2010 11:51
Check CreditCard IIN to get issuing network
def check(number)
number = number.gsub(/\D+/, '')
first = Hash.new{|h,k| h[k] = number[0, k].to_i }
size = number.size
# American Express 34, 37 Yes 15 Luhn algorithm AmEx
if [13, 16].include?(size) && number =~ /^(34|37)/
:AmEx
# China UnionPay 622126-622925, 624-626, 6282-6288 Yes 16-19 unknown CUP
elsif (16..19) === size && ((622126..622925) === first[6] ||
class SetMailException
def initialize(app)
@app = app
end
def call(env)
status, header, body = @app.call(env)
rescue => ex
env['mail.exception'] = ex
raise ex
use Rack::MailExceptions
use Sinatra::ExceptionHandler
use SetMailException
run yourapp
LotteryTicket =
get_picks: -> @picks
set_picks: (@picks) ->
get_purchased: -> @purchase
set_purchased: (@purchased) ->
@manveru
manveru / git-rank-contributors
Created August 2, 2010 01:07
Trace through logs and rank contributors
#!/usr/bin/env ruby
## git-rank-contributors: a simple script to trace through the logs and
## rank contributors by the total size of the diffs they're responsible for.
## A change counts twice as much as a plain addition or deletion.
##
## Output may or may not be suitable for inclusion in a CREDITS file.
## Probably not without some editing, because people often commit from more
## than one address.
##
module Delegator
def self.extended(into)
(class << into; self; end).send :attr_accessor, :delegates
into.delegates = []
into.send :define_method, :method_missing do |method, *args, &block|
self.class.delegates.map{|delegate| send(delegate) }.each do |receiver|
next unless receiver.respond_to?(method)
return receiver.send(method, *args, &block)
end
require 'json'
require 'pstore'
class JSON::Store < PStore
def dump(table)
JSON.pretty_unparse(@table)
end
def load(content)
JSON.load(content)
require 'ramaze'
require 'json'
class Main < Ramaze::Controller
provide(:json, type: 'application/json'){|action, value| value.to_json }
def index
{'some' => 'json'}
end
end
@manveru
manveru / PKGBUILD
Created August 20, 2010 09:20
PKGBUILD for the google talk plugin
# Maintainer: Michael Fellinger <[email protected]>
pkgname=google-talkplugin
pkgver=0
pkgrel=1
pkgdesc="Video chat plugin for Gmail, iGoogle, and Orkut"
arch=(x86_64)
url="http://www.google.com/chat/video"
license=('unknown')
depends=('libpng12' 'lib32-openssl-compatibility')
source=("http://dl.google.com/linux/direct/${pkgname}_current_amd64.deb")
@manveru
manveru / cover.rb
Created August 21, 2010 15:14
Little coverage output formatter
#!/usr/bin/env ruby
require 'pp'
require 'coverage'
Coverage.start
ARGV.each do |arg|
require_relative arg
end