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 / gist:3663539
Created September 7, 2012 05:47
Passing arguments to an around_filter
# app/controller/articles_controller.rb
around_filter { |controller, action| controller.send(:add_published_scope, Article){ action.call } }
# app/controller/application_controller.rb
def add_published_scope(klass = nil, &block)
unless klass
klass = controller_name.classify.constantize
end
klass.with_scope(:find => klass.where("published_at <= ?", Time.zone.now)) do
yield
@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'
@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"
@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 / 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 / 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