Skip to content

Instantly share code, notes, and snippets.

View fmiopensource's full-sized avatar

Fluid Media fmiopensource

View GitHub Profile
;(function($) {
// displays snowflakes in a giving selector
$.fn.snow = function(options) {
var opts = $.extend({}, $.fn.snow.defaults, options);
// generates a random position
function getRandomPosition(width) {
return Math.floor(Math.random() * width);
def putsc(text, color='y')
code = case color
when 'y' then 33
when 'r' then 31
when 'g' then 32
end
printf "\033[#{code}m#{text}\033[0m\n\n"
end
# add value from param to task if:
# - its in the list
# - its in the params so sending nil will nil it but sending nothing will leave it alone
# do some conversion on the value as well
{"hours" => ->(hours){hours_points_converter(hours)},
"parked" => ->(parked){parked == "1" ? true : false},
"description" => nil,
"tag_list" => nil,
"status_id" => ->(id){id.to_i},
# This method is heavily adapted from the Rails method of determining the subdomain.
require 'rubygems'
require 'sinatra'
helpers do
def subdomains(tld_len=1) # we set tld_len to 1, use 2 for co.uk or similar
@subdomains ||= if (request.host.nil? ||
/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(request.host))
request.host.split('.')[0...(1 - tld_len - 2)]
else
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end
$(document).ready(function() {
$('.delete').click(function() {
if(confirm('Are you sure?')) {
var f = document.createElement('form');
$(this).after($(f).attr({
method: 'post',
action: $(this).attr('href')
}).append('<input type="hidden" name="_method" value="DELETE" />'));
$(f).submit();
}
/*
To make this trick work, I embed the time stamp for a given entry in the DOM as a custom attribute that I can query for conversion like this:
<li>
<span time="Feb 05, 2009 15:30:00 GMT">09:30 AM CST (15:30 GMT)</span> /
The aliens came out of no where and took Basecamp!
We're trying to hunt them down now. Stay tuned while we bring the lasers online.
</li>