Skip to content

Instantly share code, notes, and snippets.

@dmcclory
dmcclory / requester.rb
Created February 22, 2019 16:44
Septa Demo with Elm + Sinatra
# myapp.rb
require 'sucker_punch'
require 'sinatra/base'
require 'http'
require 'json'
class SimpleCache
attr_reader :data
@dmcclory
dmcclory / ActiveRecordRelation#or.rb
Last active June 26, 2017 01:54 — forked from dicemanx/ActiveRecordRelation#or.rb
Reproduction of a possible bug in ActiveRecord_AssociationRelation#or
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.
@dmcclory
dmcclory / object_broswer.rb
Last active December 23, 2015 15:39
at startup, create a Hash of all the objects. then explore.
objects = Hash.new {|h, c| h[c] = Array.new }
ObjectSpace.each_object do |o|
objects[o.class] << o
end
require 'pry'; binding.pry
@dmcclory
dmcclory / sucker_punch.rb
Last active December 19, 2015 04:39 — forked from brandonhilkert/sucker_punch.rb
use a method_added callback to realias the methods after the base class version of #perform is defined.
require 'celluloid'
require 'pry'
module SuckerPunch
module Job
def self.included(base)
base.send(:include, ::Celluloid)
base.class_eval do
@dmcclory
dmcclory / gist:5140631
Created March 12, 2013 05:50
essence of what man does
def troff_stuff
Zlib::GzipReader.open(@file) do |troff|
troff.read
end
end
def exec_groff_less
IO.popen("groff -Wall -pt -mandoc -Tascii | less -J", 'w') do |io|
io.write troff_stuff
end
@dmcclory
dmcclory / gist:3909704
Created October 18, 2012 03:26
my remove backups rake task
task :rmbak do
Dir["**/**~"].each do |f| ## "**/**" selects everything
puts "removing #{f}" ## works in ruby, but isn't recursive on command line
FileUtils.rm(f)
end
puts "rmbak: complete"
end
@dmcclory
dmcclory / gist:3908513
Created October 17, 2012 21:49
escape a list of elements
CGI.escapeElement( Ox.dump(@doc), "p", "div", "span", ... )
@dmcclory
dmcclory / copy_folder.rb
Created August 23, 2012 21:23
Copying the contents of one directory to another
# you want to recursively copy the contents of one folder to another
# but you don't want to actually copy the first folder into the second
#3 ways to try to copy the contents of one directory to another:
require 'pathname'
require 'fileutils'
include FileUtils
p = Pathname.new('input')
o = Pathname.new('output')
@dmcclory
dmcclory / pathname_collections.rb
Created August 22, 2012 22:08
functions which return all the files or all of the directories contained within a Pathname
def collect_files(pn)
if pn.file?
return pn
end
pn.children.collect {|cn| collect_files(cn)}.flatten
end
def collect_directories(pn)
if pn.directory?
pn.children.collect {|cn| collect_directories(cn)}.flatten.reject{|i| i.nil?}.push(pn)
@dmcclory
dmcclory / podcast_spike.html
Created September 15, 2015 20:09
Javascript control of audio elements
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
<h1>Yo a Podcast episode!</h1>
<audio controls src="http://traffic.libsyn.com/ucblongform/Karin_Louise_Hammerberg.mp3" type="audio/mpe
g">
Your browser does not support the <code>audio</code> element.
</audio>