Skip to content

Instantly share code, notes, and snippets.

View FUT's full-sized avatar

Yury Koleda FUT

  • Rubyroid Labs
  • Poland
View GitHub Profile
@FUT
FUT / chef.md
Last active December 19, 2015 11:49
Chef cheatsheet

Bootstrap new instance:

knife bootstrap my.instance.compute.amazonaws.com -i my_key.pem -x ubuntu --sudo

Change password for root and ubuntu users (you will be unable to change password and run sudo under any user after 'sudo chef-client` command):

sudo su
passwd ubuntu
passwd
@FUT
FUT / settings.rb
Created June 11, 2013 13:09
Simple yml-encoded settings implementation.
class Settings
SETTINGS = YAML.load(File.read "#{Rails.root}/config/settings.yml")[Rails.env.to_sym]
def self.[](key)
SETTINGS[key]
end
end
@FUT
FUT / add_user.sh
Created June 6, 2013 13:02
Add user to MongoDB
mongo
use MY_DATABASE
db.addUser("USER", "PASSWORD")
@FUT
FUT / logging
Created June 4, 2013 15:06
Sinatra logging
before do
# if using shotgun, create a custom log format
!settings.shotgun || begin
logger.class_eval do
cattr_accessor :format
self.format = <<-TEXT
#{Time.now}
#{request.request_method} #{request.fullpath}
Content-Length: #{request.content_length}
Params: #{request.params}
@FUT
FUT / Gemfile
Created June 2, 2013 12:43
Sinatra app gemfile. Extracts gemlist from application file and makes an attempt to fetch gems from rubygems.
source 'https://rubygems.org'
gemlist = File.read('app.rb').scan(%r{^.*require.*'(?<gem>[^'"]*)'$}).flatten
gemlist.each { |gemname| gem gemname }
@FUT
FUT / nogit_show_translations
Created September 20, 2012 08:17
I18n translation debugging. Usage: SHOW_TR=true rails s
require 'i18n'
if (Rails.env.development? || Rails.env.test?) && ENV['SHOW_TR']
module I18n
class << self
def translate_with_debug(*args)
translation = translate_without_debug(*args)
puts "[\e[32mTranslate\e[0m] #{args.inspect}\t [\e[31mResult\e[0m] #{translation}"
translation
end
@FUT
FUT / api.rb
Created August 30, 2015 06:56
Log params and request time for grape
require 'grape'
class API < Grape::API
before do
@log_start_t = Time.now
Rails.logger.info " Parameters: #{params.to_hash.except("route_info")}"
end
after do
@log_end_t = Time.now
@FUT
FUT / apply.sh
Created November 24, 2014 14:12
Git config for a project
#!/bin/bash
# This file applies all the git configs and hooks related to current repository
# Run it from Rails.root directory this way:
# ./dev/git/apply.sh
cp -v dev/git/pre-commit .git/hooks/pre-commit
cp -v dev/git/config .git/config
@FUT
FUT / mysql_backup.rb
Last active August 29, 2015 14:01
Capistrano MySQL backup task
namespace :mysql do
desc "Performs a backup (using mysqldump) in app shared dir"
task :backup, :roles => :db, :only => { :primary => true } do
if rails_env != 'production'
puts 'Backup will be performed for production environment only! Exiting.'
else
keep_backups = 15
filename = "#{application}.#{rails_env}.db_backup.#{Time.now.strftime '%d.%m.%Y_%H-%M'}.sql"
backups = "#{shared_path}/backups"
filepath = "#{backups}/#{filename}"
@FUT
FUT / elasticsearch.yml
Last active August 29, 2015 14:00
Elasticsearch
cluster.name: engine_development
index.number_of_shards: 2
index.number_of_replicas: 1
index.query.bool.max_clause_count: 1000000