Skip to content

Instantly share code, notes, and snippets.

View kristenhazard's full-sized avatar

Kristen Hazard kristenhazard

View GitHub Profile
countdown = function() {
var index;
function log(){
console.log(index);
}
function iterate(){
log();
if(index>1) setTimeout(iterate, 1000);
@kristenhazard
kristenhazard / gist:813033
Created February 6, 2011 02:06
cinderella log
Last login: Wed Feb 2 15:38:02 on console
[15:45:40]~$ open http://www.atmos.org/cinderella/
[15:45:42]~$ curl https://github.com/atmos/cinderella/raw/master/bootstrap.sh \
> -o - | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
102 1333 102 1333 0 0 1462 0 --:--:-- --:--:-- --:--:-- 12342
Ensuring we have the latest version of cinderella installed
A first time install takes about 45 minutes on a modern machine
Password:
@kristenhazard
kristenhazard / rails_answer_before_type_cast.rb
Created April 30, 2012 18:56
Rails custom validation using answer_before_type_cast
class Answer < ActiveRecord::Base
validate :check_answer_validity
def check_answer_validity
raw_answer = self.answer_before_type_cast
answer_type = Question.find($question_id).answer_type
# first test the answer against the corresponding regex
case answer_type
@kristenhazard
kristenhazard / assets.rb
Created May 2, 2012 19:56
Monkey patching AssetTagHelper
# In order for the application.manifest to work on the offline capable page, we cannot have rails
# add the cache busting timestamp because we can't pass that to rack offline which creates the application.manifest
# so for offline we set our own cache busting datestamp that we also set in rack-offline so the manifest will match the
# assets in the page
# for all other pages utilize regular rails cache busting time stamp
# kdh
require 'action_view/helpers/asset_tag_helper'
module ActionView
@kristenhazard
kristenhazard / routes.rb
Created May 2, 2012 19:59
Configuring rack-offline
Kitfox::Application.routes.draw do
offline = Rails::Offline.configure :cache_interval => 30 do
cache_buster_timestamp = "20120429"
files = Dir[
"#{root}/**/*.html",
"#{root}/stylesheets/**/*.css",
"#{root}/javascripts/**/*.js",
"#{root}/images/**/*.*"]
files.each do |file|
@kristenhazard
kristenhazard / reports_controller.rb
Created May 3, 2012 20:55
Used to login user from cache manifest enabled page
def login_from_cached_page
current_user_id = params[:current_user_id]
# don't login based on parameter from offline page unless there is NO current user
if current_user.nil?
cu = User.find(current_user_id)
sign_in :user, cu
message = "current user not logged in"
else
message = "current user already logged in"
end
@kristenhazard
kristenhazard / check-cache.coffee
Created May 3, 2012 22:01
Communicate applicationCache status
appCache = window.applicationCache;
appCache.addEventListener "cached", (event) =>
# show good message
appCache.addEventListener "noupdate", (event) =>
# show good message
appCache.addEventListener "updateready", (event) =>
# swap out cache and let user know new page available
# reload page to get latest
appCache.swapCache()
appCache.addEventListener "error", (event) =>
@kristenhazard
kristenhazard / gist:4068890
Created November 13, 2012 22:30
Suntoucher carrierwave config
CarrierWave.configure do |config|
bucket = case Rails.env
when "development" then "hcadirectory-dev"
when "staging" then "hcadirectory-staging"
when "production" then "hcadirectory"
end
config.fog_credentials = {
:provider => 'AWS',
@kristenhazard
kristenhazard / gist:4068924
Created November 13, 2012 22:39
File upload
<%= form_for @location, :html => {:multipart => true} do |f| %>
<p>
<label>Photo</label>
<%= image_tag(@location.photo_url) if @location.avatar? %>
<%= f.file_field :photo %>
<%= f.hidden_field :photo_cache %>
</p>
<% end %>