Skip to content

Instantly share code, notes, and snippets.

@padde
padde / sidekiq_retry_schedule.rb
Last active April 19, 2023 15:31
Sidekiq retry schedule
require 'active_support/duration'
offset = 0
puts "attempt 0 immediately"
0.upto(24) do |count|
# https://github.com/mperham/sidekiq/blob/v6.1.2/lib/sidekiq/job_retry.rb#L225
average_jitter = (15 * (count + 1))
delay = count**4 + 15 + average_jitter
@padde
padde / keybase_proof.md
Created April 5, 2019 09:09
Keybase proof

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

@padde
padde / c9-elixir.sh
Last active June 1, 2023 02:09
Install Script for Erlang/Elixir/Phoenix on Cloud9
#!/usr/bin/env bash
############### USAGE ###############
#
# 1. Create a new workspace on Cloud9 using the "Blank" template
#
# 2. Run this command in the console:
# bash <(curl -fsSL https://gist.githubusercontent.com/padde/3c6301f15cbd5025e131740dae33aa95/raw/c9-elixir.sh)
#
# 3. There is no step 3!
defmodule Codepoints do
defstruct str: ""
def new(str) when is_list(str) do
new(to_string(str))
end
def new(str) when is_binary(str) do
%__MODULE__{str: str}
end
@padde
padde / lpmap.exs
Last active April 10, 2016 16:48
Limited parallel map in Elixir
defmodule Parallel do
def run(funs, max) do
tasks = for fun <- funs, do: {make_ref, fun}
results = do_run(tasks, max, 0, %{})
for {ref, _} <- tasks, do: results[ref]
end
defp do_run([], _max, 0, results) do
results
end
@padde
padde / shellscript.sh
Created March 18, 2016 09:03
Shell Script Template
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
#!/usr/bin/env sh
# Automatically renew all installed letsencrypt certificates on this server
service nginx stop
/root/letsencrypt/letsencrypt-auto renew -nvv --standalone > /var/log/letsencrypt/renew.log 2>&1
RESULT=$?
service nginx start
# optional: notify yourself of succeeded/failed renewals
@padde
padde / stars.rb
Last active January 29, 2016 20:03
Colored stars (dabbling with ANSI escape codes)
lines = `tput lines`.to_i
cols = `tput cols`.to_i
# hide cursor
print "\e[?25l"
# clear screen
print "\e[2J"
at_exit do
@padde
padde / lets-encrypt-nginx.md
Last active July 10, 2018 15:07
Let's Encrypt with Nginx

Let's Encrypt with Nginx

Here's how I set up a tiny Nginx/Rails server that uses HTTPS via a Let's Encrypt issued certificate.

https://letsencrypt.paddd.de/

Server

I use the smallest DigitalOcean droplet (512 MB) here, which is built from the "Ubuntu Ruby on Rails on 14.04" image provided by them.

@padde
padde / Rakefile
Created October 22, 2015 16:07
Pass options hash to Rake
module RakeOptionParser
def self.parse(args)
args.extras.each_with_object({}) do |arg, result|
key, value = arg.split(/:\s*/, 2)
result[key.to_sym] = value
end
end
end
namespace :foo do