Skip to content

Instantly share code, notes, and snippets.

View dwbutler's full-sized avatar

David Butler dwbutler

View GitHub Profile
@kares
kares / thread_safe_logger.rb
Last active September 25, 2015 10:58
a really threadsafe! (buffered) logger
require 'thread'
require 'active_support/buffered_logger'
# ActiveSupport::BufferedLogger is not completely thread-safe !
# well it is if you disable the silencer :
#
# ActiveSupport::BufferedLogger.silencer = false
#
# yet Rails might still re-invent the silencing logic and set the
# `logger.level = Logger::ERROR` by hand instead of delegating to
@bhbryant
bhbryant / retry.rb
Created September 21, 2011 01:19
auto-failover ReplicaSet config for MongoMapper, by way of ruby driver
replica_sets = mm_env['replica_sets'] # node1:port&node2:port
rs_list = replica_sets.split("&").map {|rs| host,port = rs.split(":"); [host,port.to_i] }
MongoMapper.connection = Mongo::RetryReplicaSetConnection.new(*(rs_list << {:read_secondary => true, :auto_refresh => true }))
MongoMapper.database = mm_env['database']
MongoMapper.database.authenticate(mm_env['username'], mm_env['password'])
@bryanveloso
bryanveloso / brew-services.rb
Created December 8, 2011 09:39 — forked from lwe/brew-services.rb
External script for homebrew to simplify starting services via launchctl, out of the box support for any formula which implements #startup_plist. (This version fixes the deprecation warning raised on Formula.resolve_alias.)
#!/usr/bin/env ruby -w
# brew-services(1) - Easily start and stop formulas via launchctl
# ===============================================================
#
# ## SYNOPSIS
#
# [<sudo>] `brew services` `list`<br>
# [<sudo>] `brew services` `restart` <formula><br>
# [<sudo>] `brew services` `start` <formula> [<plist>]<br>
@dblock
dblock / failures_formatter.rb
Created May 4, 2012 19:52
RSpec tests broken up into suites with retry.
# inspired by https://github.com/rspec/rspec-core/pull/596
require 'rspec/core/formatters/base_formatter'
module RSpec
module Core
module Formatters
class FailuresFormatter < BaseFormatter
def dump_failures
return if failed_examples.empty?
anonymous
anonymous / logstash.rb
Created August 17, 2012 08:58
Rails logstash logger first experiment
# Do not use this code in any production systems, really.
#
# Right now that that is out of the way, this is a hacked together
# 'see if it can be done' Rails logger for Logstash.
#
# It is a first look to see what would need to be done to replace
# standard rails logging with a nice logstash based solution.
#
# Current notes:
#
@joho
joho / deploy.rb
Created September 13, 2012 01:30
How to serve emergency "signed out" views from page cache without affecting signed in users in rails.
set :path_to_repo, "/path_to_repo/"
set :running_app_user, "appusername"
namespace :webscale do
desc "Cache a signed out version of the path. Usage: cap webscale:signed_out_cache_page -s path_to_cache=/films/on_netflix"
task :signed_out_cache, roles: :app do
cache_base_path = "#{path_to_repo}/public/signed_out"
cached_destination_path = "#{cache_base_path}#{path_to_cache}.html"
working_path = "#{cached_destination_path}.tmp"
@hryk
hryk / Gemfile
Last active December 13, 2015 22:08
Examples for using blueprints on JRuby.
source "https://rubygems.org/"
gem "neo4j"
gem "pry"
gem "minitest"
gem "jbundler"
@willurd
willurd / web-servers.md
Last active November 13, 2024 13:44
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@keithtom
keithtom / no_animations.rb
Last active September 22, 2019 06:49
Rack Middleware to disable Disable CSS3/jQuery Animations for Capybara
# Copyright (C) [2014] by Keith Tom <keith dot tom at gmail>
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE
module Rack
# disable CSS3 and jQuery animations in test mode for speed, consistency and avoiding timing issues.
# Usage for Rails:
# in config/environments/test.rb
# config.middleware.use Rack::NoAnimations
class NoAnimations