Skip to content

Instantly share code, notes, and snippets.

@tatey
tatey / 1_form.rb
Last active December 13, 2015 22:09
class RetrieverForm
include ActiveModel::Conversion
include ActiveModel::Validations
validate :existance_of_email
def initialize(attributes = {})
@email = attributes[:email]
end
require 'heroku-api'
require 'tmpdir'
branch = ''
git_url = ''
heroku_host = ''
heroku_key = ''
app_name = "t8y-#{branch.downcase.gsub('_', '-').gsub(/[^a-z0-9\-]/, '')}"
heroku = Heroku::API.new(api_key: heroku_key)
def hash2openstruct(attributes)
attributes = attributes.reduce({}) do |attributes, (name, value)|
if value.is_a?(Hash)
value = hash2openstruct(value)
elsif value.is_a?(Array)
value = value.map { |v| hash2openstruct(v) }
end
attributes[name] = value
attributes
end
require 'ostruct'
# ClosedStruct is similar to OpenStruct, except:
#
# * Immutable. Cannot be changed after insantiation.
# * Raises NoMethodError on undefined attributes instead of returning nil.
#
# Example:
# struct = ClosedStruct.new do |attributes|
# attributes.name1 = 'value1'
class Hook
attr_reader :payload
def initialize(payload)
@payload = payload
end
def operation_attributes
send(:"#{action}_operation_attributes")
end
@tatey
tatey / delayed_job
Created March 12, 2013 06:55
Delayed Job, Rails 4 and Capistrano
#!/usr/bin/env ruby
require_relative '../config/boot'
require_relative '../config/environment'
require 'delayed/command'
Delayed::Command.new(ARGV).daemonize
# RecursiveClosedStruct is similar to OpenStruct, except:
#
# * Immutable. Cannot be changed after instantiation.
# * Raises NoMethodError on undefined methods instead of returning nil.
# * Recursively coerces descendants into a RecursiveClosedStruct.
#
# NoMethodError example:
# struct = RecursiveClosedStruct.new(key1: "value")
# struct.key1 # => "value"
# struct.key2 # => NoMethodError
class ViewController
include TableSection
def numberOfSectionsInTableView(tableView)
2
end
def numberOfRowsInSection0(tableView)
@data.count
end
@tatey
tatey / 0_0.js
Last active December 15, 2015 08:59
// Create a function on the controller that computes propA
// and popC.
function ModelCtrl($scope) {
$scope.models = [{propA: 'A', probB: 'B'}];
$scope.propC = function(model) {
return model.propA + model.propB;
}
}
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __FILE__)
require 'bundler/setup'
require 'sequel'
if ARGV.size != 2
puts "usage: #{__FILE__} <DATA_PATH> <DB_PATH>"
puts " #{__FILE__} ~/Desktop/sites.txt ~/Desktop/database.sqlite"
abort