Skip to content

Instantly share code, notes, and snippets.

@cobbr2
cobbr2 / vehicle_enum.rb
Created August 21, 2012 01:28
Can't get my state_machine to Enum erate
class VehicleEnum
include DataMapper::Resource
property :id, Serial
property :name, String
property :state, Enum[ :parked, :idling ]
state_machine :initial => :parked do
event :ignite do
transition :parked => :idling
@cobbr2
cobbr2 / quoted_printable_htmltext
Last active August 29, 2015 13:56
An email that doesn't decode properly with the MailCatcher and the Mail gem
To: Blah <[email protected]>
From: Me <[email protected]>
Subject: Test quoted-printable HTML mail
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html class=3D"slim"></html>
<p>
@cobbr2
cobbr2 / ruote fancy_log
Last active September 28, 2017 22:31
Ruote "fancy_logging" code table
The abbreviation of an action is the same as its first two letters, *except* for a few that are ambiguous otherwise:
ap | apply
ca | cancel cancel_process
ce | ceased
dc | dispatch_cancel
dd | dispatched
di | dispatch
dp | dispatch_pause
dr | dispatch_resume
@cobbr2
cobbr2 / gist:b1511a530612ebf1fd6c
Last active March 23, 2016 17:09
gem / bundle fail for heroic-sns on travis-ci
rcobb@rcobb-x250: (6280738...) ~/github/benzado/heroic-sns$ ruby --version ; rvm --version ; bundle --version ; gem --version
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
rvm 1.26.11 (latest) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
Bundler version 1.7.6
2.5.1
rcobb@rcobb-x250: (6280738...) ~/github/benzado/heroic-sns$ bundle install --jobs=3 --retry=3
Resolving dependencies...
Using json 1.8.3
Using rake 10.5.0
Using rack 1.6.4
@cobbr2
cobbr2 / Results
Created February 7, 2017 18:21
Trying to understand how Roar parses hypermedia....
rcobb@rcobb-x250: ~/try_tb$ ruby roar_examples.rb
SENT: {"title":"with links","_links":{"self":{"href":"http://junk.example.com/and/nothing/else"}}}
PARSED: #<Song title="with links">
SELF LINK:
rcobb@rcobb-x250: ~/try_tb$
@cobbr2
cobbr2 / no_suppression.rb
Created April 18, 2017 20:14
4 reek UtilityFunction cases; only one should smell
# Test case for disabling utility function smells. Should smell like
# UtilityFunction
class NoSuppression
def utility_function
STDOUT.puts "I'm a utility function"
end
end
#!/usr/bin/env ruby
# Classifies a list of wfids into probably what workflow they come from,
# just based on the name.
require 'pp'
require 'set'
counters = Hash.new(0)
@cobbr2
cobbr2 / parse_audisps
Created July 31, 2019 22:40
Ruby to parse EXECVEs from audispd into something that looks like a shell session.
#!/usr/bin/env ruby
def time(tokens)
if tokens.first =~ /^\d+-\d+-\d+T/
tokens.first
else
tokens[0..2].join(' ')
end
end
@cobbr2
cobbr2 / Output:
Last active April 2, 2020 18:53
Bash `-e` does not propagate to called scripts, but does to functions.
$ ./bash_caller
script: Before failing command
script: After failing command
function: Before failing command