Skip to content

Instantly share code, notes, and snippets.

View standingwave's full-sized avatar

Gabriel Williams standingwave

  • Self Employed
  • San Francisco, CA
View GitHub Profile
@lackac
lackac / typocomments2disqus.rb
Created November 19, 2009 16:30
Migrates a blog's comments from the Typo blog engine to Disqus
#!/usr/bin/env ruby
# Author: László Bácsi <lackac@lackac.hu>
require 'rubygems'
require 'httparty'
require 'json'
require 'sequel'
require 'htmlentities'
function GithubBadge(json) {
if (json) {
var badge = new Object();
badge['username'] = json.user.login;
badge['repos'] = _.select(json.user.repositories, function(r) {
return !r.fork && '' != r.description;
}).sort(function() {
return (Math.round(Math.random()) - 0.5);
}).slice(0, 12);
$('#github-badge').html(Jaml.render('github-badge', badge));
/**
IMPORTANT: Requires this version of jquery
until 1.3.3 comes out http://gist.github.com/186325
ALSO: This is very dirty still and has not been
abstracted for use. It is just solving our immediate problems.
Use cases that must pass (and should be tested someday):
* Clicking on links updates layout
* Click around a bit and then use back/forward buttons
module Core
def self.included(mod)
url = ENV['CORE_URL'] ? URI.parse(ENV['CORE_URL']) : URI.parse('postgres://postgres@localhost/heroku')
mod.establish_connection(
:adapter => "postgresql",
:host => url.host,
:username => url.userinfo.split(':')[0],
:password => url.userinfo.split(':')[1],
:database => url.path[1..-1]
)
## /config/initializers/dynamic_job.rb
require 'heroku'
# base class for all jobs that you wish to automatically scale and go down in Heroku
class DynamicJob
#set a cap on maximum number of users ever - just in case.
MAX_CONCURRENT_WORKERS = 100
def initialize
@trevorturk
trevorturk / cache_assets.rake
Created January 13, 2011 17:38
rake deploy and rake cache_assets for heroku
desc "cache assets"
task :cache_assets => :environment do
paths = ['public/javascripts/all.js', 'public/stylesheets/all.css']
puts "-----> caching assets..."
paths.each do |path|
puts "-----> #{path}"
end
#as seen in https://github.com/mooktakim/heroku_deployment
class AppTemplatesController < ApplicationController
def app
render :inline => "SUCCESS", :layout => 'master'
end
def cms
render :inline => "SUCCESS", :layout => 'cms_admin'
end
end
@eric
eric / DISCLAIMER.md
Created March 28, 2011 22:59
Log directly to Papertrail or any remote syslog target from Heroku
def parse filename, content
offset = 0
begin
FasterCSV.parse(content) do |row|
# do stuff
offset += row.to_s.size
end
rescue FasterCSV::MalformedCSVError => e
@file_offset ||= 0
@file_offset += offset
@chanks
chanks / gist:998124
Created May 29, 2011 20:46
Override static asset cache expiration on Heroku.
# Stick the following in an initializer.
module Heroku
class StaticAssetsMiddleware
def cache_static_asset(reply)
return reply unless can_cache?(reply)
status, headers, response = reply
headers['Cache-Control'] = 'public, max-age=31556926' # 1 year