Setup remote repository:
ssh git@example.com
mkdir my_project.git
cd my_project.git
git init --bare
On local machine:
cd my_project
# importer/exporter interaction via fibers | |
require 'fiber' | |
class Importer | |
DATA = [ | |
["foo", "bar"], | |
["jazz", "quux"], | |
["cats", "dogs"] | |
] |
Setup remote repository:
ssh git@example.com
mkdir my_project.git
cd my_project.git
git init --bare
On local machine:
cd my_project
# lib/attachable_sti_type.rb | |
class AttachableStiType < ActiveRecord::Type::String | |
def cast_value(value) | |
if value =~ /\A([a-z]+)\/([a-z]+)\Z/ | |
"#{$2}/#{$1}_record".classify | |
else | |
super | |
end | |
end |
[:foo, :bar].map(&{ bar: "BAZ", foo: "QUUX" }) |
class Invoice < ApplicationRecord | |
include JsonModel::Attribute | |
json_attribute_model :payment, Payment | |
validates_associated :payment | |
end |
class UniqueCollectedValidator < ActiveRecord::Validations::UniquenessValidator | |
def initialize(options) | |
unless options[:within].present? | |
raise ArgumentError, ":within option is required to determine the unique scope's collection." | |
end | |
unless Array(options[:within]).all? { |within| within.respond_to?(:to_sym) } | |
raise ArgumentError, "#{options[:within]} is not a supported format for the :within option. " \ | |
"Pass a symbol or an array of symbols instead: `within: :profiles`" | |
end | |
super |
# include from an initializer | |
module HstoreAccessor | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def hstore_accessor(hstore_attribute, *keys) | |
Array(keys).flatten.each do |key| |
# frozen_string_literal: true | |
module DigestQueries | |
def predicate_builder | |
@predicate_builder ||= super.tap do |pb| | |
pb.register_handler(Digest::Instance, DigestHandler.new(pb)) | |
end | |
end | |
class DigestHandler |
require 'rubygems' | |
require 'nokogiri' | |
require 'csv' | |
f = File.open("table.html") | |
doc = Nokogiri::HTML(f) | |
CSV.open("output.csv", 'w') do |csv| | |
doc.xpath('//table/tbody/tr').each do |row| | |
tarray = [] |
def list((head, *tail)) | |
case tail.length | |
when 0 | |
head&.fetch(:name).to_s | |
when 1 | |
"#{list [head]} & #{list tail}" | |
else | |
"#{list [head]}, #{list tail}" | |
end | |
end |