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 SampleContracts | |
BASE_PATH = "downloads/sample_contracts/" | |
Contract = Struct.new(:type, :name, :title) do | |
# Struct responds to .call so it can be used for Enumerable.find(ifnone) | |
def self.call | |
new | |
end | |
# By adding this method we get a struct that plays nicely with destructuring |
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 Configuration | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
end | |
end | |
class ModuleBuilder |
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
# Example of prototyping models with a mix of ActiveRecord and Virtus | |
# | |
# Useful with large models where some fields are in flux during spiking/dev | |
# and you don't want or need to run migrations to try ideas out. | |
class A < ActiveRecord::Base | |
# ... | |
# belongs_to | |
# has_many |
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 "active_support/all" | |
class Event | |
STATES = %w(active archived) | |
def self.types(&block) | |
return to_enum(__callee__) unless block | |
types = { |
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 'thread' | |
q = Queue.new | |
(0..1000).each{ |i| q << i } | |
puts q.length | |
Thread.new do | |
sleep 1 | |
puts "FIRST #{q.pop}" | |
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
# $: << File.expand_path("../../recipes", __FILE__) | |
# Don't worry about the load path man, Capistrano's got your back! | |
module Capistrano | |
if const_defined? :Configuration | |
Configuration.instance(true).load do | |
@load_paths << File.expand_path("../recipes", __FILE__) | |
load "log" | |
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
# encoding: utf-8 | |
class DocumentUploader < CarrierWave::Uploader::Base | |
include ::CarrierWave::Backgrounder::Delay | |
include CarrierWave::MimeTypes | |
# Include RMagick or MiniMagick support: | |
include CarrierWave::RMagick | |
# include CarrierWave::MiniMagick | |
include CarrierWave::UNOConv |
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
Show hidden characters
{ | |
"cmd": ["open","-a","/Applications/Marked.app","$file"], | |
"selector": "text.html.markdown", | |
"variants": [ | |
{ | |
"cmd": ["open","-a","/Applications/Marked.app","$file"], | |
"name": "Open in Marked" | |
} | |
] | |
} |
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
net = require "net" | |
sugar = require "sugar" | |
chatServer = net.createServer() | |
clientList = [] | |
chatServer.on "connection", (client) -> | |
client.name = "#{client.remoteAddress}:#{client.remotePort}" | |
client.write "Hi! #{client.name}!\n" | |
console.log "#{client.name} joined" |
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
STDOUT.sync = true | |
require "net/ftp" | |
root = "tgftp.nws.noaa.gov" | |
total = 0 | |
run = true | |
puts ">> Probing max connections for: #{root}" |