Skip to content

Instantly share code, notes, and snippets.

@wildfalcon
wildfalcon / deploy.rb
Created October 14, 2011 16:40
Capistrano backup database
desc "Backup and download database"
task :backup do
filename = "#{Time.now.strftime("%Y-%m-%d-%H-%M")}.sql"
run "mysqldump -u #{user} -p#{password} #{application}_prod > /tmp/#{filename}"
download "/tmp/#{filename}", "backups/#{filename}"
end
@wildfalcon
wildfalcon / registrations_controller.rb
Created August 5, 2011 10:39
How to get devise to redirect to a specific page after user sign up
class Users::RegistrationsController < Devise::RegistrationsController
# Use this if you are sending a confirmation email before completing sign up
def after_inactive_sign_up_path_for(resource)
# resource is an instance of User
"http://www.example.com?user_id=#{resource.id}"
end
# Use this one once the account is active
def after_sign_up_path_for(resource)
@wildfalcon
wildfalcon / web_socket.js
Created June 8, 2011 16:52
Web Socket API
// to open a websocket
socket = new WebSocket("ws://<server>:<port>/<path>");
// to react to a message
socket.onmessage = function(event) {
// your code
}
// to send a message
socket.send("a string")
@wildfalcon
wildfalcon / local_storage.js
Created June 8, 2011 16:50
Local Storage API
// to save a value
localStorage.setItem(key, value)
// to read a value
var value = localStorage.getItem(key)
// to count items in the cache
var count = localStorage.length
@wildfalcon
wildfalcon / drag_drop_setup.js
Created June 8, 2011 16:47
Drag and Drop Files
var stopPropagation = function(event){
event.stopPropagation();
event.preventDefault();
}
document.addEventListener('dragenter', stopPropagation, false);
document.addEventListener('dragexit', stopPropagation, false);
document.addEventListener('dragover', stopPropagation, false);
document.addEventListener('drop', function (event) {
// your code here
@wildfalcon
wildfalcon / facebook_cookie_app_controller.rb
Created December 22, 2010 14:09
Read the fb cookie, and load the user based on the information there
deploy@184:~$ uname -a
Linux 184.106.206.118 2.6.33.5-rscloud #2 SMP Thu Jun 10 15:26:23 UTC 2010 x86_64 GNU/Linux
deploy@184:~$ gem -v
1.3.7
deploy@184:~$ bundle -v
Bundler version 1.0.0.rc.2
deploy@184:~$ mkdir temp
deploy@184:~$ cd temp/
deploy@184:~/temp$ bundle init
Writing new Gemfile to /home/deploy/temp/Gemfile
# I was dealing with a number of different log methods (per minute, per hour, per day) etc
# Where times with no data were not stored in the database. This was an attempt at getting active record to
# inject zeroed data into to the returned datasets.
#
# It worked, but the experiment was a failure:
# 1) extracting times from the where_values is brittle and will fail often
# 2) It gets applied to all AR models
# 3) It required adding two methods (new_default and period) to the corrospoding AR classes creating too strong coupling
#Compares to Bundler lock files and prints a report
#of which gems have changed version
require "yaml"
old = YAML.load_file("Gemfile.lock.old")
current = YAML.load_file("Gemfile.lock")
old['specs'].each do |elem|
elem.each do |name, details|
old_name = name