Skip to content

Instantly share code, notes, and snippets.

View krisleech's full-sized avatar

Kris Leech krisleech

View GitHub Profile
@AMHOL
AMHOL / ex.rb
Last active August 29, 2015 14:19
require 'transproc/all'
require 'json'
json = <<-EOS
{
"links": {
"self": "http://example.com/posts",
"next": "http://example.com/posts?page[offset]=2",
"last": "http://example.com/posts?page[offset]=10"
},
require "./compiler/crystal/**"
while line = gets
compiler = Crystal::Compiler.new
program = Crystal::Program.new
program.target_machine = compiler.target_machine
prelude = program.normalize(Crystal::Require.new("prelude"))
@apotonick
apotonick / wishlist.rb
Last active November 21, 2018 07:19
My Ruby Wishlist
# Ruby Wishlist
## Removals
* finalize! method for classes
* Remove constant_finding/loading at runtime, it always breaks.
## Module.freeze
Remove the ability to dynamically change code at runtime
require "rspec/exit_matchers/version"
# expect { exit(1) }.to exit_with_status(1)
module RSpec
module ExitMatchers
class ExitWithStatus
def initialize(expected_status)
@expected_status = expected_status
end
@staltz
staltz / introrx.md
Last active May 23, 2024 09:20
The introduction to Reactive Programming you've been missing
@icyleaf
icyleaf / ar_migrate.rb
Last active May 5, 2024 14:55
ActiveRecord type of integer (tinyint, smallint, mediumint, int, bigint)
# activerecord-3.0.0/lib/active_record/connection_adapters/mysql_adapter.rb
# Maps logical Rails types to MySQL-specific data types.
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
return super unless type.to_s == 'integer'
case limit
when 1; 'tinyint'
when 2; 'smallint'
when 3; 'mediumint'
when nil, 4, 11; 'int(11)' # compatibility with MySQL default
@shime
shime / readme.md
Last active March 13, 2020 09:39
bake your own code reloader for rails

Let's build our own code reloader for Rails, shall we?

Require dependency problems

Run this inside rails/railties:

$ grep -rn "eager_load_paths" .

You should get the results from Rails::Engine::Configuration and Rails::Engine. As you know, each Rails application is actually a Rails::Engine and Rails::Engine::Configuration is that thing wrapped inside Rails.application.config block.

@samnang
samnang / 1_decorator.rb
Created September 15, 2013 03:21
Decorator vs Form Object vs Service Object?
class FacebookCommentNotifer
def initialize(comment)
@comment = comment
end
def save
@comment.save && post_to_wall
end
private
@rwjblue
rwjblue / disable_should.rb
Created July 18, 2013 15:26
Disable RSpec's should syntax.
RSpec.configure do |config|
# disable the `should` syntax...
config.expect_with :rspec do |c|
c.syntax = :expect
end
config.mock_with :rspec do |c|
c.syntax = :expect
end
end
def create_very_rails
project = Project.create project_params
if project.persisted?
sync_new project
redirect_to project
else
redirect_to edit_project_path(project)
end
end