Skip to content

Instantly share code, notes, and snippets.

@rfunduk
rfunduk / amino_to_bech32.rb
Last active July 18, 2018 01:02
Using bitcoin-ruby to convert from Cosmos Amino encoded public key values to bech32.
# Prerequisites:
# gem install bitcoin-ruby
require 'bitcoin'
def amino_to_bech32( base64_pubkey_value )
bytes = [
*["1624DE6420"].pack('H*').bytes,
*Base64.decode64( base64_pubkey_value ).bytes
]
@rfunduk
rfunduk / int_to_roman_numerals.rb
Created August 18, 2013 19:07
Using only single numerals (eg, no definition in `map` for `40 => 'XL'`), convert an integer to it's equivalent roman numeral string. Run with `ruby int_to_roman_numerals.rb test` or `ruby int_to_roman_numerals.rb 1`
#!/usr/bin/env ruby
class Integer
def to_roman_numerals
num = self
map = {
1 => 'I',
5 => 'V',
10 => 'X',
;;; DECK
(ns card-game.deck)
(defn create []
(shuffle [:h2 :h3 :h4 :h5 :h6 :h7 :h8 :h9 :h0 :hj :hq :hk :ha
:d2 :d3 :d4 :d5 :d6 :d7 :d8 :d9 :d0 :dj :dq :dk :da
:s2 :s3 :s4 :s5 :s6 :s7 :s8 :s9 :s0 :sj :sq :sk :sa
:c2 :c3 :c4 :c5 :c6 :c7 :c8 :c9 :c0 :cj :cq :ck :ca])
)
(ns fizzbuzz.core (:gen-class))
(use '[clojure.string :only [blank? capitalize]])
; a macro which expands (fbfn name M) to a function of one
; argument N which outputs "Name" if N % M == 0, otherwise ""
(defmacro fbfn [name test]
`(fn [arg#] (if (zero? (mod arg# ~test))
~(capitalize (str name)) ""))
)
@rfunduk
rfunduk / autoshot.rb
Created December 4, 2012 21:30
Auto-scp screenshots to a webserver and copy the url to your clipboard (on OSX)
#!/usr/bin/env ruby
# autoshot.rb
#
# Ryan Funduk (ryanfunduk.com)
# Licensed under WTFPL (http://sam.zoy.org/wtfpl)
#
# Watch a directory and scp new files to a host that
# is running a webserver. Only works on OSX, could be
# made to work on other platforms with alternatives
@rfunduk
rfunduk / gist:3206815
Created July 30, 2012 13:18 — forked from avibryant/gist:3200554
The Regex Game
The Regex Game
Avi Bryant
This is a game for two programmers, although it's easy to imagine variations for more.
It can be played over email, twitter, or IM, but it's easy to imagine a custom web app for it, and I encourage someone to build one.
Each player starts by thinking of a regular expression. The players should decide beforehand on dialect and length restrictions (eg, has to be JavaScript-compatible and under 20 characters).
They don't reveal the Regex, but if playing over email etc, should send each other a difficult to brute force hash (eg bcrypt) of the Regex for later verification.
They do reveal two strings: one which the Regex will match, and one which it will not.
@rfunduk
rfunduk / an_initializer.rb
Created June 8, 2012 13:29
Rails 3.2.x log usefulness *= 1_000_000_000
# SHUT UP with the "GET /assets/whatever..." in the log. Do not want.
if Rails.env.development?
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
end
end
@rfunduk
rfunduk / resque.god
Created May 26, 2012 12:24
Sample god config
rails_env = ENV['RAILS_ENV'] || "development"
rails_root = ENV['RAILS_ROOT'] || Dir.pwd
num_workers = rails_env == 'production' ? 5 : 1
num_workers.times do |num|
God.watch do |w|
w.dir = "#{rails_root}"
w.name = "resque-#{num}"
w.group = 'resque'
w.interval = 30.seconds
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "PublicReadForGetBucketObjects",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
@rfunduk
rfunduk / example_controller.rb
Created February 17, 2012 13:24 — forked from shime/example_controller.rb
sending errors to Exceptional with rescue_from
class ExampleController < ApplicationController
rescue_from Exception, :with => :render_custom
def render_custom(exception)
if Exceptional::Remote.error(Exceptional::ExceptionData.new(exception, "Test Exception"))
Rails.logger.info "Exceptional: #{exception.class} has been reported to Exceptional"
else
Rails.logger.error "Exceptional: Problem sending exception. Check your API key."
end