Skip to content

Instantly share code, notes, and snippets.

@matpowel
matpowel / nexo_export_conversion.rb
Last active January 19, 2023 18:13
Automated transformation of Nexo CSV output to Koinly full template format
require 'csv'
if ARGV.empty? || ARGV.length > 2
puts
puts 'Please specific the input file name and optionally output base filename:'
puts ' ruby nexo_export_conversion.rb nexo_transactions.csv output_filename'
puts
puts 'Note that the default output filename is input filename appended with each output format appended, currently:'
puts ' - output_filename_koinly.csv'
puts ' - output_filename_coinstats.csv'
@matpowel
matpowel / monty_hall.rb
Created February 22, 2015 06:58
Monty Hall Problem Simulator
number_of_doors = 3
monty_is_random = false
switch_choice = true
number_of_simulations = 10000
# number_of_correct_initial_guesses = 0
number_of_times_monty_accidentally_exposes_car = 0
number_of_wins = 0
doors = (1..number_of_doors).inject({}){|h,i| h[i] = nil; h }
@matpowel
matpowel / jruby_1.7.3_time_patch.rb
Created March 9, 2013 07:44
Monkey patch for broken Time.at in JRuby 1.7.3
if RUBY_PLATFORM =~ /java/i
# ruby-units monkey patches the Time class which in turn exposes a bug in
# JRuby (https://github.com/jruby/jruby/issues/565)
class Time
class << self
if defined?( Unit )
# ruby units got there first
alias agworld_ruby_time_at unit_time_at
alias agworld_unit_time_at at
else
@matpowel
matpowel / gist:1120522
Created August 2, 2011 16:03
FULL trace after a 40sec timeout when the dreaded Rails 3.1 method missing freeze happens on a freshly launched Webrick instace
app/views/user_reports/_user_report_section.html.erb:28:in `_app_views_user_reports__user_report_section_html_erb__1994846421_2308184040'
/Users/matt/.rvm/gems/ree-1.8.7-2011.03@agworld-3.1/bundler/gems/rails-7ee15e8a0f84/actionpack/lib/action_view/template.rb:144:in `send'
/Users/matt/.rvm/gems/ree-1.8.7-2011.03@agworld-3.1/bundler/gems/rails-7ee15e8a0f84/actionpack/lib/action_view/template.rb:144:in `render'
/Users/matt/.rvm/gems/ree-1.8.7-2011.03@agworld-3.1/bundler/gems/rails-7ee15e8a0f84/activesupport/lib/active_support/notifications.rb:57:in `instrument'
/Users/matt/.rvm/gems/ree-1.8.7-2011.03@agworld-3.1/bundler/gems/rails-7ee15e8a0f84/actionpack/lib/action_view/template.rb:142:in `render'
/Users/matt/.rvm/gems/ree-1.8.7-2011.03@agworld-3.1/bundler/gems/rails-7ee15e8a0f84/actionpack/lib/action_view/renderer/partial_renderer.rb:256:in `render_partial'
/Users/matt/.rvm/gems/ree-1.8.7-2011.03@agworld-3.1/bundler/gems/rails-7ee15e8a0f84/actionpack/lib/action_view/renderer/partial_renderer.rb:228:in `render
@matpowel
matpowel / gist:1120516
Created August 2, 2011 16:00
ctrl-C stacktrace when the dreaded Rails 3.1 method missing freeze happens
Company Load (0.2ms) SELECT "companies".* FROM "companies" WHERE "companies"."id" IS NULL LIMIT 1
UserReportSection Load (0.5ms) SELECT "user_report_sections".* FROM "user_report_sections" WHERE "user_report_sections"."user_report_id" = 1
Rendered user_reports/_user_report_section.html.erb (60200.0ms)
Rendered user_reports/_form.html.erb (60223.1ms)
Rendered user_reports/edit.html.erb within layouts/company (60224.0ms)
Completed 500 Internal Server Error in 60280ms
ActionView::Template::Error (undefined method `radio_box' for #<ActionView::Helpers::FormBuilder:0x107f4b0e8>):
25: <td>
26: <label>Report On</label><br />
@matpowel
matpowel / Gemfile.lock
Created August 2, 2011 15:57
Gemfile.lock for a Rails 3.1 app that exhibits the dreaded freeze
GIT
remote: git://github.com/agworld/carrierwave.git
revision: e702d97baeebd7578f3611dbcff8264d306e629d
specs:
carrierwave (0.5.4)
activesupport (~> 3.0)
GIT
remote: git://github.com/agworld/geokit-rails3.git
revision: 991ff4e287b80459f0ae6e131276a530340010e3
@matpowel
matpowel / tableless.rb
Created July 23, 2011 10:04
An ActiveRecord emulating Tableless model which works with Rails 3.1
class Tableless < ActiveRecord::Base
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new( name.to_s, default, sql_type.to_s, null )
end
def self.columns()
@columns ||= [];
end