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 'capistrano/cli' | |
class TranscriptLogger | |
module TranscriptLoggerMetadata | |
attr_accessor :tx_logger_metadata | |
def self.apply_to(object, options={}) | |
object.extend(self) unless object.respond_to?(:tx_logger_metadata) |
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
# encoding: utf-8 | |
s = "Blah \xe9 blah 헌글" | |
puts "BEFORE" | |
puts "encoding: #{s.encoding}" | |
puts "valid : #{s.valid_encoding?}" | |
puts "text : #{s}" | |
s = s. |
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 'optparse' | |
module WordPicker | |
def pick | |
self[rand(length)] | |
end | |
LENGTHS = [1] + [2]*3 + [3]*4 + [4]*4 + [5]*4 + [6]*3 + [7]*2 + [8] | |
def sentence | |
words = [] |
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 'benchmark' | |
N = 100_000 | |
SIZE = 10 | |
array_1d = Array.new(SIZE * SIZE, 0) | |
array_2d = Array.new(SIZE) { Array.new(SIZE, 0) } | |
Benchmark.bm do |bm| | |
bm.report("1d.dup") { N.times { array_1d.dup } } |
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
/* Returns the number of bytes needed to represent the given | |
* Javascript string in UTF-8. */ | |
String.prototype.byteSize = function () { | |
var bytes = 0; | |
for(i = 0; i < this.length; i++) { | |
var charCode = this.charCodeAt(i); | |
if (charCode <= 0x7F) | |
bytes += 1; | |
else if (charCode <= 0x7FF) | |
bytes += 2; |
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
class Resources::Assets < Webmachine::Resource | |
def content_types_provided | |
@asset = Application.assets[request.uri.path] | |
if @asset.present? | |
[[@asset.content_type, :to_asset]] | |
else | |
accept = request.headers['Accept'] || "text/html" | |
[[accept.split(/,/).first.split(/;/).first.strip, :to_html]] | |
end |
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
RSpec::Matchers.define :not_to do | |
match { |actual| !actual } | |
end | |
RSpec.describe "Mater" do | |
specify "says `to not to' to mean false" do | |
expect(false).to not_to | |
expect(true).not_to not_to | |
end | |
end |
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 'chunky_png' | |
class Cell | |
attr_reader :row, :col | |
def initialize(row, col) | |
@row, @col = row, col | |
@links = {} | |
end |
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
# -------------------------------------------------------------------- | |
# An implementation of Aldous-Broder's algorithm for generating mazes. | |
# This is an easy one to implement, but it is also one of the | |
# "dumbest" (meaning least intelligent) algorithms. It is not even | |
# guaranteed to finish, if you get really unlucky with the RNG. | |
# Watching the animation of its progress can be an exercise in | |
# frustration as you find yourself urging the cursor to JUST GO | |
# OVER THERE! Try and it see for yourself. :) | |
# -------------------------------------------------------------------- | |
# NOTE: the display routine used in this script requires a terminal |
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
# Inspired by a church billboard that read: | |
# "When I becomes we, illness becomes welness" | |
# | |
# usage: | |
# > ruby change-x-for-y.rb i we | |
# illness wellness | |
# inch wench | |
# it wet | |
# ... |