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 / 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 / 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 / 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 / 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 / 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 / gist:3753886
Created September 20, 2012 03:54
Speed up rspec controllers test using mock before all
# http://stackoverflow.com/a/9460051/148270
describe SomeController do
render_views
describe "GET 'index'" do
before(:each) do
@@response ||= begin
get 'index'
response
end
@yurikoval
yurikoval / gist:4135113
Created November 23, 2012 10:56
Show bookmark me on iPad
# enable with:
#
# - content_for :head do
# :javascript
# window.enable_home_bookmark = true
$ ->
if window.enable_home_bookmark && (("undefined" != typeof window.navigator.standalone) && !window.navigator.standalone) && navigator.userAgent.match(/iPad/i) != null
$('<div id="home_bookmark" style="position:fixed; top: 60px; left: 155px;" ></div>').appendTo('body').popover(
placement: 'bottom'
@yurikoval
yurikoval / gist:4135120
Created November 23, 2012 10:59
Detect viewport orientation
switch (window.orientation)
{
case 0: // Portrait
break;
case 90: ; // Landscape
break;
case -90: ; // Landscape counterclockwise
break;
}
@yurikoval
yurikoval / gist:4135138
Created November 23, 2012 11:04
viewport(iOS/iPad/iPhone) headers
%meta{:content => "yes", :name => "apple-mobile-web-app-capable"}/
%meta{:content => "black", :name => "apple-mobile-web-app-status-bar-style"}/
%meta{:content => "minimum-scale = 1.0, maximum-scale = 1.0, initial-scale = 1.0, user-scalable = no", :name => "viewport"}/
%meta{:name => "format-detection", :content => "telephone=no"}
%link{:rel => "apple-touch-icon-precomposed", :href => "/assets/apple-touch-icon-precomposed.png"}/
%link{:rel => "apple-touch-icon-precomposed", :href => "/assets/apple-touch-icon-precomposed-57x57.png", :sizes => "57x57"}/
%link{:rel => "apple-touch-icon-precomposed", :href => "/assets/apple-touch-icon-precomposed-72x72.png", :sizes => "72x72"}/
%link{:rel => "apple-touch-icon-precomposed", :href => "/assets/apple-touch-icon-precomposed-114x114.png", :sizes => "114x114"}/
%link{:rel => "apple-touch-icon-precomposed", :href => "/assets/apple-touch-icon-precomposed-144x144.png", :sizes => "144x144"}/
@yurikoval
yurikoval / cors_in_rails.rb
Created November 23, 2012 12:06
Cross Origin Resource Sharing in Rails
# http://www.tsheffler.com/blog/?p=428
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
# For all responses in this controller, return the CORS access control headers.
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'