Skip to content

Instantly share code, notes, and snippets.

@markevans
markevans / edit_inline.rb
Created June 6, 2018 14:42
command line tool for inline-editing (edit_inline PATTERN(regexp) REPACEMENT(ruby code outputting string) FILE(path to file))
#!/usr/bin/env ruby
require 'open3'
require 'optparse'
script_name = File.basename($0)
options = {}
option_parser = OptionParser.new do |opts|
opts.banner = <<-HEREDOC
Usage:

Objects

Channel

{
  "id": "251533197-CE3BEA67AA7ADB52D50206C44F9FA5DB",
  "title": "Cable News Network",
  "short_name": "CNN"
}

Program

@markevans
markevans / view_example.js
Created June 8, 2012 16:28 — forked from sjltaylor/view_example.js
Example use of a view, using the class stuff
define(['view'], function(View){
return View.sub('ItemView', function(){
this.domEvent('click', 'button', 'selected')
})
})
@markevans
markevans / view_example.js
Created June 7, 2012 13:49
Example use of a view, using the class stuff
define(['view'], function(View){
return View.sub('ItemView', function(){
this.domEvent('click', 'button', 'selected')
})
})
@markevans
markevans / dragonfly_config_changes.rb
Created March 14, 2012 12:57
Ideas for changing dragonfly configuration API
### EXAMPLE: USING DRAGONFLY WITH S3 ON HEROKU ###
#### CURRENT API #####
# in initializer file
require 'dragonfly'
app = Dragonfly[:images]
app.configure_with(:imagemagick)
@markevans
markevans / async_rack.rb
Created January 12, 2012 11:00
Simplest simplest async rack server (for thin and friends)
class Server
def call(env)
EM.system 'sayBobInOneSecond' do |result, status|
env['async.callback'].call [200, {'Content-Type' => 'text/plain'}, [result]]
end
throw :async
end
@markevans
markevans / gist:1468065
Created December 12, 2011 16:17
Command Line utility for setting the background colour of the OSX terminal
#!/usr/bin/env ruby
if ARGV.length != 1
puts "Usage:"
puts " colour red"
puts "or"
puts " colour '#00ffaa' # NOTE THE QUOTES"
puts "or"
puts " colour rgb(255,0,0)"
exit
@markevans
markevans / async_fibers.rb
Created November 17, 2011 14:55
Async server example with Fibers
require 'fiber'
module Stuff
class << self
def system_call_1
f = Fiber.current
EM.system 'delayedEcho dogs' do |result, status|
f.resume result
end
(function($){
// Simple tabs
// Example markup:
//
// <div data-tabs="tabs">
// <ul>
// <li data-tabs="title" data-tabs-id="fish">...</li>
// <li data-tabs="title" data-tabs-id="egg">...</li>
// </ul>
# Helper file
class Block < BlockHelpers::Base
def initialize(opts={})
@opts = opts
end
def display(body)
content_tag :div, body, :class => "block #{@opts[:class]}"