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
| #!/usr/bin/env ruby | |
| # It's ODM (Object Document Mapper) to the RGB data | |
| class RGB | |
| COLORS = { | |
| r: ->(val) { "\e[31m#{val}\e[0m" }, | |
| g: ->(val) { "\e[32m#{val}\e[0m" }, | |
| b: ->(val) { "\e[34m#{val}\e[0m" }, | |
| }.freeze |
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
| #!/usr/bin/env ruby | |
| # It's ODM (Object Document Mapper) to the RGB data | |
| class RGB | |
| # @overload initialize(r, g, b, value) | |
| # @param r [Integer] Value for R | |
| # @param g [Integer] Value for G | |
| # @param b [Integer] Value for B | |
| # @param value [Object] describe value param | |
| # @overload initialize(r, g, b) |
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 running queries (pre 9.2) | |
| SELECT procpid, age(clock_timestamp(), query_start), usename, current_query | |
| FROM pg_stat_activity | |
| WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' | |
| ORDER BY query_start desc; | |
| -- show running queries (9.2) | |
| SELECT pid, age(clock_timestamp(), query_start), usename, query | |
| FROM pg_stat_activity | |
| WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' |
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 'nokogiri' | |
| require 'cgi' | |
| xml = <<~XML | |
| <export> | |
| <row> | |
| <CODIGO>13213215</CODIGO> | |
| <MERCADORIA>Exemplo <1</MERCADORIA> | |
| <II></II> | |
| <PIS></PIS> |
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 BooleanValue | |
| # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/column.rb#L8 | |
| FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'] | |
| def self.from_string(value) | |
| Rails.present? ? with_rails(value) : without_rails(value) | |
| end | |
| private |
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
| # Aws::VERSION | |
| # => "2.11.97" | |
| credentials = Aws::Credentials.new(ENV['AWS_KEY'], ENV['AWS_SECRET']) | |
| client = Aws::S3::Client.new(credentials: credentials) | |
| s3 = Aws::S3::Resource.new(credentials: credentials) | |
| s3_bucket = s3.bucket(ENV['BUCKET']) | |
| # https://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Client.html#put_object_acl-instance_method | |
| s3_bucket.objects(prefix: 'path/to/directory').each do |obj| | |
| client.put_object_acl(bucket: s3_bucket.name, key: obj.key, acl: 'public-read').to_h |
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
| module ViewAssigns | |
| def self.included(base) | |
| puts "Included #{ self }/#{self.singleton_class} into #{base}/#{base.singleton_class}" | |
| class << base | |
| attr_accessor :assigns | |
| def assign(name, value = nil) | |
| self.assigns ||= {} | |
| self.assigns[name] = value |
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 A | |
| def name | |
| @name ||= rand | |
| end | |
| end | |
| class B | |
| # Ruby Memoization using Singleton Method | |
| def name | |
| def self.name; @name; 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
| # this monit config goes in /etc/monit/conf.d | |
| check process puma_master | |
| with pidfile /data/myapp/current/tmp/puma.pid | |
| start program = "/etc/monit/scripts/puma start" | |
| stop program = "/etc/monit/scripts/puma stop" | |
| group myapp | |
| check process puma_worker_0 | |
| with pidfile /data/myapp/current/tmp/puma_worker_0.pid |
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
| #!/usr/bin/env ruby | |
| require 'net/telnet' | |
| key_prefix = 'www.your:prefix' | |
| cache_dump_limit = 1000 | |
| localhost = Net::Telnet::new("Host" => "localhost", "Port" => 11211, "Timeout" => 3) | |
| slab_ids = [] | |
| localhost.cmd("String" => "stats items", "Match" => /^END/) do |c| | |
| matches = c.scan(/STAT items:(\d+):/) |