It's common in Ruby to see some code setup a Struct
like this:
class Specialized < Struct.new(:whatever)
# ... define custom methods here...
end
require "rubygems" | |
require "bundler/setup" | |
require "sinatra" | |
require "base64" | |
get "/" do | |
Base64.encode64(File.binread("image")) | |
end |
Fedifeed implementation notes | |
Two components | |
Server implements a few endpoints | |
/reblogs — returns accounts that you reblog the most | |
/core_servers — returns the instances who host most of the accounts you follow | |
/favourites — returns users that you favourite the most | |
Client hits those endpoints, and then: |
#!/usr/bin/env ruby | |
# You should ensure that the `rmagick` and `a2_printer` gems are installed. | |
require "rubygems" | |
require "RMagick" | |
require "a2_printer" | |
if ARGV.length < 2 | |
puts "Usage: convert_image_to_bytes.rb <image_file> <output_file>" |
$ ruby huffman.rb this is a test of compression | |
input length in bits 232 (29 * 8) | |
Binary 1111100000100011001000110100101101111101000111111001111100110111010111001110001101111010000001001110110 | |
Encoded string length in bits: 103 | |
Compression: 44.396551724137936% | |
Decoded: this is a test of compression |
module Refinement | |
refine Object do | |
def new_method | |
'new method!' | |
end | |
end | |
end | |
class Thing | |
using Refinement |
/*--------------------- Layout and Typography ----------------------------*/ | |
body { | |
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif; | |
font-size: 15px; | |
line-height: 22px; | |
color: #252519; | |
margin: 0; padding: 0; | |
} | |
a { | |
color: #261a3b; |
select substring(md5(<first salt> || proposal_id) for 8) as proposal_hash, substring(md5(<second salt> || user_id) for 8) as user_hash from selections; |
class Thing | |
def self.runner=(custom_runner) | |
@runner = custom_runner | |
end | |
def self.runner | |
@runner ||= new | |
end | |
def run(*args) |
describe ThingController do | |
describe "creating a thing" do | |
action { post :create, attributes } | |
describe "when not logged in" do | |
it "should redirect to login" do | |
assert_redirected_to login_path | |
end | |
end |