Skip to content

Instantly share code, notes, and snippets.

@hugodias
hugodias / add_authentication_token_to_users.rb
Created April 11, 2016 00:33
AddAuthenticationTokenToUsers Migration
class AddAuthenticationTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :authentication_token, :string
end
end
@hugodias
hugodias / api_controller.rb
Last active April 11, 2016 01:28
Api Controller Rails
# app/controllers/api/v1/api_controller.rb
module Api::V1
class ApiController < ApplicationController
rescue_from ActiveRecord::RecordNotFound, :with => :request_not_found
before_filter :authenticate_user_from_token!
before_filter :authenticate_user!
def invalid_request
@response = Hash.new
@hugodias
hugodias / .tmux.conf
Created April 7, 2016 14:19
My Tmux Conf
set-option -g xterm-keys on
set -g default-terminal "xterm"
set -g utf8
set-window-option -g utf8 on
# ----------------------
# set some pretty colors
# ----------------------
# set pane colors - hilight the active pane
@hugodias
hugodias / Dropbox.coffee
Last active December 7, 2017 19:16
Upload images from Dropbox to Carrierwave on Ruby on Rails
class Dropbox
constructor: ->
@options =
success: @success
cancel: ->
# Do something
linkType: 'direct'
multiselect: true
extensions: [
'.jpg'
@hugodias
hugodias / sidekiq.config
Created March 24, 2016 18:15 — forked from RobertoSchneiders/sidekiq.config
Sidekiq Config for Elastic Beanstalk
# Sidekiq interaction and startup script
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_sidekiq.sh":
mode: "000755"
content: |
#!/bin/bash
. /opt/elasticbeanstalk/hooks/common.sh
. /opt/elasticbeanstalk/support/envvars
@hugodias
hugodias / realties_controller.rb
Last active March 23, 2016 15:57
Qual é a melhor maneira de alterar dentro params?
class RealtiesController < ApplicationController
before_action :set_realty, :only => [:update]
def update
@realty.status = 3
if @realty.update_attributes(realty_update_params)
redirect_to conta_imoveis_path
end
@hugodias
hugodias / digital_ocean_setup.md
Created February 29, 2016 19:15 — forked from ChuckJHardy/digital_ocean_setup.md
DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3 Setup Instructions
@hugodias
hugodias / gist:382f191eb5a365e98bf1
Created December 15, 2015 18:54
Kill Specific processes in linux based on process port
$ lsof -i:8090
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ssh 75782 eoin 5u IPv6 0x01c1c234 0t0 TCP localhost:8090 (LISTEN)
$ kill -9 75782
import random
def encontrar_saida_on2(parede, posicao, porta):
"""Procura uma valor True no vetor fazendo um loop entre faixas
A faixa inicial e 0, ou seja, a busca inicial sera posicao - faixa => posicao + faixa
0,0
Se a porta nao for encontrada a faixa e incrementada
Args:
@hugodias
hugodias / .htaccess
Created November 24, 2015 15:27
Block WP-Admin with Password
AuthName "Admins Only"
AuthUserFile /home/path/to/.htpasswds/public_html/wp-admin/passwd
AuthGroupFile /dev/null
AuthType basic
require user username