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
| 1.9.3-p429 |
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 "base64" | |
| require "digest" | |
| require "openssl" | |
| # openssl req -in <csr_file> -noout -pubkey | |
| def extract_public_key_from_csr(csr_file) | |
| csr = OpenSSL::X509::Request.new(File.read(csr_file)) | |
| csr.public_key.to_pem | |
| 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
| def each_chunk(io, chunk_size = 1024 * 1024) | |
| return enum_for(:each_chunk, io, chunk_size) unless block_given? | |
| loop do | |
| break if io.eof? | |
| yield io.read(chunk_size) | |
| end | |
| end | |
| def scan(io, search_term, buffer_size) |
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
| # Define a method as both an instance & class method | |
| class Foo | |
| def self.bar | |
| end | |
| # Note: this requires Rails/Active Support - not sure if it can be done with Forwardable | |
| delegate :bar, to: "self.class" | |
| 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
| #!/bin/sh | |
| # Takes a file path as input and echoes it back to STDOUT with a newline inserted between every adjacent > and < characters | |
| sed 's/\>\</\>\ | |
| \</g' < $1 |
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
| ; Trying to figure out how namespaced elisp functions work: https://www.greghendershott.com/2017/02/emacs-themes.html | |
| (defun dh/foo (x) | |
| "adds 4 to x" | |
| (+ x 4)) | |
| (dh/foo 1) | |
| (defun dh/bar (x, fn) | |
| "adds 5 to fn(x)" | |
| (+ 5 (fn x))) | |
| (dh/bar 7 #'dh/foo) |
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
| # Add following to enable debug logging of Resque internals | |
| Resque.logger = Logger.new(STDOUT) | |
| Resque.logger.level = Logger::DEBUG | |
| # Use resque-retry plugin for automatic retries | |
| class SomeJob | |
| extend Resque::Plugins::Retry | |
| end | |
| # The scheduler process must be running to perform retries - if not running, the job |
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
| # How to stub out Faraday for testing | |
| # The last middleware in the list is the innermost one and must be the HTTP adapter. | |
| # Generally, it will be a single argument (a symbol), such as :net_http | |
| # | |
| # For example: | |
| # | |
| Faraday.new(url: 'http://example.com') do |conn| | |
| # POST/PUT params encoders: | |
| conn.request :multipart |
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
| # Conditional Routing in Rails | |
| # Send requests matching the same path to different controller actions based on information in the request | |
| # http://bjedrocha.com/rails/2015/03/18/role-based-routing-in-rails/ | |
| class ThingsConstraint | |
| def initialize(*names) | |
| @matches = names | |
| end | |
| def matches?(request) |