Skip to content

Instantly share code, notes, and snippets.

Avatar

Jesper Rønn-Jensen jesperronn

View GitHub Profile
@tobiashm
tobiashm / capistrano-database.rb
Last active Aug 29, 2015
Capistrano recipe for creating PostgreSQL database user
View capistrano-database.rb
Capistrano::Configuration.instance(true).load do
namespace :db do
desc "Create database user for current site"
task :create_user, roles: :db do
config = Pathname.new(__dir__).join("..", "database.yml")
config = ERB.new(config.read).result(binding)
config = YAML.load(config)
fail "No database config for #{stage}" unless config[stage.to_s]
username, password = config[stage.to_s].values_at("username", "password")
run "#{sudo as: 'postgres'} psql -d postgres" do |channel, _, _|
View convert_encoding.rb
#!/usr/bin/env ruby -KU
require 'optparse'
require 'ostruct'
require 'iconv'
SCRIPT_NAME = "File Character Encoding Converter"
SCRIPT_VERSION = "0.1"
class FileEncodingConverterOptionParser
View screenshots.rb
# This is an example of how you can set up screenshots for your
# browser testing. Just run cucumber with --format html --out report.html
#
module Screenshots
def embed_screenshot(id)
%x(scrot #{$ROOT_PATH}/images/#{id}.png)
end
end
World(Screenshots)
@jpmckinney
jpmckinney / twitter-bootstrap-ie6.scss
Created Nov 14, 2011
SCSS additions to make Twitter Bootstrap work in IE6
View twitter-bootstrap-ie6.scss
// Assumes you are using <html> conditional classes as described here:
// http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
.lt-ie7 {
// blockquote small:before{content:'\2014 \00A0';}
blockquote small:before{content:"";}
// [class*="span"]{display:inline;float:left;margin-left:20px;}
.span1{display:inline;float:left;margin-left:20px;}
.span2{display:inline;float:left;margin-left:20px;}
.span3{display:inline;float:left;margin-left:20px;}
.span4{display:inline;float:left;margin-left:20px;}
@pcreux
pcreux / helper_steps.rb
Created Jan 23, 2012
Cucumber step to match tables
View helper_steps.rb
module TableMatchHelper
# @param table [Array[Array]]
# @param expected_table [Array[Array[String]]]
# The expected_table values are String. They are converted to
# Regexp when they start and end with a '/'
# Example:
#
# assert_table_match(
# [["Name", "Date"], ["Philippe", "Feb 08"]],
# [["Name", "Date"], ["Philippe", "/\w{3} \d{2}/"]]
@mlangenberg
mlangenberg / deploy.rb
Created Jun 25, 2012
Capistrano task to download all application log files (including logrotated)
View deploy.rb
namespace :log do
desc "Downloads application logs to ./log/deploy/<RAILS_ENV>/<TIMESTAMP>/"
task :fetch, :roles => :app do
source = "#{shared_path}/log/#{rails_env}.log*"
files_per_host = {}
run "ls #{source}" do |channel, stream, data|
files_per_host[channel[:host]] = data.split("\n")
end
destination = File.join('log', 'deploy')
@mguymon
mguymon / factory_girl_helper.rb
Last active Jan 27, 2016
RSpec helper for adding find_or_create to FactoryGirl for Rails
View factory_girl_helper.rb
module FactoryGirlHelper
def find_or_create(*args)
name = args.shift
clazz = nil
# convert from underscores String to camelcase Class
if name.is_a? Hash
name = name.first[0]
clazz = name.first[1].to_s.camelize.constantize
@rwjblue
rwjblue / readme.md
Last active May 13, 2016
Guide to using drip with JRuby
View readme.md

#Overview drip is an awesome command line tool that can be used to dramatically lower perceived JVM startup time. It does this by preloading an entirely new JVM process\instance and allowing you to simply use the preloaded environment. This has extraordinary results with jruby.

We reduced time to run rake environment from 13 seconds to a mere 3.5 seconds. This is actually at or near MRI 1.9.3p327 (with falcon patch) speeds!

Adding a few addition jruby options will reduce startup time even further (down to 1.69 seconds).

#Install Drip Install drip if you haven't already (see https://github.com/flatland/drip)

@drewsberry
drewsberry / ublock-filter.md
Created Mar 30, 2015
ublock Analytics Filter
View ublock-filter.md

ublock Allow Google Analytics

  • Go to ublock settings and select the "Filters" tab

  • In the box, copy the following filter rule in:

    @@||google-analytics.com^

  • Click "Apply changes"

  • You're done

View dockerize-app.production.sh
APP_NAME=dockerized-rails
RAILS_ROOT=/usr/app/${APP_NAME}
RAILS_ENV=production
cd $APP_NAME
# Before we start we'll make sure that we have a scaffolded app just to make sure we can test everything is working.
docker-compose up
docker-compose run app bundle exec rails generate scaffold post title body:text published:boolean RAILS_ENV=development
You can’t perform that action at this time.