Skip to content

Instantly share code, notes, and snippets.

View fnordfish's full-sized avatar

Robert Schulze fnordfish

View GitHub Profile

Keybase proof

I hereby claim:

  • I am fnordfish on github.
  • I am fnordfish (https://keybase.io/fnordfish) on keybase.
  • I have a public key ASAsnbLeS3CQ3GCuWeQ8aT64rQwmS0BcH_jMEuBN8-HP_Ao

To claim this, I am signing this object:

@fnordfish
fnordfish / hamlit_plugin.rb
Last active January 12, 2017 21:02
Padrino plugin for using Using hamlit as redering engine instead of haml
##
# Use hamlit instead of haml for rendering
# This is basically a copy of the existing integration for slim
RENDERING=<<'RUBY'
module Padrino
module Helpers
module OutputHelpers
##
# Handler for Hamlit templates.
@fnordfish
fnordfish / SpotifyStartup.app
Last active March 5, 2021 07:53
Run Spotify cache in a RamDisk. Handles quiting and unmounting.
property LookTime : 10 -- interval to check process
property RamDiskSizeMB : 128 -- size of the Ramdisk in MB
on mount()
do shell script "diskutil erasevolume HFS+ 'SpotifyRamDisk' `hdiutil attach -nomount ram://" & (RamDiskSizeMB * 2048) & "`"
end mount
on link()
do shell script "ln -fs '/Volumes/SpotifyRamDisk' ~/Library/Caches/com.spotify.client"
end link
@fnordfish
fnordfish / sidekiq_sequel_validate_connection_middleware.rb
Last active October 5, 2016 17:46
An experimental Sidekiq middleware that validates the Sequel connection before each run.
module SidekiqSequel
module Middleware
class Server
attr_reader :db
def initialize(options = nil)
@db = options[:db]
@max_retry = options.fetch(:max_retry, 5)
@error_classes = @db.send(:database_error_classes).dup.freeze
end
@fnordfish
fnordfish / config_initializers_yaks.rb
Last active May 11, 2016 10:12
A Padrino (0.13.2) Initializer for Yaks
# config/initializers/yaks.rb
require "yaks-sinatra"
# Usage:
# In your "app/app.rb": `register YaksInitializer`
module YaksInitializer
def self.registered(app)
# code run on application `register YaksInitializer`
# this code is run every time `app.rb` is reloaded
app.register Yaks::Sinatra
@fnordfish
fnordfish / collection_mapper.rb
Last active May 3, 2016 13:52
A Yaks policy to work on Sequel::Dataset (without converting them to Array first)
module YaksSequel
class CollectionMapper < Yaks::CollectionMapper
attr_reader :collection_dataset
def call(collection, *args)
return super unless collection.is_a?(Sequel::Dataset)
@collection_dataset = collection
if collection.opts[:eager_graph]
super(collection.all, *args)
@fnordfish
fnordfish / safe_refresh_materialized_view_concurrently.sql
Last active April 28, 2016 14:35
Refresh a materialized view concurrently won't work when it's not populated yet. This function tries "concurrently" first and falls back to normal refresh.
CREATE OR REPLACE FUNCTION safe_refresh_materialized_view_concurrently(_name regclass)
RETURNS void AS $$
BEGIN
EXECUTE 'REFRESH MATERIALIZED VIEW CONCURRENTLY ' || _name;
EXCEPTION
-- when a materialized view is not populated, concurrently will not work and throw feature_not_supported
WHEN feature_not_supported THEN
EXECUTE 'REFRESH MATERIALIZED VIEW ' || _name;
END
$$ LANGUAGE plpgsql;
#!/bin/bash
add_dns_config() {
local interface=$1; shift
sudo networksetup -setdnsservers "${interface}" $@
}
main() {
local servers=
servers=()
local line=
@fnordfish
fnordfish / current_utc_offsets.rb
Last active November 12, 2015 17:27
generate a list of all current UTC offsets for a given country
#!/usr/bin/env duct # ruby
# Usage:
# duct current_uts_offsets.rb <Country as its ISO 3166 code> <strftime-format>
# Example:
# duct current_uts_offsets.rb US
# #=> US: -0500 -0600 -0700 -0800 -0900 -1000
# duct current_uts_offsets.rb RU '%:z'
# #=> RU: +02:00 +03:00 +04:00 +05:00 +06:00 +07:00 +08:00 +09:00 +10:00 +11:00 +12:00
require 'time'
@fnordfish
fnordfish / Vagrantfile
Last active November 19, 2015 10:48
automatically mount nfs share from your Vagrant guest onto your OS X host
Vagrant.configure(2) do |global_config|
global_config.vm.define :my_project do |config|
#
# ... All your stuff ...
#
# Auto-Mount the boxes "/home/vagrant" onto your local machine
if Vagrant.has_plugin? 'vagrant-triggers'
def box_ip(config)
if (net_cgf = config.vm.networks.find {|k, _| k == :private_network})