I've been trying to understand how to setup systems from
the ground up on Ubuntu. I just installed redis onto
the box and here's how I did it and some things to look
out for.
To install:
| #!/bin/sh | |
| # Licence: MIT | |
| # Created by tomykaira, 2011-10-25 | |
| if [ $# -ne 1 ]; then | |
| echo "Give me your new project name (only)" | |
| exit 1 | |
| fi |
| // ----------- | |
| // Debugger that shows view port size. Helps when making responsive designs. | |
| // ----------- | |
| function showViewPortSize(display) { | |
| if(display) { | |
| var height = jQuery(window).height(); | |
| var width = jQuery(window).width(); | |
| jQuery('body').prepend('<div id="viewportsize" style="z-index:9999;position:fixed;top:40px;left:5px;color:#fff;background:#000;padding:10px">Height: '+height+'<br>Width: '+width+'</div>'); | |
| jQuery(window).resize(function() { |
| <!DOCTYPE HTML> | |
| <html lang="en-US"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>test upload by chunk</title> | |
| </head> | |
| <body> | |
| <input type="file" id="f" /> | |
| <script src="script.js"></script> |
| #Session controller provides a token | |
| #/controllers/api/sessions_controller.rb | |
| class Api::SessionsController < Devise::SessionsController | |
| before_filter :authenticate_user!, :except => [:create] | |
| before_filter :ensure_params_exist, :except => [:destroy] | |
| respond_to :json | |
| def create | |
| resource = User.find_for_database_authentication(:email => params[:user_login][:email]) | |
| return invalid_login_attempt unless resource |
| t = 236 # seconds | |
| Time.at(t).utc.strftime("%H:%M:%S") | |
| => "00:03:56" | |
| # Reference | |
| # http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time |
| # this is the easiest way to use partials from model I could find so far | |
| class Entry < AR::Base | |
| def as_json | |
| context = ApplicationController.new.view_context | |
| context.render('/api/entries/entry.json', entry: self) | |
| end | |
| end |
| References: | |
| http://blog.carbonfive.com/2012/02/27/supporting-cross-domain-ajax-in-rails-using-jsonp-and-cors/ | |
| https://github.com/cyu/rack-cors | |
| http://nelm.io/blog/2011/11/cors-with-sencha-touch/ | |
| http://jessehowarth.com/2011/04/27/ajax-login-with-devise | |
| ============================================================================================================= | |
| GEMFILE | |
| ============================================================================================================= | |
| gem 'rack-cors', :require => 'rack/cors' |
| require 'bundler/capistrano' | |
| require 'capistrano_colors' | |
| load 'deploy/assets' | |
| # ssh forwarding and shell | |
| set :default_run_options, { :pty => true } | |
| set :ssh_options, { :forward_agent => true } | |
| set :scm_verbose, true | |
| set :scm, :git |
| /** | |
| * Get a random floating point number between `min` and `max`. | |
| * | |
| * @param {number} min - min number | |
| * @param {number} max - max number | |
| * @return {number} a random floating point number | |
| */ | |
| function getRandomFloat(min, max) { | |
| return Math.random() * (max - min) + min; | |
| } |