Skip to content

Instantly share code, notes, and snippets.

View noniq's full-sized avatar

Stefan Daschek noniq

View GitHub Profile
@noniq
noniq / gist.rb
Last active September 15, 2022 13:42
Code reloading with Sidekiq and Zeitwerk (if not using Rails)
loader = Zeitwerk::Loader.new
loader.push_dir(__dir__)
if ENV['RACK_ENV'] == 'production'
loader.setup
Zeitwerk::Loader.eager_load_all
else
loader.enable_reloading
loader.setup
Sidekiq.configure_server do |config|
config[:reloader] = ->(&block){ loader.reload; block.call }
@noniq
noniq / flowdock-archive-to-html.rb
Last active July 1, 2022 11:49
Convert the messages.json file from an exported Flowdock flow into a static HTML page.
#!/usr/bin/env ruby
# Convert an exported Flowdock flow into a static HTML document.
#
# Usage:
#
# flowdock-archive-to-html messages.json > messages.html
#
# The script assumes that there is a subdirectory `files` containing all files referenced in the exported flow. (This is exactly the
# directory structure you get if you unzip an archive downloaded from Flowdock.)
@noniq
noniq / capistrano_rsync.rb
Created August 30, 2017 16:46
Simple plugin for Capistrano 3.7+ to deploy via rsync
require 'capistrano/scm/plugin'
class Capistrano::SCM
# Usage: Add this to your `Capfile`:
#
# require_relative "lib/capistrano_rsync" # adapt path as needed
# install_plugin Capistrano::SCM::Rsync
#
# Note that this you need to deactivate any other SCM plugins (there can only be one SCM plugin active at any time)-
#
inherit_from: https://raw.githubusercontent.com/die-antwort/style/master/rubocop.yml
AllCops:
Exclude:
- '**/*.erb'
- 'bin/**/*'
- 'db/**/*'
- 'config/initializers/simple_form*.rb'
- 'features/**/*'
- 'lib/file_column/*'
@noniq
noniq / logical.pl
Last active October 22, 2016 21:29
% Lösung des aktuellen (04/2010) P.M.-LogikRätsels
% ================================================
%
% http://www.pm-magazin.de/de/onlinetraining/logik_trainer/logikraetsel.asp
%
% Der Brite Samuel Farwell gehört zu jenen Pionieren des modernen Segelsports,
% die heute kaum noch jemand kennt. Mehrfach versuchte er zu Beginn des
% 20. Jahrhunderts alleine in seinem Boot die Welt zu umsegeln – ohne jemals
% dieses hoch gesteckte Ziel zu erreichen.
%

Keybase proof

I hereby claim:

  • I am noniq on github.
  • I am noniq (https://keybase.io/noniq) on keybase.
  • I have a public key ASBaNOMZ1twHzYDHXdFvNQCqBA0TDcZQlk6NMSptpLxN3wo

To claim this, I am signing this object:

@noniq
noniq / erb_zip_file_generator.rb
Last active June 9, 2016 15:04
Zip file generator in ruby, suitable for templating OOXML documents (DOCX, XLSX, …)
# This is a simple example which uses rubyzip to recursively generate a zip file from the contents of a specified directory. The
# directory itself is not included in the archive, rather just its contents.
#
# The generator has been extended to support ERB templates: Files with an extension ending in `.erb` will be processed by ERB
# before they are added to the archive (the filename in the archive will have `.erb` stripped).
#
# Suitable for templating OOXML documents (eg. DOCX or AXSLX): Just create the template document in the office application of your
# choice, rename the extension to ".zip" and unzip the file. Now add ERB code to individual files as needed (for DOCX you’ll most
# likely want to edit `word/document.xml`). Don't forget to also add an additonial `.erb` extension to those files! Then run
# ErbZipGenerator on the top level directory and with a suitable output filename – done!
@noniq
noniq / gist:4147547
Created November 26, 2012 10:25
Prolog nonogram solver
% Succeeds if `Lines` represents the nonogram specified by `ColumnSpecs` and
% `LineSpecs`. For example:
%nonogram
% 1
% 2 1 2
% +------
% 1 | . # . ColumnSpecs = [[2], [1,1], [2]]
% 1 1 | # . # LineSpecs = [[1], [1,1], [3]]
% 3 | # # # Lines = [[0,1,0], [1,0,1], [1,1,1]]
nonogram(ColumnSpecs, LineSpecs, Lines) :-
@noniq
noniq / cleanup-old-containers.sh
Last active January 15, 2016 11:54
A shell script to remove all exited docker containers that are older than a certain threshold. Customize the filter expression to restrict this to a certain group of containers. Should work on Linux and Mac OS.
#!/bin/bash
FILTER="--filter label=myapp"
THRESHOLD=$((7 * 24 * 60 * 60))
NOW=$(date +%s)
USE_BSD_DATE=$(date -j >/dev/null 2>&1 && echo 1)
function date_to_timestamp {
if [[ $USE_BSD_DATE ]]; then
@noniq
noniq / human_nr.html
Last active December 21, 2015 16:28
Convert numbers from 1 to 999999 into german strings. Script should prompt for a number and show result using an JavaScript-alert. Must run in Chrome out of the box, just by loading the HTML file.
<pre>
<script>
function human_nr(n){
// Make `prompt` and `alert` no-ops when run in test mode
prompt = function() { return n };
alert = function() {};
// To extract the bare, minimized, executable script:
// * Copy the lines between the markers into a new file