Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am anselm-helbig on github.
  • I am mnemonikk (https://keybase.io/mnemonikk) on keybase.
  • I have a public key ASDr7ygYF0wF1tNwE87z4eVN2qj4lL5ZoCp9nokJu2u_zAo

To claim this, I am signing this object:

require 'test_helper'
module Kindlemd
Chapter = Struct.new(:position, :nxt, :previous) do
def self.normalize(chapters)
chapters = chapters.map { |h| new(h[:position]) }.sort_by(&:position)
chapters.each_cons(2) { |previous, nxt|
previous.nxt = nxt
nxt.previous = previous
@anselm-helbig
anselm-helbig / caching.rb
Created August 25, 2016 14:38
memoize macro for ruby
module Caching
def cache(method)
mod = Module.new do
define_method(method) do |*args, &block|
instance_variable_get("@#{method}") ||
instance_variable_set("@#{method}", super(*args, &block))
end
end
prepend mod
end
@anselm-helbig
anselm-helbig / copy_dns_zones.rb
Last active July 20, 2016 17:04 — forked from prein/copy_dns_zones.rb
Copy DNS zones from CloudFlare to Route53
#!/usr/bin/env ruby
require "bundler/inline"
gemfile do
gem "rubyflare"
gem "route53"
end
require "yaml"
@anselm-helbig
anselm-helbig / diamond.rb
Last active June 6, 2016 10:38
OO solution to diamond kata
require "forwardable"
class Diamond
class Canvas
def initialize(size)
@size = size
end
def []=(x, y, value)
lines[size - y][x + size] = value
(setq gnus-select-method
'(nnimap "wimdu"
(nnimap-address "imap.gmail.com")
(nnimap-server-port 993)
(nnimap-stream ssl)
(nnir-search-engine imap)))
(add-to-list 'gnus-secondary-select-methods
'(nnimap "gmail"
(nnimap-address "imap.gmail.com")
(nnimap-server-port 993)
(defun avg-dired-enter-or-find-file-other-window ()
(interactive)
(if (file-directory-p (dired-get-file-for-visit))
(dired-view-file)
(dired-find-file-other-window)))
(define-key dired-mode-map (kbd "l") #'avg-dired-enter-or-find-file-other-window)
@anselm-helbig
anselm-helbig / calsync-extract-icalendar-fixtures.el
Last active January 2, 2016 19:39
Extract icalendar fixtures in emacs
(defvar calsync-extract-icalendar-fixtures--fixture-regexp
"<<-?\\(\\w+\\)\n\\(\\(.*\\\\r\n\\)*\\)\\1")
(defun calsync-extract-icalendar-fixtures ()
"Extracts heredocs into icalendar fixtures."
(interactive)
(let ((offer-ids (calsync-extract-icalendar-fixtures--offer-ids))
(fixture-dir
(format "%s/%s" (expand-file-name "../fixtures/icalendar")
(calsync-extract-icalendar-fixtures--find-cassette-name))))
@anselm-helbig
anselm-helbig / gist:3667085
Created September 7, 2012 15:18
Get a backtrace from a hanging ruby process
Say you have one process in an endless loop. You know its process id:
ruby -e 'puts $$; loop {}'
=> 30360, hangs
You can attach to this process with gdb now and make it print a backtrace to stdout:
gdb -p 30360
GNU gdb (GDB) 7.5
Copyright (C) 2012 Free Software Foundation, Inc.