Skip to content

Instantly share code, notes, and snippets.

require 'tempfile'
def check_authorized_keys(keyfile)
valid = false
File.foreach(keyfile).map do |line|
if line =~ /^ssh/
Tempfile.open('key') do |keyfile|
keyfile.write(line)
keyfile.flush
@result = %x[echo #{keyfile.path} | ssh-keygen -l 2>&1]
@manveru
manveru / setup_gitconfig.rb
Created October 31, 2011 21:25 — forked from eykanal/setup_gitconfig.rb
Create basic .gitconfig file
#!/usr/bin/ruby
def ask(question, retries = 3)
fail "Failed to get user input" if retries <= 0
print question
if got = gets
got.strip
else
Ramaze::Cache.options.session = Ramaze::Cache::MemCache.using(
compression: false,
username: ENV['MEMCACHE_USERNAME'],
password: ENV['MEMCACHE_PASSWORD'],
servers: ENV['MEMCACHE_SERVERS'].split(','),
)
class KeyMetrics
def initialize(date, day)
@@data = Metric.last(source: 'all', start_date: date, end_date: date)
p 'DATA'
p @@data
end
def find
{
visits: @@data.visits.to_s,
revenue: CURRENCY + sdlw_data.transaction_revenue.to_s
@manveru
manveru / gist:5716970
Last active December 18, 2015 03:19 — forked from jcoene/gist:5034155
#!/usr/bin/ruby
# This program adds up the numbers 1 through 10,000 using 100 threads.
# Challenge A: Does this solution have any problems? If so, explain.
# Challenge B: Propose an alternate implementation that does not use threads.
n = 10000
p (1..n).reduce(:+) # by iteration
#!/usr/bin/ruby
# This program adds up the numbers 1 through 10,000 using 100 threads.
# Challenge A: Does this solution have any problems? If so, explain.
# Challenge B: Propose an alternate implementation that does not use threads.
require "thread"
mt_result = 0
@manveru
manveru / thread_sum.rb
Last active December 18, 2015 03:19 — forked from jcoene/gist:5034155
#!/usr/bin/env ruby
threads = 100.times.map do |n|
Thread.new n do |m|
base = 1 + (m * 100)
100.times.map do |i|
base + i
end
end
end