Skip to content

Instantly share code, notes, and snippets.

@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.
##
LotteryTicket =
get_picks: -> @picks
set_picks: (@picks) ->
get_purchased: -> @purchase
set_purchased: (@purchased) ->
use Rack::MailExceptions
use Sinatra::ExceptionHandler
use SetMailException
run yourapp
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
@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] ||
url: require 'url'
querystring: require 'querystring'
request: require 'request'
class Rpx
constructor: (apiKey) ->
@apiKey: apiKey
authInfo: (token, callback) ->
@apiCall 'auth_info', {token: token}, (data) ->
module Ramaze
module Helper
module ReCaptcha
# Call this to generate the actual ReCaptcha script into your template.
# Options can include
# [rcc_pub] public recaptcha key (defaults to RCC_PUB constant)
# [rcc_priv] privte recaptcha key (defaults to RCC_PRIV constant)
# [ssl] generate ssl-based output, defaults to false
#
# This method also sets :rcc_err into the session.
@manveru
manveru / rpn-calculator.rb
Created July 16, 2010 03:37
RPN Calculator
# Simple RPN calculator with stack.
# Example usage:
# >> 400 400 400 *
# Top of stack: 64000000
# >> 40 40 *
# Top of stack: 102400000000
# >> 40
# Top of stack: 40
# >> 30
# Top of stack: 30
require 'activesupport'
module Password
VERSION = '1.0.0'
FILENAME = "#{ENV['HOME']}/.they_stole_my_facebook_login_oh_noez" # honestly, "security", who gives a shit
SITES = {}
def set(credentials)
SITES[credentials[:site]] = {:username => credentials[:username],
:password => credentials[:password]}
end
def username(site)
require './examples/javascript'
sys: require 'sys'
p: (obj) -> sys.puts(sys.inspect(obj, false, 100))
p JSGrammar.parse('something.that(/works/)')