This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def temporary_assign(object, attribute, new_value) | |
previous_value = object.public_send attribute | |
object.public_send "#{attribute}=", new_value | |
yield | |
ensure | |
object.public_send "#{attribute}=", previous_value | |
end | |
# Example usage: | |
# Want to debug SQL queries in tests? Log to STDOUT just for the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'micro_bench' | |
# Various methods to update every value in a hash in place | |
module HashUpdate | |
module_function | |
# also Hash#update | |
def merge!(hash) | |
hash.merge!(hash) do |key, value| | |
value + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ uname -a | |
Darwin MacBook-Pro.fritz.box 14.0.0 Darwin Kernel Version 14.0.0: Fri Sep 19 00:26:44 PDT 2014; root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64 | |
$ ruby -v | |
ruby 2.1.4p265 (2014-10-27 revision 48166) [x86_64-darwin14.0] | |
$ gem --version | |
2.4.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative './board' | |
require_relative './naive_solver' | |
# | |
# This is a reference implementation for solving the board | |
# and may be considered a spoiler | |
# | |
# s = Solver.load 'my-team', 100 | |
# s.solve | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Attachinary | |
module Utils | |
Rails.logger.warn 'Monkey patched Attachinary::Utilss#process_hash' | |
def self.process_hash(hash, scope=nil) | |
file = if hash['id'] | |
Attachinary::File.find hash['id'] | |
else | |
file = Attachinary::File.new hash.slice('public_id', 'version', 'width', 'height', 'format', 'resource_type') | |
file.scope = scope.to_s if scope && file.respond_to?(:scope=) | |
file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery -> | |
$('.cloudinary-fileupload').on 'cloudinarydone', (e, data) -> | |
$('.js-cl-preview').html $.cloudinary.image data.result.public_id, { | |
format: data.result.format, | |
version: data.result.version, | |
width: 150, | |
height: 100, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=n.gsub(?|,' ').split$/ | |
i=!p;t=a.map(&:chars).transpose.map(&:join).select{i^=a}.sort_by{|s|s[/[A-Z]/][0]} | |
x=0;t.map{|t|y=0;u=p;t.chars{|c|u&&a[y][x,3]=?|*3;a[y][x+1]=c;y+=1;u|=c=='_'};x+=2} | |
a.join$/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def changes | |
@changes ||= created_changes + updated_changes + deleted_changes | |
end | |
def created_changes | |
changes_for created_fields, :created | |
end | |
def updated_changes | |
changes_for updated_fields, :updated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'active_record' # 4.2.3 | |
require 'paperclip' # 4.3.0 | |
ActiveRecord::Migration.verbose = false | |
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") | |
ActiveRecord::Base.raise_in_transactional_callbacks = true | |
ActiveRecord::Schema.define(:version => 1) do | |
create_table :widgets, force: true do |t| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Small Arrays: (80 + 40) | |
Calculating ------------------------------------- | |
b & a | a 24.860k i/100ms | |
sort_by 27.909k i/100ms | |
set 7.622k i/100ms | |
------------------------------------------------- | |
b & a | a 339.055k (± 3.3%) i/s - 1.715M | |
sort_by 393.757k (± 2.9%) i/s - 1.982M | |
set 84.387k (± 2.1%) i/s - 426.832k |