Skip to content

Instantly share code, notes, and snippets.

@thenoseman
thenoseman / capybara_save_css.rb
Created August 27, 2015 06:54
save css files when using save_and_open_page in capybara
module Capybara
class Session
def save_page(path=nil)
body = rewrite_css_and_image_references(html)
path ||= "capybara-#{Time.new.strftime("%Y%m%d%H%M%S")}#{rand(10**10)}.html"
path = File.expand_path(path, save_folder_path)
FileUtils.mkdir_p(File.dirname(path))
@thenoseman
thenoseman / bundler_only_in_production.rb
Last active August 29, 2015 13:55
list gems bundler_only_in_production
Bundler.setup(:production).dependencies.select { |g| g.groups.include?(:default) || g.groups.include?(:production) }
graph = Bundler::Graph.new(Bundler.load, "/dev/null").relations["development"]
@thenoseman
thenoseman / jsonf.js
Created June 19, 2014 11:45
JSON serializer allowing functions to be serailized
/*eslint no-new-func:0*/
"use strict";
var JSONF = {
stringify: function(object) {
return JSON.stringify(object, this._functionSerializer);
},
parse: function(jsonString) {
return JSON.parse(jsonString, this._functionDeserializer);
},
_functionSerializer: function(key, value) {
#!/bin/bash
#
# Based on: http://imaginationunbound.blogspot.com/2007/12/adobe-photoshop-cs3-on-mac-os-x-case.html
# Instructions for use
# 1. Copy Photoshop CS5 from a case-insensitive install by copying these folders:
# a) "old_disk_image/Library/Application Support/Adobe" to "/Library/Application Support/Adobe
# b) "old_disk_image/Library/Application Support/FLEXnet Publisher" to "/Library/Application Support/FLEXnet Publisher
# c) "old_disk_image/Library/ScriptingAdditions/Adobe Unit Types.osax" to "/Library/ScriptingAdditions/Adobe Unit Types.osax
# d) "old_disk_image/Applications/Adobe Photoshop CS5" to "/Applications/Adobe Photoshop CS5"
# 2. Run the script below to rename all the folders Adobe's programmers where too lazy to name correctly.
@thenoseman
thenoseman / form-o-fill-rule-with-prompt.js
Last active August 29, 2015 14:07
A Form-O-Fill rule demonstrating the use of standard JS prompts
var rules = [{
url: /.*test.*/,
name: "Usage of prompt()",
before: function(resolve) {
var a = prompt("Paste excel here");
// Split on \n
// Split on \t
// var data = [
// [cell, cell, cell],
// ];

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

@thenoseman
thenoseman / compile_haml_asset_pipeline.rb
Created February 11, 2015 09:52
Compile assets (haml -> html) via rake task
require 'fileutils'
require "haml"
require "sprockets"
class HamlTemplate < Tilt::HamlTemplate
def prepare
@options = @options.merge :format => :html5
super
end
end
@thenoseman
thenoseman / dynamic_rspec.rb
Created April 10, 2015 06:23
Setting rspec metadata dynamically
RSpec.configure do |config|
# Auto tagging: Add mandant tag to directory specific specs
SELF_CARE_MANDANTS.each do |mandant_name|
config.define_derived_metadata(:file_path => %r{/spec/integration/self_care/#{mandant_name.underscore}}) do |metadata|
metadata[mandant_name.to_sym] = true
end
end
end
@thenoseman
thenoseman / fill_only_empty_fields.js
Created August 30, 2015 11:14
Form-O-Fill: Fill only empty fields
var rules = [{
url: /all-types/,
name: "Just fill empty fields",
fields: [{
"selector": "input[type=text]",
"value": function($e) {
return (!$e.val() ? "use this" : null);
}
},{
"selector": "textarea",
ALLES ALS ROOT:
---------------
apt-get -y install build-essential libssl-dev libreadline5-dev zlib1g-dev libxslt-dev libxml2-dev lynx telnet subversion
mkdir -p /opt/local/ruby/sources
mkdir -p /opt/local/ruby/runtimes
cd /opt/local/ruby/sources
wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.7-p174.tar.bz2
tar xzf ruby-1.8.7-p174.tar.bz2