Skip to content

Instantly share code, notes, and snippets.

View bess's full-sized avatar

Bess Sadler bess

View GitHub Profile
@bess
bess / rails_42_with_active_support.rb
Created March 11, 2020 12:14 — forked from tonytonyjan/rails_42_with_active_support.rb
session cookie decrypter for Rails
require 'cgi'
require 'json'
require 'active_support'
def verify_and_decrypt_session_cookie(cookie, secret_key_base)
cookie = CGI::unescape(cookie)
salt = 'encrypted cookie'
signed_salt = 'signed encrypted cookie'
key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
secret = key_generator.generate_key(salt)
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML:Document for the page we're interested in...
doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
# Do funky things with it using Nokogiri::XML::Node methods...
####
@bess
bess / explain_partials.rb
Created May 30, 2017 17:37 — forked from bmaddy/explain_partials.rb
An initializer to show what parts of your page come from what rails partials
# Start the app with EXPLAIN_PARTIALS=true to show locations of view partials
if Rails.env.development? and ENV['EXPLAIN_PARTIALS']
module ActionView
class PartialRenderer
def render_with_explanation(*args)
rendered = render_without_explanation(*args).to_s
# Note: We haven't figured out how to get a path when @template is nil.
start_explanation = "\n<!-- START PARTIAL #{@template.inspect} -->\n"
end_explanation = "\n<!-- END PARTIAL #{@template.inspect} -->\n"
start_explanation.html_safe + rendered + end_explanation.html_safe
@bess
bess / capybara cheat sheet
Created April 7, 2017 15:56 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
#!/usr/bin/env ruby
#
# ./dscm-to-html.rb repository_url PID
#
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'erb'
require 'active_support'