Skip to content

Instantly share code, notes, and snippets.

View srpouyet's full-sized avatar

Sebastiaan Pouyet srpouyet

View GitHub Profile
@srpouyet
srpouyet / preserve_keys_encoder.rb
Created February 23, 2015 10:36
Faraday PreserveKeysEncoder: Only decodes url parameter values and leaves keys intact.
## PreserveKeysEncoder doesn't encode parameter keys (which is standard Faraday behaviour).
## Usage:
## Faraday.new(url, request: { params_encoder: PreserveKeysEncoder.new })
## Modes:
## :nested { '$product_id' =>' [10,20,30] } becomes $product_id[1]=10&$product_id[1]=20&$product_id[1]=30
## :flat and $product_id=10&$product_id=20&$product_id=30 in :flat mode
class Faraday::PreserveKeysEncoder
MODES = [:nested, :flat]
delegate :decode, :escape, to: :super_encoder, allow_nil: true
@srpouyet
srpouyet / wisper_example.rb
Created February 14, 2015 18:43
Simple Wisper example
require 'wisper'
class User
include Wisper::Publisher
attr_accessor :name, :last_email_sent_at
def initialize(name, email)
@name, @email = name, email
end
# db/migrate/20131118172653_create_transactional_items_view.rb
class CreateTransactionalItemsView < ActiveRecord::Migration
def up
select_sql = File.open("#{Rails.root}/db/migrate/20131118172653_create_transactional_items_view.sql", 'r') { |f| f.read }
# for materialized view:
view_sql = "CREATE MATERIALIZED VIEW transactional_items AS (#{select_sql})"
# for normal view:
view_sql = "CREATE VIEW transactional_items AS (#{select_sql})"
# Outputs this at warn log level:
# 1.2.3.4 GET /path 200 OK BlahController#action HTML 938.2 (DB 11.8, View 719.7) {params} {optional params from flash[:log]}
#
# Save as config/initializers/oneline_detailed_logging.rb. Consider
# decreasing the log level from "info" to "warn" (in production.rb) so
# the one-line log message replaces the standard request logs.
# override process_action to add 2 things to the payload:
# - remote IP
@srpouyet
srpouyet / bundle install Charlock Holmes with Homebrew on OS X Mountain Lion and Mavericks
Last active December 24, 2015 21:19
Set bundle.config build options so Nokogiri and Charlock Holmes are correctly built with homebrew installed dependencies (libxml2, libxslt, libiconv, icu4c) on OS X Mountain Lion / Mavericks.
$ bundle config build.charlock_holmes --with-icu-dir=`brew --prefix icu4c`
$ bundle install
@srpouyet
srpouyet / restore_ipkg_and_rdiff_on_dsm.md
Last active December 19, 2015 05:29
How to restore IPKG and rdiff-backup after updating Synology DSM 4 to a new version.
  1. ssh in to your Synology
  2. $ vi /root/.profile
  3. prepend /opt/bin:/opt/sbin: to PATH so it looks like PATH=/opt/bin:/opt/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin
    replace the standard rdiff packages with symlinks:
  4. $ ln -s /opt/bin/rdiff-backup-2.6 /usr/bin/rdiff-backup
  5. $ ln -s /opt/bin/rdiff-backup-statistics-2.6 /usr/bin/rdiff-backup-statistics
# include from an initializer
module HstoreAccessor
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def hstore_accessor(hstore_attribute, *keys)
Array(keys).flatten.each do |key|
@srpouyet
srpouyet / active_link_to.rb
Last active December 15, 2015 14:39
Rails 3 active class navigation helper which by default takes query params into account.
@srpouyet
srpouyet / fix-nokogiri-libxml-warnings-mountain-lion.markdown
Last active December 14, 2015 14:18 — forked from devpuppy/nokogiri libxml homebrew lion
Get rid of those pesky "WARNING: Nokogiri was built against LibXML version X, but has dynamically loaded Z" warnings on Mac OS X (Mountain) Lion.

How to get rid of those pesky
WARNING: Nokogiri was built against LibXML version X, but has dynamically loaded Z
warnings on Mac OS X (Mountain) Lion:

  1. gem uninstall nokogiri libxml-ruby
    Continue to step 5 if you already recently brewed libxml2 and libxslt...
  2. brew update
  3. brew install libxml2 --with-xml2-config
  4. brew install libxslt
  5. gem install nokogiri -- --with-xml2-include=/usr/local/opt/libxml2/include --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xslt-dir=/usr/local/opt/libxslt

h1. Sublime Text 2 - Useful Shortcuts (Mac OS X)

h2. General

  • ⌘T go to file
  • ⌘⌃P go to project
  • ⌘R go to methods
  • ⌃G go to line
  • ⌘KB toggle side bar
  • ⌘⇧P command prompt