Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
# Clean up the stale cached files from a theme
rake themes:uncache
# Restart the server: necessary to reload classes etc in production mode
touch tmp/restart.txt
namespace :themes do
desc "Clear out old cached versions of theme files"
task :uncache do
Dir[File.join(RAILS_ROOT, "themes/*")].each do |theme|
%w(images javascripts stylesheets).each do |dir|
if File.directory?(File.join(theme, dir))
Dir[File.join(theme, dir, "*")].each do |file|
dest = File.join RAILS_ROOT, "public", dir, File.basename(file)
if File.exist?(dest) && File.mtime(dest) < File.mtime(file)
puts "X #{dest}"
#!/bin/sh
# Clean up the stale cached files from a theme
rake themes:uncache
# Restart the server: necessary to reload classes etc in production mode
touch tmp/restart.txt
#!/usr/bin/env ruby
# Find common Twitter friends
# Usage: ./twat.rb user1 user2 ...
lists = ARGV.inject({}) do |hash, username|
page = 1
friends = []
while !(output = `curl -s http://twitter.com/statuses/friends/#{username}.xml?page=#{page} | grep "<screen_name>"`.gsub(%r{</?screen_name>}, '').split).empty?
friends += output
page += 1
$(document).ajaxSuccess(function() {
jQuery('.wymeditor').wymeditor({
/* options */
});
});
def response_keys
d = {}
responses.genuine.find_in_batches(:batch_size => 100) do |batch|
batch.each { |response| d.merge! response.data }
end
d.keys - [ "id" ]
end
# Custom types are scoped to a particular site instance,
# so their class names are suffixed with the site ID.
# This also helps Content#const_missing figure out when we're
# trying to load a custom type, because it gets numbers at the
# end of the class name.
# Note: I've put some validation logic in CustomType to ensure
# that the name in the database is a valid Ruby constant name.
# new_custom_type = Content::CustomType.create(:site_id => 1, :name => "My custom type")
# Content::MyCustomType1 #=> Content::MyCustomType1(...)
#!/usr/bin/env ruby
words = {}
stop_words = File.open("stop.txt") { |file| file.read.split }
def valid?(word)
case word
when /^\@/ then false # reject @usernames
when /^\#/ then true # keep #hashtags (separate from the word 'hashtags')
when /\.+/ then false # reject things that look like URLs
class SomeClass < ActiveRecord::Base
def object_from_yaml_with_dmatrix_support(string)
if string.is_a?(String) && string =~ /^Linalg\:\:DMatrix/
eval string
else
object_from_yaml_without_dmatrix_support(string)
end
end
alias_method_chain :object_from_yaml, :dmatrix_support
end
# Allow the metal piece to run in isolation
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
# Speeds up the presentation of static files by not going through Rails at all.
# TODO: streaming for large files
class StaticFiles
MAX_FILE_SIZE = 262_144 # 256KB
def self.call(env)
static_file_name = File.join Rails.root, "assets", env["SERVER_NAME"], "original", env["PATH_INFO"]