Skip to content

Instantly share code, notes, and snippets.

@henrik
henrik / yosemite_upgrade_notes.md
Last active December 30, 2015 02:29
Yosemite upgrade notes

Yosemite upgrade notes

From a (mostly) Ruby on Rails developer.

After doing the below everything seems to work (some of it worked before doing anything), including Ruby, Gems, RVM, Homebrew, VirtualBox/Vagrant VMs, Pow, tmux, git, vim.

  1. Did a full-disk backup that I can restore from
  2. Moved out /usr/local to avoid super slow install, per option 1 in https://jimlindley.com/blog/yosemite-upgrade-homebrew-tips/: sudo mv /usr/local ~/local
  3. Upgraded to Yosemite
  4. Restored /usr/local, per option 1 in https://jimlindley.com/blog/yosemite-upgrade-homebrew-tips/: sudo mv ~/local /usr
@henrik
henrik / using_string_range.rb
Last active July 12, 2019 08:18
Is a given time in a time range, in Ruby?
# Note: upper bound is 12:01:59 (you could use second precision to get around this, e.g. "12:01:00")
time = Time.mktime(2014, 10, 14, 12, 1)
allowed_ranges = [
"11:59".."12:01",
]
formatted_time = time.strftime("%H:%M")
p allowed_ranges.any? { |range| range.cover?(formatted_time) }
@inscapist
inscapist / Dockerfile
Last active April 11, 2020 08:32
Docker + Rails configuration + Docker Sync
# This Dockerfile is intended to build a production-ready app image.
#
# This is not required for development environments
FROM sagittaros/rails-base:latest
MAINTAINER Felix Tioh <felix.tioh@crowdo.com>
COPY . /app
WORKDIR /app
EXPOSE 5000
@adamico
adamico / collection_check_boxes_input.rb
Last active April 28, 2020 15:12 — forked from mattclar/simple_form.rb
This fork adds a custom horizontal form wrapper and merges append/prepend in a 'group' wrapper
#app/inputs/collection_check_boxes_input.rb
class CollectionCheckBoxesInput < SimpleForm::Inputs::CollectionCheckBoxesInput
def item_wrapper_class
"checkbox-inline"
end
end
@decors
decors / delegate.cr
Created January 26, 2017 04:35
Crystal-lang simple delegator
class Delegator(T)
def initialize(@object : T)
end
def self.delegate(object)
new(object)
end
forward_missing_to @object
end

This is a proof-of-concept of a couple of concurrent data structures written in Ruby.

The implementations are heavily commented for those interested. There are benchmarks (with results) included below. The results are interesting, but, as always, take with a grain of salt.

Data structures

AtomicLinkedQueue is a lock-free queue, built on atomic CAS operations.

@bantic
bantic / rails_route_recognizer.rb
Last active September 9, 2022 12:22
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
@zenhob
zenhob / generic_api.rb
Created April 4, 2014 03:57
Starter Ruby client for your REST API, based on Faraday
#
# This module is a starter Ruby client for your REST API, based on Faraday:
# https://github.com/lostisland/faraday/
#
# It supports HTTP basic authentication, sending and recieving JSON, and simple error reporting.
# I use this as a basis for building API clients in most of my Ruby projects.
#
# Use it like this:
#
# http = GenericApi.connect('http://localhost:3000/', 'myname', 'secret')
@PatrickKalkman
PatrickKalkman / secrets.js
Created February 2, 2020 18:40
Reading secrets from the file system
// dependencies
const fs = require('fs');
const log = require('../log');
const dockerSecret = {};
dockerSecret.read = function read(secretNameAndPath) {
try {
return fs.readFileSync(`${secretNameAndPath}`, 'utf8');
} catch(err) {
@MTuner
MTuner / fix-sublimetext-subpixel.txt
Last active March 31, 2023 21:44
Fixing font rendering/aliasing in Sublime Text in MacOS Mojave
Apple removed colored sub-pixel antialiasing in MacOS Mojave
(https://developer.apple.com/videos/play/wwdc2018/209/ starting from ~28min)
To make fonts look normal in Sublime Text, add to Preferences:
// For the editor
"font_options": [ "gray_antialias" ],
// For the sidebar / other elements
"theme_font_options": [ "gray_antialias" ],