Skip to content

Instantly share code, notes, and snippets.

@LolWalid
LolWalid / color_in_terminal.rb
Last active February 3, 2016 14:00
Coloryze your terminal
def color_code
colors_code = %w(1;32 0;32 0;36 1;36 1;37 0;37 1;30 0;30 0;34 1;34 0;35 1;35 0;31 1;31 0;33 1;33)
colors_code.each do |color|
puts "#{color} : \033[#{color}m color \033[0;30m"
end
nil
end
@LolWalid
LolWalid / dafuq.rb
Last active March 24, 2016 09:10
Why can I call method as class one but I have to define it as instance method in mailer?
Mailer.send_mail('subject', 'message')
class Mailer < ActionMailer::Base
def send_mail(subject, message)
subject = subject
@message = message
mail(to: '[email protected]', subject: subject)
end
end
@LolWalid
LolWalid / parameters.rb
Last active February 10, 2016 15:12
Strong parameters
class UsersController < ApplicationController
def create
@user = User.new(user_params)
# blablabla
end
private
def user_params
params.require(:user).permit(:user_id, :username, :name, :password)
@LolWalid
LolWalid / How_to_chef_mysql.md
Last active April 1, 2016 09:52
Add Chef To your project

export EDITOR=emacs

gem install knife-solo

knife solo init chef

cd chef

touch Gemfile, add custom stuff

@LolWalid
LolWalid / Rakefile
Created February 22, 2016 18:11
Action before and after rake task
require File.expand_path('../lib/tasks/hooks', __FILE__)
require File.expand_path('../config/application', __FILE__)
Rails.application.load_tasks
@LolWalid
LolWalid / 0_basics.sh
Last active March 9, 2016 15:08
Basic Linux Commands
# http://www.comptechdoc.org/os/linux/usersguide
# http://www.tecmint.com/20-advanced-commands-for-linux-experts/
man ls # format and display the on-line manual pages
pwd # print working directory
cd new_directory # change current directory to new_directory
cd ~ # Move to the user's home directory which is "/home/username". The '~' indicates the users home directory.
cd # same as cd ~
@LolWalid
LolWalid / delayed_job.rb
Created March 18, 2016 09:51
Delayed job
Delayed::Job.find(X).invoke_job
@LolWalid
LolWalid / args.rake
Created March 24, 2016 09:08
Pass argument to rake task
task :task, [:arg1] => :environment do |_, args|
arg1 = args.arg1 || 'default_value'
puts arg1
end
@LolWalid
LolWalid / oauth.rb
Last active March 31, 2016 09:43
How to init oauth - Rails
class Oauth
def client
consumer = OAuth::Consumer.new(
consumer_key, consumer_secret, site: BASE_URL)
token = {
oauth_token: access_token,
oauth_token_secret: access_token_secret
}
module API
module V1
class ApplicationController < ActionController::Base
before_filter :authenticate
TOKEN = ENV['my_api_token'].freeze
protected
def authenticate
authenticate_or_request_with_http_token do |token, _|