Skip to content

Instantly share code, notes, and snippets.

@padde
padde / NSData+CRC32.h
Created July 27, 2012 11:34
NSData CRC32 Category
@interface NSData (CRC32)
-(NSUInteger) crc32;
@end
@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 / openvpn.md
Last active April 30, 2018 17:11
OpenVPN on Ubuntu 12.10 at DigitalOcean

OpenVPN on Ubuntu 12.10 at DigitalOcean

Install OpenVPN

sudo apt-get install openvpn

Generate Server Certificates

sudo cp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0 /etc/openvpn/easy-rsa2

cd /etc/openvpn/easy-rsa2

@padde
padde / unicode_pattern_matching.exs
Created June 5, 2015 17:10
Elixir Unicode Pattern Matching
iex> <<first, rest::binary>> = "☺ how dare you, unicode!"
"☺ how dare you, unicode!"
iex> <<first>>
<<226>>
iex> rest
<<152, 186, 32, 104, 111, 119, 32, 100, 97, 114, 101, 32, 121, 111, 117, 44, 32, 117, 110, 105, 99, 111, 100, 101, 33>>
@padde
padde / chained-comparison.rb
Created April 20, 2012 15:45
chained comparison in Ruby
# Chained comparisons in Ruby
# inspired by http://coffeescript.org/#comparisons
# as well as http://refactormycode.com/codes/1284
[:<, :>, :<=, :>=].each do |operator|
[Float, Fixnum, Rational, Comparable].each do |klass|
klass.class_eval do
alias_method "_#{operator}", operator
define_method operator do |rhs|
send("_#{operator}", rhs) && rhs
@padde
padde / filter_matching.exs
Last active May 8, 2017 23:31
Filter a list by pattern matching in Elixir
defmodule MyEnum do
defmacro filter_matching(collection, pattern) do
quote do
Enum.filter unquote(collection), fn
unquote(pattern) -> true
_ -> false
end
end
end
end
@padde
padde / .gitignore
Created December 2, 2011 18:58
LaTeX .gitignore
*.aux
*.glo
*.idx
*.log
*.toc
*.ist
*.acn
*.acr
*.alg
*.bbl
@padde
padde / gist:1216920
Created September 14, 2011 15:43
Rails Helper for Typekit integration
def typekit_include_tag apikey
javascript_include_tag("http://use.typekit.com/#{apikey}.js") +
javascript_tag("try{Typekit.load()}catch(e){}")
end
#!/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 / mutate.exs
Created March 24, 2015 06:25
Stream.mutate/3
defmodule MyStream do
def mutate(enum, user_acc, user) do
step = fn val, _acc -> {:suspend, val} end
next = &Enumerable.reduce(enum, &1, step)
&do_mutate([], user_acc, user, next, &1, &2)
end
defp do_mutate(values, user_acc, user, next, {:suspend, acc}, fun) do
{:suspended, acc, &do_mutate(values, user_acc, user, next, &1, fun)}
end