Skip to content

Instantly share code, notes, and snippets.

View trappist's full-sized avatar

Rocco Stanzione trappist

View GitHub Profile
module Concerns
module Gmoney
extend ActiveSupport::Concern
included do
def self.gmoney(*attrs)
attrs.each do |attr|
define_method(:"#{attr}=") do |money|
if money.blank?
@trappist
trappist / big_decimal.rb
Created March 5, 2018 20:46
Make decimals not suck
class BigDecimal
include ActionView::Helpers::NumberHelper
def inspect
to_s('F')
end
end
def subscribe_to_ticker
@ticker_thread = Thread.new do
@ticker_connection = WampClient::Connection.new(uri: 'wss://api.poloniex.com', realm: 'realm1', verbose: false)
@ticker_connection.on_join do |session, details|
session.subscribe('ticker', method(:ticker_handler))
end
@ticker_connection.on_disconnect do |reason|
puts "DISCONNECTED: #{reason}"
end
@ticker_connection.open

Keybase proof

I hereby claim:

  • I am trappist on github.
  • I am trappist (https://keybase.io/trappist) on keybase.
  • I have a public key ASDunj4asLbxBUugGXYZpex-Z3RhgzOhzXiiUeU0N0e85Ao

To claim this, I am signing this object:

Verifying myself: My Bitcoin username is +trappist. https://onename.io/trappist
mac:~$ ssh -v lkf
OpenSSH_5.9p1, OpenSSL 0.9.8y 5 Feb 2013
debug1: Reading configuration data /Users/trappist/.ssh/config
debug1: /Users/trappist/.ssh/config line 3: Applying options for lkf
debug1: /Users/trappist/.ssh/config line 31: Applying options for *
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 53: Applying options for *
debug1: Connecting to 69.164.193.64 [69.164.193.64] port 22.
debug1: Connection established.
@trappist
trappist / .vimrc
Created December 25, 2013 06:18
Open the file with the cursor on lineno given /path/to/file:linono on the command line
function! s:gotoline()
let file = bufname("%")
let names = matchlist( file, '\(.*\):\(\d\+\)')
if len(names) != 0 && filereadable(names[1])
exec ":e " . names[1]
exec ":" . names[2]
if foldlevel(names[2]) > 0
exec ":foldopen!"
endif
endif
class Conversation < ActiveRecord::Base
belongs_to :initiator, :class_name => '::User'
belongs_to :recipient, :class_name => '::User'
has_many :messages
has_one :last_message, -> { order("created_at DESC") }, :class_name => '::Message'
scope :visible, -> do
joins("LEFT OUTER JOIN blockings b ON (b.blocker_id=conversations.initiator_id AND b.blocked_id=conversations.recipient_id) OR (b.blocked_id=conversations.initiator_id AND b.blocker_id=conversations.recipient_id)").where("b.id IS NULL")
end
scope :between, ->(user1,user2) { with(user1).with(user2) }
scope :with, ->(other) { where("? IN (initiator_id,recipient_id)", other.id) }
@trappist
trappist / spiral.rb
Created December 3, 2013 00:45
Consume a 2d array in a "spiral"
#!/usr/bin/env ruby
def spiral(array,ans=[])
return ans unless array.any?
ans += array.shift
spiral(array.transpose.reverse, ans)
end
array = [
[1,2,3,1],
class Sizes::CupSize < Size
US = %w[A B C D DD/E DDD/F DDDD/G DDDDD/H]
EU = %w[A B C D E F G H]
UK = %w[A B C D DD E F FF]
[:us, :uk, :eu].each do |region|
class_eval %Q"
def #{region}
by_region(:#{region})