Skip to content

Instantly share code, notes, and snippets.

Install ree with the following commands: CFLAGS="-O2 -fno-tree-dce -fno-optimize-sibling-calls" rbenv install ree-1.8.7-2012.02

Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

This guide enables you to install (ruby-build) and use (rbenv) multiple versions of ruby, isolate project gems (gemsets and/or bundler), and automatically use appropriate combinations of rubies and gems.

TL;DR Demo

# Ensure system is in ship-shape.

aptitude install git zsh libssl-dev zlib1g-dev libreadline-dev libyaml-dev

Speed up integration tests in Rails 5 app

Rails 5 recompiles templates on every request in test env. Fix will be released only in 5.0.2.

Add this lines to test helper to get the performance now (I've got x2 improvement):

class << ActionView::LookupContext::DetailsKey
 def clear
@freiden
freiden / macos_minikube_install.md
Last active August 26, 2017 20:57
Installation of minikube on MacOS

1/ Install Docker for Mac through DMG

2/ Install minikube with Homebrew:

  • brew cask install minikube

3/ Install kubernetes-cli with Homebrew:

  • brew install kubectl

4/ Install xhyve driver:

  • brew install docker-machine-driver-xhyve
@freiden
freiden / rails http status codes
Created September 11, 2018 08:40 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@freiden
freiden / gist:c6f38f96595570179bb7c067ec8d7d57
Created September 13, 2018 17:04 — forked from cpjolicoeur/gist:3590737
Ordering a query result set by an arbitrary list in PostgreSQL

I'm hunting for the best solution on how to handle keeping large sets of DB records "sorted" in a performant manner.

Problem Description

Most of us have work on projects at some point where we have needed to have ordered lists of objects. Whether it be a to-do list sorted by priority, or a list of documents that a user can sort in whatever order they want.

A traditional approach for this on a Rails project is to use something like the acts_as_list gem, or something similar. These systems typically add some sort of "postion" or "sort order" column to each record, which is then used when querying out the records in a traditional order by position SQL query.

This approach seems to work fine for smaller datasets, but can be hard to manage on large data sets with hundreds (or thousands) of records needing to be sorted. Changing the sort position of even a single object will require updating every single record in the database that is in the same sort group. This requires potentially thousands of wri

@freiden
freiden / gist:eaa86d0d824511b747166921d3dc21fe
Created October 16, 2018 13:06 — forked from ryanlecompte/gist:1283413
Providing an ActiveRecord-like before_filter capability to arbitrary Ruby classes
# First the end result of what we want:
class Foo
before_hook :whoa
before_hook :amazing
def test
puts "This is kinda cool!"
end
@freiden
freiden / update_rubygem_versions.rb
Created November 11, 2019 21:20
Update ruby gems versions
for version in $(rbenv versions --bare); do RBENV_VERSION=$version gem update --system; done
@freiden
freiden / GitHub Wiki Subtree Storage.markdown
Created December 3, 2020 07:19 — forked from yukoff/GitHub Wiki Subtree Storage.markdown
Store and edit GitHub wikis within the main project repository.

Project documentation

The project documentation (stored in the docs directory) is a git subtree of the project wiki. This allows for the documentation to be referenced and edited from within the main project.

Initial local setup

When cloning the main project repository for the first time, the wiki repository must be added as a remote.

git remote add wiki https://github.com//.wiki.git

@freiden
freiden / rails_route_recognizer.rb
Created January 25, 2021 15:01 — forked from bantic/rails_route_recognizer.rb
Programmatically list all routes (/paths) from within a rails app.
class RouteRecognizer
attr_reader :paths
# To use this inside your app, call:
# `RouteRecognizer.new.initial_path_segments`
# This returns an array, e.g.: ['assets','blog','team','faq','users']
INITIAL_SEGMENT_REGEX = %r{^\/([^\/\(:]+)}
def initialize