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|
@rx
rx / math.thor
Last active December 7, 2016 10:04
Command line math flash cards. Requires: Ruby 2 and thor Usage: `gem install thor && thor math:times`
Signal.trap("INT") do
puts ''
system('say "Goodbye!"')
exit 1
end
# A command line math flash cards
class Math < Thor
desc "times", "Practice your times tables - 2 to 12"
@rx
rx / example-dry-auto_inject.rb
Created May 1, 2016 19:26
This is a rework of the example for AutoInject. The example does not run on its own. This one does if you bundle dry-container and dry-auto_inject
require 'dry-container'
require 'dry-auto_inject'
# set up your container
my_container = Dry::Container.new
my_container.register(:data_store, -> { {users:[]} })
my_container.register(:user_repository, -> { my_container[:data_store][:users] })
my_container.register(:persist_user, -> { PersistUser.new })
@rx
rx / uuid.rb
Last active May 1, 2016 17:37
Dry-Type UUID
UUID = Types::Strict::String.constrained(
format: /\A[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}\z/i)
describe UUID do
context 'UUID' do
include Voom::Types
let(:uuid){SecureRandom.uuid}
let(:bad_uuid){uuid+"&"}
it 'should constrain' do
@rx
rx / gist:92f0904395d61d99787ff5ade08a437e
Created April 30, 2016 17:24
El Capitan gem build errors with libv8 and eventmachine
ruby 2.2.5
os x 10.11.4
I moved from rvm to rbenv. When I went to bundle I had build errors with libv8 (3.16.14.7) and eventmachine (1.0.8).
This is what up ended up working.
YMMV
```
brew install gcc
brew link openssl --force
gem install libv8 -v '3.16.14.7' -- --with-system-v8
bundle
@rx
rx / bad_validation_spec.rb
Last active April 30, 2016 04:51
bad dry-validation 0.7.4 spec
describe "Bad Validation Spec" do
subject {
Dry::Validation.Form do
key(:id).required
key(:foo).schema do
optional(:bar).maybe
optional(:goo).maybe
optional(:zurb).maybe # comment this line out and it works
end
end
@rx
rx / zurb-ink-650.css
Last active February 6, 2016 11:02
Zurb Ink converted to 650px wide.
/**********************************************
* Ink v1.0.5 - Copyright 2013 ZURB Inc *
**********************************************/
/* Client-specific Styles & Reset */
#outlook a {
padding: 0;
}
<select id="<%= options.id %>" name="<%= options.name %>"
<% if((!options.blank && collection.size()==0) ||
options.disabled ){ %>
disabled="disabled"
<% }; %>
>
<% if(options.blank){ %>
<option value=''><%= options.blank %></option>
<% }; %>
<% collection.each(function(item) { %>
@rx
rx / gist:1118201
Created August 1, 2011 14:18 — forked from cmorss/gist:1076315
Jammit Handlebar Template funciton
Handlebars.template = function(templateString) {
return function () {
if (arguments.length < 1) {
// With no arguments, return the raw template -- useful for rendering
// partials.
return templateString;
} else {
Handlebars.templates = Handlebars.templates || {}
Handlebars.templates[templateString] = Handlebars.templates[templateString] || Handlebars.compile(templateString);
return Handlebars.templates[templateString](arguments[0], arguments[1]);
namespace :gem do
begin
require 'jeweler'
gem_name = 'voomify-jobs'
Jeweler::Tasks.new do |gem|
gem.name = gem_name
gem.summary = 'Voomify jobs engine for Rails 3.'
gem.files = Dir['{lib}/**/*', '{app}/**/*', '{config}/**/*']
gem.author = 'Russell Edens'
gem.email = 'russell@voomify.com'