Skip to content

Instantly share code, notes, and snippets.

View Arkham's full-sized avatar
🏠
Working from home

Ju Liu Arkham

🏠
Working from home
View GitHub Profile
@Arkham
Arkham / autosave_association.rb
Created August 4, 2014 22:38
activerecord/lib/active_record/autosave_association.rb
module ActiveRecord
# = Active Record Autosave Association
#
# +AutosaveAssociation+ is a module that takes care of automatically saving
# associated records when their parent is saved. In addition to saving, it
# also destroys any associated records that were marked for destruction.
# (See +mark_for_destruction+ and <tt>marked_for_destruction?</tt>).
#
# Saving of the parent, its associations, and the destruction of marked
# associations, all happen inside a transaction. This should never leave the
@Arkham
Arkham / test_autosave_inverse_of.rb
Created August 4, 2014 22:39
Test autosave inverse_of system stack error
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'active_record'
require 'minitest/autorun'
require 'logger'
require 'pry'
# Ensure backward compatibility with Minitest 4
@Arkham
Arkham / gemfile
Created August 4, 2014 22:40
Test activerecord gemfile
source 'http://rubygems.org'
gem 'arel', github: 'rails/arel'
gem 'rack', github: 'rack/rack'
gem 'i18n', github: 'svenfuchs/i18n'
gem 'rails', path: 'vendor/rails'
gem 'sqlite3'
gem 'pry'
@Arkham
Arkham / gist:8f82282cf45dbe2ade2a
Created August 11, 2014 17:09
Fix delayed job invoices
# Select all invoices with last_error
blob = Invoice.where("last_error ILIKE ?", "Invalid field%").includes(advisor: :bank_account).map do |invoice|
[ invoice.id, invoice.bank_account.account_number_crypted, invoice.bank_account.aba_crypted ]
end.to_json
# On blueberry
require_relative 'app'
require 'json'
@Arkham
Arkham / meta.rb
Created September 7, 2014 00:24
Respond To Missing
class Person
def initialize(name)
@name = name
end
def small_talk(other)
greet(other)
topics = methods.grep /^chat_about_/
topics.shuffle!
@Arkham
Arkham / introrx.md
Last active August 29, 2015 14:25 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

[
{
"token": "nhMbMTpjMRM1zxNMQzw3g8cwiuOM9D12kQ0MDMvUGdlJ",
"mail_address": "test@example.com",
"port_not_allowed": true,
"hole": false,
"warning": true,
"info": true,
"difference": false,
"no_problem": true,
@Arkham
Arkham / poldo.rb
Created January 23, 2013 10:07
Poldo!
class Poldo
cattr_accessor :sausages
def self.all
@sausages ||= SausageFetcher.fetch!
end
def self.reload!
@sausages = SausageFetcher.fetch!
end
class AcronymSolver
attr_reader :text
def initialize(text)
@text = text
end
def self.substitutions
{
:PPC => 'Pocket PC',
@Arkham
Arkham / gist:5141232
Created March 12, 2013 08:45
mover specs
describe Wordmove::SqlMover do
context ".serialized_replace!" do
let(:content) { 'a:3:{i:0;s:20:"http://dump.com/spam";i:1;s:6:"foobar";i:2;s:22:"http://dump.com/foobar";}' }
let(:sql) { Tempfile.new('sql').tap do |d| d.write(content); d.close end }
let(:sql_path) { sql.path }
it "should replace source vhost with dest vhost" do
sql_mover.serialized_replace!('http://dump.com', 'http://shrubbery.com')
sql_mover.sql_content.should == 'a:3:{i:0;s:25:"http://shrubbery.com/spam";i:1;s:6:"foobar";i:2;s:27:"http://shrubbery.com/foobar";}'