Skip to content

Instantly share code, notes, and snippets.

after ssh into the instance
cd ~/echo
eval $(ssh-agent) # to check if ssh agent is running
ssh-add ~/.ssh/prod_deploy # if unfortunately not then we need to re-add the key
git pull origin develop
fab build_release # build the app
mv /home/ubuntu/echo-0.1.0.tar.gz /home/ubuntu/echo-0.1.0.tar.gz.2016.03.30.2014 # move away the current version, remember to change the date/time
mv /home/ubuntu/echo/rel/echo/echo-0.1.0.tar.gz /home/ubuntu # move the new release over
cd /srv/prod
sudo tar xvzf /home/ubuntu/echo-0.1.0.tar.gz
@bleakwood
bleakwood / gist:14a9ac85e6edb0993eef
Created January 14, 2015 02:14
using promise for ajax calls
var Foods = {
category: function(cats_url){
var promise = $.Deferred();
$.ajax(cats_url, {
success: function(dat) {
promise.resolve(dat);
}
error: function(){
var error = 'invalid food';
promise.reject(error);
@bleakwood
bleakwood / post.rb
Created August 21, 2013 20:03
Each post is created with a role, which represents a data type. A user can only access certain data types another user shared with him. Each type of data is assigned a binary code for permission, which is assigned with a group where user can decides permissions. One user can belong to multiple groups of another user. self.for_user is trying to f…
class Post < ActiveRecord::Base
attr_accessible :user, :description, :role, :guid, :created_at, :group, :gpoint
belongs_to :user
has_many :notifications, :as => :notifiable
has_data_fields [:gpoint, :group]
validates_presence_of :user_id, :description
@bleakwood
bleakwood / user_sessions_controller.rb
Created August 21, 2013 20:02
a simple controller to allow user sign in and sign in w/ Facebook and google
class UserSessionsController < ApplicationController
skip_before_filter :require_login, :only => [:new, :create, :authenticate]
rescue_from User::NotActivated do |e|
flash.now.alert = "You are not activted"
render :not_activated
end
rescue_from User::InvalidPassword do |e|
flash.now.alert = "Invalid email or password"
class Readings::BloodPressure < Readings::Base
has_data_fields [:diastolic, :systolic]
validates :diastolic, :numericality => {:greater_than => 0}
validates :systolic, :numericality => {:greater_than => 0}
def self.display_name
"Blood Pressure"
end
@bleakwood
bleakwood / normalized_model.rb
Created August 21, 2013 20:01
a module used on models to allow storage of one hash containing multiple key-value pairs in one column "data", for each data fields passed with has_data_fields (see blood_pressure.rb as an example), it creates getter and setter methods, and delegate those methods to data.m, which will be taken care of by the hashie gem, which is a gem allows you…
module NormalizedModel
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def has_data_fields(fields)
include Cloud2Health::NormalizedModel::InstanceMethods
serialize :data
@bleakwood
bleakwood / menu.js
Created August 21, 2013 19:58
menu.js: Menu view of Backbone.js app, I mostly worked with notification count on upper right corner. Each time a new push is received, the count will be updated with the number in payload, and the upper right corner will be re-rendered.
define([
// Application.
"app",
"modules/notification",
"modules/common",
"modules/happ"
],
function(app, Notification, Common, Happ) {
@bleakwood
bleakwood / notification.js
Created August 21, 2013 19:57
notification.js: Notifications list view of Backbone.js. When the icon for notification is tapped, the view for notifications will be rendered, and it listens to the event of a new push is received, and will fetch new notifications and re-render the view afterwards. A unread notification being tapped on will be marked as read and saved to server.
define([
// Application.
"app"],
function(app) {
var Notification = app.module();
Notification.Model = Backbone.Model.extend({
unread: function(){