Skip to content

Instantly share code, notes, and snippets.

View juandazapata's full-sized avatar

Juanda juandazapata

View GitHub Profile
@juandazapata
juandazapata / deploy.rake
Created February 12, 2013 15:10
Deploy task to Heroku
# Pushes to heroku origin
# Call like this:
# >> rake deploy:heroku staging
# >> rake deploy:heroku production
namespace :deploy do
task :heroku do
current_branch = `git branch --no-color | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`.gsub("\n", "").gsub("* ", "")
deploy_to = ARGV[1].try(:dup) || 'staging'
sh "git push #{deploy_to} #{current_branch}:master -f"
@juandazapata
juandazapata / .aliases
Last active December 13, 2015 17:39
Vim dotfiles
alias fucking='sudo'
alias be='bundle exec'
alias r='bundle exec rake'
alias fs='bundle exec foreman start'
alias rs='bundle exec rails server'
alias rg='bundle exec rails generate'
alias rc='bundle exec rails console'
alias log='tail -f log/*.log'
alias c='clear'
alias v='vim'
# Include the authorization tokens if we're issuing an API request.
# By doing this, we can call the API and the system will include the authorization headers for us.
# http://api.jquery.com/jQuery.ajaxPrefilter/
$.ajaxPrefilter (options, originalOptions, xhr) ->
is_request_to_api = (options.url.indexOf('<%= Settings.API.URL %>') == 0)
if is_request_to_api
xhr.setRequestHeader('Authorization', "Token token=\"<%= Settings.API.TOKEN %>\", signature=\"<%= Settings.API.SIGNATURE %>\", timestamp=\"<%= Settings.API.TIMESTAMP %>\"")
return
# Get the user location using our API
template = require 'views/templates/hostels/search'
CollectionView= require 'views/base/collection-view'
HostelItemView = require 'views/hostels/item'
module.exports = class HostelSearchView extends CollectionView
className: 'search-results'
itemView: HostelItemView
template: template
listSelector: '.hostels'
fallbackSelector: '.empty-message'
@juandazapata
juandazapata / gist:5212968
Created March 21, 2013 13:22
MySQL number of connections
mysql -u root -p -e"show processlist;"|awk '{print $3}'|awk -F":" '{print $1}'|sort|uniq -c
@juandazapata
juandazapata / memcached.sh
Last active December 15, 2015 05:59
Memcached script
apt-get -y update
apt-get -y install build-essential
apt-get -y install make
apt-get install memcached
#cd /tmp
#wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz
#tar -xvzf ruby-1.9.3-p327.tar.gz
#cd ruby-1.9.3-p327/
#./configure --prefix=/usr/local
@juandazapata
juandazapata / redis.sh
Created March 22, 2013 15:57
Redis setup
apt-get -y update
apt-get -y upgrade
apt-get -y install redis-server
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre-headless -y
wget https://github.com/elasticsearch/elasticsearch/archive/v0.20.1.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/local/share
@juandazapata
juandazapata / localized-models.md
Last active December 16, 2015 08:38
Localized model
class Hostel < ActiveRecord::Base
  attr_accessible :name, :address_1...
  
  # Model definition...
  has_one :conditions, class_name: 'Hostel::Condition'
  has_one :directions, class_name: 'Hostel::Direction'
end

class Hostel::Condition &lt; ActiveRecord::Base
# =============================================================
# REQUIREMENTS
# =============================================================
# - Heroku toolbelt installed in your system
# - A heroku remote named `staging`.
# - A heroku remote named `production`.
# =============================================================
namespace :h do
# -------------------------------------------------------------