Skip to content

Instantly share code, notes, and snippets.

View leifcr's full-sized avatar

Leif Ringstad leifcr

View GitHub Profile
@leifcr
leifcr / will_paginate.rb
Created October 21, 2011 21:35 — forked from henrik/will_paginate.rb
Extends will_paginate to play well with Twitter's Bootstrap (http://twitter.github.com/bootstrap/). Suggested location: config/initializers/will_paginate.rb
# https://gist.github.com/1305042
module WillPaginate
module ActionView
def will_paginate(collection = nil, options = {})
options[:renderer] ||= BootstrapLinkRenderer
super.try :html_safe
end
class BootstrapLinkRenderer < LinkRenderer
# mongo_template.rb
# remove unneeded defaults
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm public/javascripts/controls.js"
run "rm public/javascripts/dragdrop.js"
run "rm public/javascripts/effects.js"
run "rm public/javascripts/prototype.js"
@leifcr
leifcr / page.rb
Created December 19, 2011 09:52
Rails 3.1 Helper Issue in production mode with cache_classes=true
#model page.rb
class Page < ActiveRecord::Base
STATUSES = %w[new published]
end
@leifcr
leifcr / gist:2145998
Created March 21, 2012 10:21
maler-pris dig
----------------------------------------------
leif@gnomik:~$ dig @8.8.8.8 maler-pris.dk
; <<>> DiG 9.7.0-P1 <<>> @8.8.8.8 maler-pris.dk
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59780
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
@leifcr
leifcr / quiet_assets.rb
Created December 11, 2012 18:07
Rails 3.2 compatible quiet assets
if Rails.env.development?
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
end
end
@leifcr
leifcr / .irbrc
Last active December 13, 2015 16:58 — forked from patmcnally/.irbrc
irbrc with wirble, hirb and awesome_print + logging of activesupport requests...
# load libraries
require 'rubygems' rescue nil
alias q exit
class Object
def local_methods
(methods - Object.instance_methods).sort
end
end
@leifcr
leifcr / leifcr.zsh-theme
Created March 14, 2013 08:48
Oh-my-zsh theme based on "muse". Added green user@machine
#!/usr/bin/env zsh
#local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
setopt promptsubst
autoload -U add-zsh-hook
PROMPT_SUCCESS_COLOR=$FG[117]
PROMPT_FAILURE_COLOR=$FG[124]
PROMPT_VCS_INFO_COLOR=$FG[242]
@leifcr
leifcr / riak1.app.config
Last active December 21, 2015 02:28
Riak example cluster configuration with 3 nodes (riak1, riak2 and riak3)
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
[
%% Riak Client APIs config
{riak_api, [
%% pb_backlog is the maximum length to which the queue of pending
%% connections may grow. If set, it must be an integer >= 0.
%% By default the value is 5. If you anticipate a huge number of
%% connections being initialised *simultaneously*, set this number
%% higher.
@leifcr
leifcr / gist:6238842
Created August 15, 2013 07:06
bitcask settings for example riak cluster
{bitcask, [
{max_file_size, 268435456}, %% maximum 256 mb files
{frag_merge_trigger, 35}, %% fragmentation >= 35%
{dead_bytes_merge_trigger, 134217728}, %% dead bytes > 128 MB
{frag_threshold, 20}, %% fragmentation >= 20%
{dead_bytes_threshold, 33554432}, %% dead bytes > 32 MB
{small_file_threshold, 10485760}, %% file is < 10MB
]}
require 'resque_mailer'
require 'devise/async'
# pop and set locale from the args before running
module PerformWithLocale
def perform(*args)
I18n.with_locale(args.pop) do
super(*args)
end
end