Skip to content

Instantly share code, notes, and snippets.

## /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

I have a Rails 3 application; we can consider it a blog system. All content is stored in Nodes. I am using a specifically tailored route to allow Nodes to have clean URLs.

= form_for [:admin, @node] do                        # => generated URL is /admin/nodes or /admin/nodes/4d1a44571d41c821eb000006
= link_to 'all nodes', nodes_path                    # => generated URL is /
= link_to @node.title, node_path(@node.to_path)      # => generated URL is /about or /about/people or /4d1a44571d41c821eb000006
= link_to 'all nodes (admin view)', admin_nodes_path # => generated URL is /admin/nodes
= link_to 'add', new_admin_node_path                 # => generated URL is /admin/nodes/new
= link_to 'edit', edit_admin_node(@node)             # => generated URL is /admin/nodes/4d1a44571d41c821eb000006/edit
= link_to 'delete', [:admin, @node], :confirm => 'Are you sure?', :method => :delete

=> generated URL is /admin/nodes/4d1a44571d41c8

@anarchivist
anarchivist / bookmarks_controller.rb
Created January 29, 2011 18:01
Blacklight workaround BookmarksController for Postgres
require_dependency( 'vendor/plugins/blacklight/app/controllers/bookmarks_controller.rb')
class BookmarksController < ApplicationController
def collection
user_id = current_user ? current_user.id : nil
assocations = nil
conditions = ['user_id = ?', user_id]
if params[:a] == 'find' && ! params[:q].blank?
q = "%#{params[:q]}%"
#!/usr/bin/env jython
# This is a Jython Servlet wrapper for FITS <http://code.google.com/p/fits/>
#
# INSTALL:
# Set the FITS_HOME variable to the location of the FITS package
#
# Some JARs may need to be moved into the endorsed folder (./common/endorsed)
# like jaxon, jdom, saxon, saxpath, and xerces.
#
ie = Dir.glob('/Users/scmac/Desktop/ChrisWeeg/ruby/identical/Enhanced/*')
ir = Dir.glob('/Users/scmac/Desktop/ChrisWeeg/ruby/identical/Raw/*')
junk = "abcdefghijklmnopqrstuvwxyzABCDEFGHILKLMNOPQRSTUVWXYZ"
ie.each {|x| x.delete! junk}
ir.each {|x| x.delete! junk}
ie.each {|x| x.delete! "/"}
ir.each {|x| x.delete! "/"}
@cjweeg
cjweeg / "BagIt" error finder
Created December 20, 2011 20:31
Looks through a "BagIt" Missing-Files-manifest and locates lines where the string "._" does not occur
#!/usr/bin/env ruby
# ARGV[0] should point to the directory where the "BagIt" text file is stored
if !ARGV[0]
puts "You must specify the directory \"BagIt\" text file is stored. Try again!"
exit
end
# first we find the full path of the argument in case we're only given
@simi
simi / Gemfile
Created February 7, 2012 14:32
Refinery + Twitter Bootstrap WIP
source 'https://rubygems.org'
gem 'rails', '3.2.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
Status Code Status Message Symbol
1xx Informational
100 Continue :continue
101 Switching Protocols :switching_protocols
102 Processing :processing
2xx Success
200 OK :ok
201 Created :created
202 Accepted :accepted
@pristinenoise
pristinenoise / blacklight_google_analytics.rb
Created April 9, 2012 15:12
changing to environment friendly
# Change to your Google Web id
BlacklightGoogleAnalytics.web_property_id = case Rails.env.to_s
when 'development'
'UA-3-1'
when 'test'
nil
else
'UA-2-1'
end
@niklasl
niklasl / rdfa_prototypes.html
Created December 9, 2012 08:52
HTML5+RDFa version of <http://d.lib.ncsu.edu/collections/catalog/mc00096-001-ff0155-000-001_0001> using experimental RDFa prototypes
<!DOCTYPE html>
<html>
<head>
<base href="http://d.lib.ncsu.edu/collections/catalog/mc00096-001-ff0155-000-001_0001" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width; initial-scale=1.0">