Skip to content

Instantly share code, notes, and snippets.

View TheNaoX's full-sized avatar
🌮
Tacos

Antonio Chavez TheNaoX

🌮
Tacos
View GitHub Profile
var objects;
$.ajax({
url: "/path",
done: function(response){
// Return here the value
objects = response;
}
});
@TheNaoX
TheNaoX / ssh.rb
Created October 29, 2013 22:28
ssh connection
module Ci
class SSH
attr_reader :user, :host, :password, :port, :buffer, :session
def initialize(options={})
#
# Argument validations
#
@TheNaoX
TheNaoX / resque.rake
Created October 22, 2012 22:10 — forked from bkutil/deploy.rb
Start and Stop tasks for resque workers and resque scheduler with capistrano deploy hook (without God)
# Start a worker with proper env vars and output redirection
def run_worker(queue, count = 1)
puts "Starting #{count} worker(s) with QUEUE: #{queue}"
ops = {:pgroup => true, :err => [(Rails.root + "log/workers_error.log").to_s, "a"],
:out => [(Rails.root + "log/workers.log").to_s, "a"]}
env_vars = {"QUEUE" => queue.to_s}
count.times {
## Using Kernel.spawn and Process.detach because regular system() call would
## cause the processes to quit when capistrano finishes
pid = spawn(env_vars, "rake resque:work", ops)
@TheNaoX
TheNaoX / your_application_init.sh
Created October 9, 2012 19:58
init.d script for deploy unicorn on VPS
#!/bin/bash
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
@TheNaoX
TheNaoX / sessions_controller.rb
Created September 28, 2012 19:44
API authentication with devise
class Api::V1::SessionsController < ApplicationController
respond_to :json
def create
return invalid_login_attempt if params[:user_login].nil?
resource = User.find_for_database_authentication(email: params[:user_login][:email])
return invalid_login_attempt unless resource
@TheNaoX
TheNaoX / registrations_controller.rb
Created September 11, 2012 18:08 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@TheNaoX
TheNaoX / Rails dynamic model
Created August 3, 2012 22:12
This model allows you to manipulate your variables as Setting.apple = {:color => "red", :taste => "sweet"}, and fetch data like this Setting.apple.color # => 'red'
require 'ostruct'
class Setting < ActiveRecord::Base
class SettingNotFound < RuntimeError ; end
validates_uniqueness_of :key
serialize :value
class << self
# /bin/bash
// save as somefile.sh and apply execution permissions
// Installing jupiter for battery managment on ubuntu 11.10 64-bit, works for 32-bit computers too
sudo add-apt-repository ppa:webupd8team/jupiter
sudo apt-get update
sudo apt-get install jupiter