This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ajaxSuccess(function() { | |
jQuery('.wymeditor').wymeditor({ | |
/* options */ | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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(...) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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"] |
OlderNewer