Skip to content

Instantly share code, notes, and snippets.

@joost
joost / .env.example
Last active June 24, 2024 23:34
Clone or pull all your Azure DevOps repo's (for all projects)
export AZURE_PERSONAL_ACCESS_TOKEN=YOUR_AZURE_ACCESS_TOKEN
export AZURE_ORGANIZATION_URL=https://dev.azure.com/YOURORG
@joost
joost / Dockerfile
Created June 28, 2016 18:37
Dockerfile for OpenCV 3.1.0 with Tesseract on Ubuntu 14.04
FROM phusion/passenger-full
# Set correct environment variables.
ENV HOME /root
ENV RUBY_VERSION 2.2.1
# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]
# ===================
@joost
joost / compare_yaml.rb
Created November 9, 2015 14:25
Compare two YAML files
def compare_yaml_hash(cf1, cf2, context = [])
cf1.each do |key, value|
unless cf2.key?(key)
puts "Missing key : #{key} in path #{context.join(".")}"
next
end
value2 = cf2[key]
if (value.class != value2.class)
@joost
joost / docker_compose.rb
Last active August 29, 2015 14:22
Homebrew Docker Compose v1.3.0rc2 Formula
# Usage:
# https://gist.githubusercontent.com/joost/20934650f68dd561fc35/raw/44629ade560e0e546ac7d2f94537a594546c5e1f/docker_compose.rb
class DockerCompose < Formula
desc "Isolated development environments using Docker"
homepage "https://docs.docker.com/compose/"
url "https://github.com/docker/compose/archive/1.3.0rc2.tar.gz"
sha256 "4e0a6c82e283e44eb551a8e57bb40c1c2768f8acaf36eb7e858c99ca4fb3d0dc"
# bottle do
# sha256 "bf8a80a39a59185add39a12e6da2b53e19e08bb09d823b1cbaf2ffdcf797c3d7" => :yosemite
@joost
joost / resize_boot2docker.sh
Last active December 14, 2022 07:34
Resize boot2docker VirtualBox image
# Steps we will take:
# 1. Change boot2docker image type (this will take long)
# 2. Resize image
# 3. Resize partion (using GParted)
#
# Also see: https://docs.docker.com/articles/b2d_volume_resize/
# Stop boot2docker
boot2docker stop

Keybase proof

I hereby claim:

  • I am joost on github.
  • I am joosth (https://keybase.io/joosth) on keybase.
  • I have a public key whose fingerprint is 3546 2624 A98A C4A1 2E7C 414D ABA4 5856 9272 EE8A

To claim this, I am signing this object:

@joost
joost / api_controller.rb
Last active July 31, 2018 06:38
Validate parameters in Rails 4 JSON API
class ApiController < ApplicationController
# FIXME: Since we cannot set ActionController::Parameters.action_on_unpermitted_parameters = :raise
# on a controller level we do this hotfix.
class ApiParameters < ActionController::Parameters
def action_on_unpermitted_parameters
:raise
end
end
def params
@joost
joost / your_model.rb
Created March 27, 2015 11:01
Sunspot reindex without removing the index
class YourModel
# Overwrite sunspot version to not remove from index.
# See: https://github.com/sunspot/sunspot/blob/16e5f620814fd4bdf43e3df158e7fdcbbd92713b/sunspot_rails/lib/sunspot/rails/searchable.rb#L206
def self.solr_reindex(options = {})
solr_index(options)
solr_clean_index_orphans
end
end
@joost
joost / json_validator.rb
Created March 26, 2015 14:13
Rails 3 / Rails 4 JSON validator
# Put this code in lib/validators/json_validator.rb
# Usage in your model:
# validates :json_attribute, presence: true, json: true
#
# To have a detailed error use something like:
# validates :json_attribute, presence: true, json: {message: :some_i18n_key}
# In your yaml use:
# some_i18n_key: "detailed exception message: %{exception_message}"
class JsonValidator < ActiveModel::EachValidator
@joost
joost / change_s3_metadata.rb
Last active August 26, 2016 01:40
Change metadata on existing S3 files
# Using v1 of Ruby aws-sdk as currently v2 seems not able to do this (broken?).
require 'aws-sdk-v1'
key = YOUR_AWS_KEY
secret = YOUR_AWS_SECRET
region = YOUR_AWS_REGION
AWS.config(access_key_id: key, secret_access_key: secret, region: region)
s3 = AWS::S3.new
bucket = s3.buckets[bucket_name]