Skip to content

Instantly share code, notes, and snippets.

View toolmantim's full-sized avatar
:shipit:
🎉

Tim Lucas toolmantim

:shipit:
🎉
View GitHub Profile
# To be stuck in the top of your Sinatra app or whichever file you want to
# declare the gems.
#
# Use this to ensure you use the same local gems as you do in production.
# Check it's a file as Heroku replaces .gems with a dir full of gems
File.file?(gems_file = "#{File.dirname(__FILE__)}/.gems") && File.read(gems_file).each do |gem_decl|
gem_name, version = gem_decl[/^([^\s]+)/,1], gem_decl[/--version ([^\s]+)/,1]
version ? gem(gem_name, version) : gem(gem_name)
end
require 'rubygems'
require 'eventmachine'
class IChatTracker < EM::Protocols::LineAndTextProtocol
def receive_line(line)
puts line
end
end
EM.run do
> telnet 127.0.0.1 8000
Trying 127.0.0.1...
Connected to ticketsystem.local.
Escape character is '^]'.
GET / HTTP/1.1
HTTP/1.1 200 OK
Content-Type: text/event-stream
Cache-Control: no-cache
Connection: keep-alive
So I asked about conditionals in Rake and basically everybody
told me the concept is ridiculous, but I could maybe use invoke.
I'm thinking maybe I asked the wrong question, so here's some more
detail so we can either find me a viable solution or confirm I'm crazy.
I have a rake task that combines and minifies all my CSS and JS into
one file each. I want to automate that task so that it runs before
each deploy.
Ideally, I type 'cap deploy' as per normal, it runs the minifier tasks,
(function () {
if (!window.fluid) return;
// Dock badge unread messages
setInterval(function() {
var m = document.title.match(/\((\d+)\)/);
window.fluid.dockBadge = m ? parseInt(m[1]) : '';
}, 1000);
module Haml
module Filters
module Coffeescript
include Base
def render_with_options(text, options)
<<END
<script type=#{options[:attr_wrapper]}text/coffeescript#{options[:attr_wrapper]}>
#{text.rstrip.gsub("\n", "\n ")}
</script>
END
# Configure ActionMailer
require 'action_mailer'
ActionMailer::Base.template_root = options.views
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => "25",
:authentication => :plain,
:user_name => "username@domain.com",
:password => "yourpassword"
}
desc "Boot up the app"
task :default do
exec "ruby -rrubygems myapp.rb -p 4567"
end
desc "Boot up the app with shotgun (uses config.ru)"
task :shotgun do
exec "shotgun -rinit -o 0.0.0.0 -p 4567"
end
// For today's WTF moment, I present to you:
//
// The wp_get_archives function from WordPress 2.9.2 (the latest)
//
// ...but wait, there's more! The total line count for the file this
// can be found in (general-template.php): 2049 lines.
//
// Save me jeebas!
function wp_get_archives($args = '') {
global $wpdb, $wp_locale;
# In answer to: http://twitter.com/jimwhimpey/status/11727440383
#
# "I want to output 10 Flickr photos one at a time as the REST response
# is returned for each rather than wait for all 10."
class FlickrStreamer
def initialize(photos)
@photos = photos
end
def each