Skip to content

Instantly share code, notes, and snippets.

View TheNaoX's full-sized avatar
🌮
Tacos

Antonio Chavez TheNaoX

🌮
Tacos
View GitHub Profile
@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 / vscode_settings.md
Created January 29, 2018 18:54
My VSCode settings

Extensions list

  • ESLint
  • HTML Snippets
  • Material Icon theme
  • Rainglow
  • Ruby
  • ruby-on-rails-snippets
  • ruby-snippet
  • Simple Ruby ERB
// Update with your config settings.
module.exports = {
development: {
client: 'postgresql',
connection: {
database: 'db_name',
charset: 'utf8'
},
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 / bmi_test.rb
Created November 17, 2015 14:50
BMI example
weight = 85 # Kilograms
height = 1.77 # Meters
bmi = BodyMassIndex.new(weight, height)
bmi.calculate_index # 27.1
exports.up = function(knex, Promise) {
return knex.schema.hasTable('short_urls').then(function(exists) {
if (!exists) {
return knex.schema.createTable('short_urls', function(t) {
t.increments('id').primary();
t.text('long_url');
t.string('token', 11);
t.index(['token'], 'short_urls_token_idx')
t.timestamps();
});
@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