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
package main | |
import ( | |
"bytes" | |
"database/sql" | |
"encoding/csv" | |
"errors" | |
"fmt" | |
_ "github.com/lib/pq" | |
) |
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
package reflectiontest | |
import "reflect" | |
type ThingWithId struct { | |
Id string | |
Name string | |
} | |
type ThingWithoutId struct { |
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 'erb' | |
require 'binding_of_caller' | |
GENERATED_CLASS_FOR_MESSAGE = <<-CLS | |
class <%= name %> | |
attr_reader <%= message.fields.map {|name, _| ':' + name.to_s }.join(', ') %> | |
def initialize | |
<% message.fields.each do |name, field| %> | |
<%= field.to_s %> | |
<% 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 'json' | |
class PostsController | |
def create | |
CreatePost.new(params) | |
.on_success(&-> { | |
render json: {}, status: 200 | |
}) | |
.on_failure(&-> { | |
render json: {errors: {name: ["can't be blank"]}}, status: 422 |
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 'thor' | |
class BootstrapApp < Thor | |
include Thor::Actions | |
desc "create", "Create a Twitter Bootstrap app" | |
method_option :database, aliases: '-d', type: :string, desc: 'The database adapter to use: sqlite3 oracle mysql2 etc.', default: 'sqlite3' | |
method_option :test, aliases: '-t', type: :string, desc: 'The test framework to use: test-unit rspec-rails etc.', default: 'rspec-rails' |
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
# Paste me into your config/initializers directory. | |
class Object | |
def try(*args) | |
message, *other_args, options = *args | |
if options.is_a?(Hash) && options[:force] | |
self && self.public_send(message, *other_args) | |
else | |
raise NoMethodError, <<-MSG | |
Stop! Hold everything! |
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
g() { | |
if [[ $# > 0 ]]; then | |
git "$@" | |
else | |
git status | |
fi | |
} | |
source "/usr/local/etc/bash_completion.d/git-completion.bash" | |
__git_complete g _git |
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 'httparty' | |
class HTTPGetter | |
include HTTParty | |
base_uri 'http://google.com' | |
end | |
class LoggingDecorator < SimpleDelegator | |
def initialize(thing, logger) | |
super(thing) | |
@logger = logger |
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 'csv' | |
ORDERING_FREQUENCY = ['Monday', 'Thursday', 'Wednesday'] | |
def date_of_next(day, anchor) | |
anchor + 0.upto(6).find {|i| Date::DAYNAMES[(anchor + i).wday] == day } | |
end | |
people = CSV.parse(File.read(ARGV[0])).shuffle | |
start = Date.parse(ARGV[1]) rescue Date.today | |
schedule = ORDERING_FREQUENCY.cycle.take(30).map {|day| start = date_of_next(day, start) } |
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
cf ssh $APP_NAME -c 'export PATH=~/app/vendor/ruby-2.3.1/bin:~/app/bin:$PATH && gem install bundler && bundle exec rails c production' |
OlderNewer