Skip to content

Instantly share code, notes, and snippets.

View briandemant's full-sized avatar
💭
is happy coding

Brian Demant briandemant

💭
is happy coding
View GitHub Profile
@briandemant
briandemant / cache_middleware.coffee
Created November 4, 2012 13:40 — forked from turtlesoupy/nginx.conf
node.js upstream nginx config
cacheMiddleware = cacheMiddleware = (seconds) -> (req, res, next) ->
res.setHeader "Cache-Control", "public, max-age=#{seconds}"
next()
app.get "/recent", cacheMiddleware(5 * 60), (req, res, next) ->
#When someone hits /recent, nginx will cache it for 5 minutes!

GitHub Javascript Strategy

Unless otherwise necessary (such as mobile development), the GitHub javascript codebase is based off jQuery. You can safely assume it will be included on every page.

File naming

  • All jquery plugins should be prefixed with jquery, such as jquery.facebox
  • All github-specific jquery plugins should be prefixed with jquery.github. Like jquery.github.repo_list.js
  • All page-specific files (that only run on ONE page) should be prefixed with page. page.billing.js
require 'digest/sha1'
module EasyAuth
# http://techspeak.plainlystated.com/2010/03/drop-dead-simple-authentication-for.html
# To generate a hashed password (in irb):
# require 'easy_auth'
# EasyAuth.hash('my_password') # Put this in AUTHORIZED_USERS
AUTHORIZED_USERS = {
# a simple/configurable rake task that generates some random fake data for the app (using faker) at various sizes
# NOTE: requires the faker gem - http://faker.rubyforge.org - sudo gem install faker
require 'faker'
class Fakeout
# START Customizing
# 1. first these are the model names we're going to fake out, note in this example, we don't create tags/taggings specifically
@briandemant
briandemant / Gemfile
Created January 29, 2010 23:24 — forked from rmanalan/.gems
gem 'rack-contrib', :git => 'git://github.com/rack/rack-contrib.git'
gem 'rack-rewrite'
module Spec::DSL::Main
alias :Feature :describe
def Story(description)
@description_args.push("\n#{description}\n")
end
end
module Spec::Example::ExampleGroupMethods
def executes(scope=:all, &blk)
before(scope, &blk)
# Build an inverted index for a full-text search engine with Redis.
# Copyright (C) 2009 Salvatore Sanfilippo. Under the BSD License.
# USAGE:
#
# ruby invertedindex.rb add somedir/*.c
# ruby invertedindex.rb add somedir/*.txt
# ruby search your query string
require 'rubygems'
require 'redis'
class ActiveRecord::Base
def self.find_values opts
sql = self.send(:construct_finder_sql, opts)
self.connection.select_values(sql)
end
end
>> Tagging.find_values(:select => :taggable_id, :limit => 30, :order => 'tagged_at asc')
=> ["1", "3", "6", "6", "6", "10", "10", "10", "11", "11", "11", "10", "10", "10", "10", "10", "13", "13", "13", "13", "13", "13", "15", "15", "15", "15", "15", "15", "15", "15"]
class ActiveRecord::Base
class << self
def select_values(*args)
options = args.extract_options!
validate_find_options(options)
set_readonly_option!(options)
raise "select_values does not support the :include option" if options[:include]
#!/usr/bin/env ruby
require 'rubygems'
require 'octopi'
require 'choice'
include Octopi
Choice.options do
header ''