This file contains hidden or 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
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', github: 'gsamokovarov/rails', branch: 'fix-null-resolver' | |
gem 'arel', github: 'rails/arel' | |
gem 'rack', github: 'rack/rack' | |
gem 'i18n', github: 'svenfuchs/i18n' | |
GEMFILE | |
system 'bundle' |
This file contains hidden or 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
die_ruby.rb:10: [BUG] Segmentation fault at 0x007fff9cd5cfe8 | |
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux] | |
-- Control frame information ----------------------------------------------- | |
c:0002 p:0015 s:23794 E:001928 EVAL die_ruby.rb:10 [FINISH] | |
c:0001 p:0000 s:0002 E:0016d8 TOP [FINISH] | |
die_ruby.rb:10:in `<main>' | |
-- C level backtrace information ------------------------------------------- |
This file contains hidden or 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
class Exception | |
def set_backtrace_with_extension | |
set_backtrace_without_extension(*args) | |
end | |
alias set_backtrace_without_extension set_backtrace | |
alias set_backtrace set_backtrace_with_extension | |
end | |
raise |
This file contains hidden or 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 'pty' | |
PTY.spawn 'irb' do |output, input, pid| | |
loop do sleep 1 | |
input.puts 'puts :Wootz!' | |
puts output.gets | |
end | |
end | |
__END__ |
This file contains hidden or 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
# If you truncate a StrinIO and don't rewind it, the next write will have | |
# leading zeroes. | |
require 'stringio' | |
s = StringIO.new | |
s.write 'foo' | |
p s.string # => "foo" | |
s.truncate 0 | |
# s.rewind |
This file contains hidden or 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 'irb/xmp' | |
xmp = XMP.new(binding) | |
xmp.puts "foo = 42" | |
xmp.puts "foo" |
This file contains hidden or 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 power_linear(number, exponent): | |
return sum([number * number for _ in range(exponent)]) | |
def power_log(number, exponent): | |
if exponent == 0: | |
return 1 | |
half = power_log(number, exponent / 2) | |
return half * half if exponent % 2 == 0 else number * half * half |
This file contains hidden or 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 permute(sequence, index=0): | |
length = len(sequence) | |
if index > length: | |
raise StopIteration | |
if index == length: | |
yield sequence | |
else: | |
for i in range(index, length): |
This file contains hidden or 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
_.mixin({ | |
// Invalid date predicate. The invalid dates are still `Date` instances, however their time is `NaN`. | |
isInvalidDate: function(obj) { | |
return _.isDate(obj) && _.isNaN(obj.getTime()); | |
} | |
}); |
This file contains hidden or 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 'carmine' | |
# Opinionated client. | |
carmine = Carmine.new( | |
# Default to JavaScript lexing, if that's what the examples | |
# would be written in. | |
:lexer => :javascript, | |
# An image, so we can embed it into presentations. | |
:formatter => :png, | |
:options => { |