Skip to content

Instantly share code, notes, and snippets.

View yurikoval's full-sized avatar
🌴
On an island in the sun

Yuri Kovalov yurikoval

🌴
On an island in the sun
  • on an island in the sun
View GitHub Profile
@yurikoval
yurikoval / column_to_bool.sql
Created November 25, 2014 11:33
Update column to boolean in Postgres after MySQL migration
ALTER TABLE my_table ALTER COLUMN my_column DROP DEFAULT;
ALTER TABLE my_table ALTER my_column TYPE bool USING CASE WHEN my_column=0 THEN FALSE ELSE TRUE END;
ALTER TABLE my_table ALTER COLUMN my_column SET DEFAULT FALSE;
@yurikoval
yurikoval / add_sequence.sql
Last active August 29, 2015 14:10
Add sequence for PostgreSQL after migrating from MySQL
CREATE SEQUENCE feedbacks_id_seq;
ALTER TABLE feedbacks ALTER COLUMN id SET DEFAULT nextval('feedbacks_id_seq'::regclass);
ALTER SEQUENCE feedbacks_id_seq OWNED BY feedbacks.id;
select setval('feedbacks_id_seq', (select max(id)+1 from feedbacks), false);
@yurikoval
yurikoval / gist:8265068f1bdfe44b07e4
Last active August 29, 2015 14:08
Set bundler build configs
bundle config build.pg --with-pg-include='/Applications/Postgres.app/Contents/Versions/9.3/include/'
bundle config build.nokogiri --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/
@yurikoval
yurikoval / database.yml
Last active August 29, 2015 14:06
Universal Rails database.yml
development: &development
adapter: postgresql
database: <%= Rails.application.class.parent_name.underscore %>_development
host: localhost
pool: 5
timeout: 5000
test:
<<: *development
database: <%= Rails.application.class.parent_name.underscore %>_test
production:
@yurikoval
yurikoval / each_with_index.rb
Last active August 29, 2015 14:01
each_with_index with key, value and index
items = {
'orange' => 'shoes',
'pink' => 'skirt',
'borwn' => 'socks',
'blue' => 'hat'
}
items.each.with_index(1) do |(color, item), index|
puts "#{index}. Please wear your #{color} #{item}."
end
@yurikoval
yurikoval / asset_sync.rb
Created November 20, 2013 01:23
asset_sync initializer config to work with non-stupid-digest-assets gem for non-digest asset compilation and upload to S3.
if defined?(AssetSync)
AssetSync.configure do |config|
config.fog_provider = 'AWS'
config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
config.fog_directory = ENV['FOG_DIRECTORY']
config.manifest = false
config.existing_remote_files = 'ignore'
@yurikoval
yurikoval / iframe_print.html
Created November 19, 2013 08:48
Printing from iframe when CSS is limiting
<html>
<head>
<link rel="stylesheet" type="text/css" href="all.css" media="all" />
<link rel="stylesheet" type="text/css" href="screen.css" media="screen" />
</head>
<body>
<p class="test_paragraph">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eleifend congue vehicula. Nullam tempor volutpat nisi et dictum. Vestibulum dictum ipsum massa, eget dapibus est posuere vel. Donec a magna justo. Curabitur et erat non erat porta porttitor. Ut tristique eleifend diam cursus lacinia. Nam ultricies mi tincidunt lobortis tincidunt. Duis ac mi tempus, auctor augue sed, accumsan ante. Nunc dictum tempus ullamcorper. Nunc ullamcorper placerat gravida.</p>
<p class="test_paragraph">Maecenas convallis neque tortor, non sodales dui tristique eu. Integer condimentum enim ac mollis sagittis. Suspendisse elementum, tellus quis pretium rutrum, nunc urna eleifend neque, at feugiat ligula justo porta lectus. Praesent in consequat felis. Quisque suscipit auctor mattis. Proin eleifend arcu non l
@yurikoval
yurikoval / update.rb
Created November 12, 2013 08:27
Fetch all remote git update for your repos in your dev folder recursively
#!/usr/bin/ruby
def is_git_repo
%x[git rev-parse 2>&1]
$?.exitstatus == 0
end
dir_to_scan = if ARGV[0]
if ARGV[0] !~ /^\//
"#{Dir.pwd}/#{ARGV[0]}"
@yurikoval
yurikoval / defaults.yaml
Last active December 27, 2015 17:29
Generate rails app template
# rails_apps_composer template ~/template.rb -d defaults.yaml
# rails new app_name -m ~/template.rb
recipes:
- apps4
- controllers
- core
- email
- extras
- frontend
@yurikoval
yurikoval / reset_ios_simulator.rake
Created May 22, 2013 02:21
Rake task to Reset Content and Settings of iOS Simulator
# encoding: UTF-8
namespace :simulator do
desc "Call 'Reset Content and Settings' in iOS Simulator menu"
task :reset do
%x{
osascript <<-END
tell application "iPhone Simulator" to activate
tell application "System Events"
tell process "iPhone Simulator"