Skip to content

Instantly share code, notes, and snippets.

View rx's full-sized avatar
👾
Bit twiddling

Russell Edens rx

👾
Bit twiddling
View GitHub Profile
@rx
rx / utils-subprocess.rb
Created December 6, 2017 21:36
Slick IO error handling for ruby shelled commands:
# From: https://nickcharlton.net/posts/ruby-subprocesses-with-stdout-stderr-streams.html
require 'open3'
module Utils
class Subprocess
def initialize(cmd, &block)
# see: http://stackoverflow.com/a/1162850/83386
Open3.popen3(cmd) do |stdin, stdout, stderr, thread|
# read each stream from a new thread
{ :out => stdout, :err => stderr }.each do |key, stream|

Keybase proof

I hereby claim:

  • I am rx on github.
  • I am redens (https://keybase.io/redens) on keybase.
  • I have a public key ASAAZ-B-ISv9frXtpgJ7e5tPAz0IkuPlvWUmKeHQHcNrwAo

To claim this, I am signing this object:

@rx
rx / timezones
Created June 14, 2019 23:38
Geotix valid timezones
{"International Date Line West"=>"Pacific/Midway",
"Midway Island"=>"Pacific/Midway",
"American Samoa"=>"Pacific/Pago_Pago",
"Hawaii"=>"Pacific/Honolulu",
"Alaska"=>"America/Juneau",
"Pacific Time (US & Canada)"=>"America/Los_Angeles",
"Tijuana"=>"America/Tijuana",
"Mountain Time (US & Canada)"=>"America/Denver",
"Arizona"=>"America/Phoenix",
"Chihuahua"=>"America/Chihuahua",
@rx
rx / test_page.rb
Last active November 11, 2019 19:34
Voom::Presenters.define(:test_page) do # Registers the presenter named `test_page`
content id: :hello_world do # Provides a content block wrapper with id :hello_world
heading6 "Hello World! #{Time.now}" # Displays the text as a level 6 heading
end
button :click_me do # Defines a button `CLICK ME`
event :click do # Listens for a `click` event on the button
snackbar 'hello world again!' # Displays the text in the snackbar at the bottom of the screen
inserts :hello_world, presenters_url(:hello_world2) # Inserts the contents of the presenter named `hello_world2` into the content block with id: `hello_world`
end
end
@rx
rx / safe-paths-demo-assets.md
Last active April 25, 2020 14:48
Safe Paths Demo Assets

Safe Paths and Safe Places Demo Assets

This doc contains assets use to setup and give a Safe Paths and Safe Places demo.

Demo Sequence/Flow

This is the general outline of the demo. These slides should be used to guide the demo flow/discussion.

Demo Setup

These instructions setup a demo environment for the Safe Paths App and Safe Places tool.

@rx
rx / github-mirrored-repo.md
Created May 27, 2021 20:59
Setting up a mirrored repository on Github

I ran into some issues trying to mirror a repository on Github. This Gist outlines what changes were needed to get it working.

I was attempting to follow these instructions: https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/duplicating-a-repository#mirroring-a-repository-in-another-location

The problem was that the pull refs from Github generate error/warnings (and lots of them). Here is more about that: https://christoph.ruegg.name/blog/git-howto-mirror-a-github-repository-without-pull-refs.html

After issueing the git clone --mirror call I ran the following command to remove the pull request refs: git show-ref | cut -d' ' -f2 | grep 'pull' | xargs -r -L1 git update-ref -d

@rx
rx / response.rb
Created September 8, 2021 11:34
Response Object
class Response
SUCCESS = 0
FAILURE = 1
attr_reader :data, :status, :messages
def initialize(data: [],
status: SUCCESS,
messages: {})
@data = data
@status = status
@rx
rx / service_validation.rb
Created September 8, 2021 12:12
Service Validation Example
module Services
class DoesSomething < BaseService
def initialize(model_ids:)
@model_ids = model_ids
validate_params
end
def call
# Your service logic goes here
@rx
rx / service_dependency_injection
Created September 8, 2021 12:20
Service Dependency Injection
module Services
class DoesSomething < BaseService
def initialize(:some_parameter, :another_parameter,
some_other_service: Services::SomeOtherService.new)
@some_parameter = some_parameter
@another_parameter = another_parameter
end
def call
@rx
rx / app_template.rb
Last active September 28, 2021 15:41
Rails service - application template
ruby_version = '3.0.2'
file '.ruby-version', "ruby-#{ruby_version}\n"
gem 'redis'
gem 'sidekiq'
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem