Skip to content

Instantly share code, notes, and snippets.

Dan Manges dan-manges

Block or report user

Report or block dan-manges

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am dan-manges on github.
  • I am danmanges (https://keybase.io/danmanges) on keybase.
  • I have a public key whose fingerprint is 4224 49E1 A87C D6BD 22D2 29AF 6317 7701 6B90 2E19

To claim this, I am signing this object:

View dinner.rb
require_relative "helper"
available = {}
0.upto(15).each do |i|
available[i] = {}
i.upto(15).each do |j|
available[i][j] = true
if i / 4 == j / 4
available[i][j] = false
end
@dan-manges
dan-manges / app.coffee
Created Jun 9, 2011
mongrel2 timeout handler
View app.coffee
http = require 'http'
m2node = require 'm2node'
server = http.createServer((req, res) ->
console.log("#{req.method} #{req.url}")
sendResponse = ->
res.writeHead(200, {'Content-Type': 'text/plain'})
res.end('Hello World\n')
match = req.url.match(/sleep.(\d+)/)
if match
View gist:431922
def fib(n)
if n <= 2
1
else
fib(n-1) + fib(n-2)
end
end
def fibsum(n)
sum = 0
View gist:430424
def mask(x)x[0,6]+'*'*(x.size-10)+x[-4..-1]end
View gist:429507
def luhn?(number)
digits = number.scan(/\d/).map { |d| d.to_i }.reverse
digits.each_with_index do |digit, index|
if index % 2 == 1
digits[index] = (digit >= 5 ? digit * 2 - 9 : digit * 2)
end
end
digits.inject(0) { |a,b| a + b } % 10 == 0
end
View gist:429398
def self.luhn_valid?(number)
return false unless number.to_s =~ /\A\d+\z/
digits = number.scan(/\d/).map(&:to_i).reverse
digits.each_with_index do |digit, index|
if index.odd?
digits[index] = (digit >= 5 ? digit * 2 - 9 : digit * 2)
end
end
digits.sum % 10 == 0
end
View gist:429392
def luhn10?(number)
return false unless number.to_s =~ /\A\d+\z/
digits = number.scan(/\d/).map(&:to_i).reverse
digits.each_with_index do |digit, index|
if index.odd?
digits[index] = (digit >= 5 ? digit * 2 - 9 : digit * 2)
end
end
digits.sum % 10 == 0
end
View mixology_hook.rb
require "rubygems"
gem "mixology", "0.2.0"
require "mixology"
Mixology.class_eval do
def mixin_with_hook(mod)
result = mixin_without_hook(mod)
if mod.respond_to?(:mixed_into)
mod.mixed_into(self)
end
View gist:149193
require "rubygems"
gem "ezcrypto", "0.7"
require "ezcrypto"
key = EzCrypto::Key.new("x" * 32, :algorithm => "aes-256-cbc")
encrypted = key.encrypt("foo")
decrypted = key.decrypt(encrypted)
p decrypted
You can’t perform that action at this time.