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] | |
name = "ant" | |
version = "0.1.0" | |
edition = "2021" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
[[bin]] |
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/ruby | |
env = ARGV.shift | |
files = ARGV.map {|f| f.sub(/^\//, '') }.join(',') | |
Kernel.exec "cap #{env} deploy:upload FILES=#{files} deploy:restart" |
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
#option A) | |
stream = StringIO(string) | |
stream.content_type = 'application/pdf' #paperclip adds silly attr accessors to StringIO that we need to pass validations | |
#stream.original_filename = "anything.pdf" #if needed... | |
signed_pdf_document.original_pdf = stream | |
signed_pdf_document.save | |
#option B) | |
file = Tempfile.new( ["file_name", '.pdf'] ) |
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
def back_and_fore_color(color) | |
rgb = color.sub('#','').scan(/../).map {|c| c.to_i(16)} | |
fore_color = rgb.sum > 384 ? 'black' : 'white' | |
"background-color:#{color};color:#{fore_color};" | |
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
class Enum < Hash | |
def initialize(*members) | |
super() | |
@rev = {} | |
members.each_with_index {|m,i| self[i] = m } | |
end | |
def [](k) | |
super || @rev[k] # || raise ArgumentError, "#{k} is not a member of this enum" | |
end | |
def []=(k,v) |
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
#tl;dr - user :extend, embrace module explosion. | |
#delegates are a classic and simple tool here, they allow you to mass produce simple forwarding functions to be replaced as needed. this is exactly what LOD is all about. | |
# first of all, without knowing the code I'd reject the claim that knowing how to stop a subset of workers is the factory's concern rather than the Worker class (not instance). in which case - why pass a factory instance at all? the following will work. | |
class Factory | |
has_many :machines, :inverse_of=>:factory | |
delegate :stop, :start, :eat, :to=>machines, :prefix=>true | |
end |