Skip to content

Instantly share code, notes, and snippets.

@movstox
movstox / gist:7945c996ec6fcff0fe8209b08ee0c5f7
Created July 19, 2016 10:43 — forked from fastjames/gist:2725983
Patch to get content_for working with action caching and fragment caching in Rails 3.1
module ActionController
class Metal
attr_internal :cached_content_for
end
module Caching
module Actions
def _save_fragment(name, options)
return unless caching_allowed?
@movstox
movstox / rails content_for caching
Created July 19, 2016 10:39 — forked from stackng/rails content_for caching
make action and fragment caching of rails3 compatible with content_for
module ActionController
class Metal
attr_internal :cached_content_for
end
module Caching
module Actions
def _save_fragment(name, options)
return unless caching_allowed?
@movstox
movstox / gist:6d4edf5461045cb4475eb46288ddb141
Created July 19, 2016 10:39 — forked from dignoe/gist:2485272
Patch to get content_for working with action caching and fragment caching in Rails 3.1
module ActionController
class Metal
attr_internal :cached_content_for
end
module Caching
module Actions
def _save_fragment(name, options)
return unless caching_allowed?
@movstox
movstox / beorn
Created July 14, 2016 19:36 — forked from allspiritseve/beorn
#!/bin/bash
case "$1" in
production) environment=production; shift;;
staging) environment=staging; shift;;
* environment = staging;;
esac
case "$environment" in
staging) app=my-app-staging;;
#!/bin/bash
# Usage:
# $ ./heroku-deploy.sh <app name> <git repo url> <heroku api key>
APP="$1"
REPO="$2"
APIKEY="$3"
echo "-----> Creating application $APP"
curl -u ":$APIKEY" -d "app[name]=$APP" -X POST https://api.heroku.com/apps -s > /dev/null
@movstox
movstox / example.rb
Created March 4, 2016 11:40 — forked from JoshCheek/example.rb
Debug
# https://minhajuddin.com/2016/03/03/put-this-in-your-code-to-debug-anything
require 'rouge'
require 'method_source'
require 'pp'
class Dbg
def initialize(object, to:)
@object, @stream = object, to
end
@movstox
movstox / README.md
Created March 4, 2016 11:39 — forked from derwiki/README.md
Ruby module that you can use in a `before_action` on sensitive controllers for which you'd like a usage audit trail

Adding an audit log to your Rails app

If you have any sort of administrative interface on your web site, you can easily imagine an intruder gaining access and mucking about. How do you know the extent of the damage? Adding an audit log to your app is one quick solution. An audit log should record a few things:

  • controller entry points with parameter values
  • permanent information about the user, like user_id
  • transient information about the user, like IP and user_agent

Using the Rails framework, this is as simple as adding a before_action to your admin controllers. Here’s a basic version that I’m using in production.

@movstox
movstox / socksify_faraday.rb
Created March 3, 2016 21:42 — forked from andrey-kazakov/socksify_faraday.rb
HTTP over SOCKS support monkey patch for Mechanize, Faraday and it's based clients (OAuth2 like)
# requires socksify gem
require "socksify"
require 'socksify/http'
# use w/ OAuth2 like OAuth2::Client.new(id, secret, connection_opts: { proxy: 'socks://127.0.0.1:9050' })
class Faraday::Adapter::NetHttp
def net_http_class(env)
if proxy = env[:request][:proxy]
if proxy[:uri].scheme == 'socks'
Net::HTTP::SOCKSProxy(proxy[:uri].host, proxy[:uri].port)
@movstox
movstox / capybara.rb
Created January 28, 2016 22:50 — forked from futhr/capybara.rb
Restart and retry when Poltergeist fails randomly.
# Borrowed from https://github.com/y310/rspec-retry/blob/master/lib/rspec/retry.rb
# Drop this script into spec/support
# To test snippet just set timeout to 1
RSpec.configure do |config|
Capybara.javascript_driver = :poltergeist
Capybara.register_driver(:poltergeist) do |app|
Capybara::Poltergeist::Driver.new app,
@movstox
movstox / gist:770a85ab6585595ac079
Created January 28, 2016 13:03 — forked from redbar0n/gist:8fdc90cbc918d286725e
capybara-webkit evaluate_script vs execute_script
Regarding this article: http://makandracards.com/makandra/12317-capybara-selenium-evaluate_script-might-freeze-your-browser-use-execute_script
code:
puts page.evaluate_script("2+3;").to_i
output:
Started "Evaluate(2+3;)"
Finished "Evaluate(2+3;)" with response "Success(5)"
Wrote response true "5"