Skip to content

Instantly share code, notes, and snippets.

@exAspArk
exAspArk / gist:d81e5d7b6ad1bdd3bcf6
Created October 31, 2014 16:50
Immutable deep hash merge (ruby)
def deep_merge(hash1, hash2)
result = hash1.dup
hash2.keys.each do |key|
if hash2[key].is_a?(Hash) && hash1[key].is_a?(Hash)
result[key] = deep_merge(hash1[key], hash2[key])
else
result[key] = hash2[key]
end
end
@exAspArk
exAspArk / hacks.rb
Last active August 29, 2015 14:08 — forked from conf/monkey_patches.rb
Get rid of TZInfo::AmbiguousTime exception
# config/initializers/hacks.rb
Dir[Rails.root.join("lib/hacks/**/*.rb")].each { |file| require file }
@exAspArk
exAspArk / ruby_heart_print.rb
Last active August 29, 2015 14:15
Prints heart with ruby
ruby_print = ->(a, b = 28, c = 1) { puts ("ruby" * a).center(b) * c } ; [[2, 14, 2], [3, 14, 2], 7, 7, 7, 6, 5, 4, 3, 2, 1].map { |i| ruby_print.call(*i) }
rubyruby rubyruby
rubyrubyruby rubyrubyruby
rubyrubyrubyrubyrubyrubyruby
rubyrubyrubyrubyrubyrubyruby
rubyrubyrubyrubyrubyrubyruby
rubyrubyrubyrubyrubyruby
rubyrubyrubyrubyruby
rubyrubyrubyruby
require "net/http"
def start_server
# Remove the X to enable the parameters for tuning.
# These are the default values as of Ruby 2.2.0.
@child = spawn(<<-EOC.split.join(" "))
XRUBY_GC_HEAP_FREE_SLOTS=4096
XRUBY_GC_HEAP_INIT_SLOTS=10000
XRUBY_GC_HEAP_GROWTH_FACTOR=1.8
XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0
@exAspArk
exAspArk / gist:42bdb62751a9300ee6d7
Created December 21, 2015 09:42
Screen / Tmux (in iTerm 2)
ssh login@server.example.com -t "screen -DR session_name"
tmux -CC attach -t session_name || tmux -CC new -s session_name
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@exAspArk
exAspArk / simple_form.rb
Last active December 26, 2015 12:28 — forked from clyfe/simple_form.rb
# http://stackoverflow.com/questions/14972253/simpleform-default-input-class
# https://github.com/plataformatec/simple_form/issues/316
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
config.boolean_style = :nested
config.wrappers :bootstrap3, tag: 'div', class: 'form-group', error_class: 'has-error',
defaults: { input_html: { class: 'default_class' } } do |b|
@exAspArk
exAspArk / The Technical Interview Cheat Sheet.md
Created January 20, 2016 11:11 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@exAspArk
exAspArk / state_machine.rb
Last active February 22, 2016 22:28
HACK StateMachine gem to make it work with ActiveRecord 4.2
# HACK to enable using protected methods from Rails 4.2 and initial states as default attributes for ActiveRecord
module StateMachine
module Integrations
module ActiveModel
public :around_validation
end
module ActiveRecord
public :around_save
require "net/http"
require "socket"
socket = "/tmp/portal2.sock"
sock = Net::BufferedIO.new(UNIXSocket.new(socket))
request = Net::HTTP::Get.new("/")
request.exec(sock, "1.1", "/")
begin