This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(($) -> | |
# Finds the angle between the center of the first element | |
# and the provided point, or the center of another element | |
degreesPerRadian = 180 / Math.PI | |
$.fn.angleTo = () -> | |
args = arguments | |
if 1 == args.length | |
target = $ args[0] | |
position = target.offset() | |
targetX = position.left + target.outerWidth() / 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationModel | |
extend Feedable | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
task :uptodate do | |
if pending_migrations.blank? | |
puts "Migrations are up-to-date" | |
else | |
puts "The following migrations are pending:" | |
puts pending_migrations.map { |mp| "%s\t\t%s" % [ mp.version, mp.name ] }.join("\n") | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
desc "Populate Users Table with images from /public/feedimg" | |
task :populate => :environment do | |
require "populator" | |
require "faker" | |
image_filenames = Dir.glob(File.join(Rails.root, '/public/feedimg', '*')) | |
User.populate 1 do |user| | |
user.username = Faker::Name.first_name.downcase | |
user.email = Faker::Internet.user_name + "@myhost.com".downcase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# UpdateOrCreate makes it simple to to perform updating or creating models | |
# without a lot of boilerplate. | |
# | |
# It can be used in several forms. In its simplest form, it can be used with a | |
# single OrderedHash. | |
# | |
# User.update_or_create(username: 'Admin', admin: true) | |
# | |
# The first key/value pair from the provided hash is used to look up any existing record. | |
# In this case, it will look for a user with the username 'Admin' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Loop | |
attr_accessor :name | |
def initialize name | |
self.name = name | |
end | |
end | |
module LoopDecoratorHelper | |
def loop_delete_link loop | |
"Delete #{loop.name}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SessionsHelper | |
def sign_in(user) | |
cookies.permanent.signed[:remember_token] = [user.id, user.salt] | |
self.current_user = user | |
end | |
def current_user=(user) | |
@current_user = user | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!!! | |
%html | |
%head | |
= csrf_meta_tags | |
= stylesheet_link_tag "application" | |
%body | |
= yield | |
= javascript_include_tag "application" | |
= render_inline_javascript_controller_action_asset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
Dir['./db/migrate/*.rb'].each do |from| | |
to = File.join(File.dirname(from), | |
"%014d%s" % File.basename(from).match(/^(\d+)(_.*)$/)[1..-1].map.with_index do |f, i| | |
0 == i ? f.to_i : f | |
end) | |
FileUtils.mv(from, to) if from != to | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function throttle(millis, fn) { | |
var sched; | |
return function() { | |
if (!sched) | |
sched = setTimeout(function executeAndClear() { fn(); sched = false; }, millis); | |
}; | |
} |