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 / 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 / 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 / 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 / add_user.sh
Created June 6, 2013 13:02
Add user to MongoDB
mongo
use MY_DATABASE
db.addUser("USER", "PASSWORD")
@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 / ttyecho.c
Last active May 6, 2022 04:55
Send terminal command to a TTY terminal
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <string.h>
#include <unistd.h>
void print_help(char *prog_name) {
printf("Usage: %s [-n] DEVNAME COMMAND\n", prog_name);
@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 / vagrant.md
Created July 12, 2013 06:19
Vagrant tips

Download the box here: vagrantbox.es

When setting up process is finished check twice to have static predefined DNS server address (8.8.8.8) in your developer machine network connection. Otherwise you will be unable to connect to the host via vagrant ssh.

@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
@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}"