Skip to content

Instantly share code, notes, and snippets.

View manuelmeurer's full-sized avatar
🤷‍♂️

Manuel Meurer manuelmeurer

🤷‍♂️
View GitHub Profile
module AllCacheKey
extend ActiveSupport::Concern
module ClassMethods
def cache_key
pluck("COUNT(*)", "MAX(updated_at)").flatten.map(&:to_i).join("-")
end
end
end
@pgib
pgib / haml_renamer.sh
Created October 26, 2011 20:16
Rename all .haml to .html.haml
#!/bin/sh
for h in `find . -name '*.haml'`; do
if ! echo $h | grep -q ".html.haml"; then
hh=`echo $h | sed -e s/.haml/.html.haml/`
if [ -e $hh ]; then
echo "Can't rename $h to $hh because $hh already exists. :("
else
@butlermh
butlermh / wishlist.rb
Created June 16, 2011 19:29
Find out what books are available on your Amazon wishlist on Kindle
#!/usr/bin/ruby
require 'rubygems'
require 'open-uri'
require 'nokogiri'
require 'net/http'
require 'uri'
require 'amazon/aws/search'
include Amazon::AWS
@pauldatta
pauldatta / rabl_grape.rb
Created December 31, 2012 13:00
Using Rabl with Grape Trying to get view helpers to work within Rabl templates that are called from Grape. @pauldatta
# https://github.com/drapergem/draper/wiki/Using-Rails-Path-Helpers-in-Draper-Decorators-with-Grape
# https://github.com/nesquena/rabl/wiki/Using-Rabl-with-Grape
module Grape
class Endpoint
include Rails.application.routes.url_helpers
default_url_options[:host] = ::Rails.application.routes.default_url_options[:host]
end
end
@jens-a-e
jens-a-e / install_nokogiri.sh
Created December 6, 2013 16:28
Install nokogiri 1.5.10 on a synology DSM 4.3
# Make sure you have installed libxml2 via IPKG before like this:
# ipkg update && ipkg install libxml2
gem install nokogiri --version 1.5.10 -- --with-xml2-include=/opt/include/libxml2 --with-xml2-lib=/opt/lib
@jtomaszewski
jtomaszewski / asyncable.rb
Created February 16, 2014 01:09
Allow instance methods to be delayed to Sidekiq
# Idea from http://krautcomputing.com/blog/2012/10/07/how-to-make-everything-background-processable-through-sidekiq/
#
# Usage:
#
# class Synchronization
# include Asyncable
# end
#
# Then:
# Synchronization.find(12).perform_async(:synchronize, 3, 2)
@psychocandy
psychocandy / URI-monkey-patch.rb
Created July 17, 2012 16:11
Fix ArgumentError invalid %-encoding for malformed URLs
# The following should prevent an ArgumentError "invalid %-encoding (...%)" exception from being raised for malformed URLs.
# To use this code simply drop this in your rails app initializers.
# See: https://github.com/rack/rack/issues/337
# Taken from: http://stackoverflow.com/a/11162317/1075006
module URI
major, minor, patch = RUBY_VERSION.split('.').map { |v| v.to_i }
#!/usr/bin/env ruby
#
# Syncs Ruby binstubs for ruby-communal-gems.
# Run this everytime you install a new Ruby, or when you install a new gem
# with a bin/ command. (ie, when you typically do rbenv rehash)
#
# See: https://github.com/tpope/rbenv-communal-gems/issues/5
#
require 'fileutils'
# app/admin/email_previews.rb
ActiveAdmin.register_page 'Email Previews' do
content do
div '.'
end
sidebar 'Mail Previews' do
Dir['app/mailer_previews/*_preview.rb'].each do |preview_path|
preview_mailer = File.basename(preview_path, '.rb')
@olivierlacan
olivierlacan / migrate_postgresql_database.md
Last active March 24, 2022 20:30
How to migrate a Homebrew-installed PostgreSQL database to a new major version (9.3 to 9.4) on OS X. See upgraded version of this guide: http://olivierlacan.com/posts/migrating-homebrew-postgres-to-a-new-version/

This guide assumes that you recently run brew upgrade postgresql and discovered to your dismay that you accidentally bumped from one major version to another: say 9.3.x to 9.4.x. Yes, that is a major version bump in PG land.

First let's check something.

brew info postgresql

The top of what gets printed as a result is the most important: