Skip to content

Instantly share code, notes, and snippets.

View tomeduarte's full-sized avatar

Tomé Duarte tomeduarte

View GitHub Profile
@tomeduarte
tomeduarte / ovpn-writer.sh
Created August 23, 2016 17:53
Script to generate an OpenVPN client configuration file in the unified format
#!/bin/sh
##
## Usage: ./ovpn-writer.sh SERVER CA_CERT CLIENT_CERT CLIENT_KEY SHARED_SECRET > client.ovpn
##
## Example invocation (note it must be run as root since key and cert files are protected
## ./ovpnwritter titty.nipples.org /etc/easy-rsa/pki/ca.crt /etc/easy-rsa/pki/issued/client.crt /etc/easy-rsa/pki/private/client.key /etc/openvpn/ta.key > iphone.ovpn
##
## Tested and works with OpenVPN Connect 1.0.7 build 199 (iSO 64-bit) on iOS 9.3.3
##
@tomeduarte
tomeduarte / keybase.md
Created August 10, 2016 14:57
keybase.io

Keybase proof

I hereby claim:

  • I am tomeduarte on github.
  • I am tomeduarte (https://keybase.io/tomeduarte) on keybase.
  • I have a public key whose fingerprint is 2D2B F7AF B5DB 2CD5 C61A 09CF 1A98 170C 387C 3673

To claim this, I am signing this object:

@tomeduarte
tomeduarte / gist:6340205
Last active December 21, 2015 17:28
Sample (and simple) NGINX configuration as a load-balancer, using SaltStack's peer communication to retrieve list of backend servers.
# /srv/salt/shared/nginx/files/sites-available/default.lb
upstream app_nodes {
# Build list of backend servers
# using peer communication as the mine is cached and slow to pick up new hosts
{% for server,ips in
salt['publish.publish'](
'G@roles:appnode',
'network.ip_addrs', expr_form='compound').items() -%}
# host: {{ server }}
{% for ip in ips -%}
@tomeduarte
tomeduarte / i18n_registry.rb
Created March 15, 2013 23:55
A Ruby on Rails initializer which binds I18n.translate and logs every lookup to logs/i18n_registry.log. Tested on Rails 3.
# adapted from: http://stackoverflow.com/a/10211540/514700
module I18n
module Registry
protected
def lookup(locale, key, scope = [], options = {})
@log ||= Logger.new(File.join(Rails.root, 'log', 'i18n_registry.log'))
@log.info "i18n lookup - key: #{key} | locale: #{locale} | scope: #{scope}"
super
end
end
@tomeduarte
tomeduarte / truncate_name
Created September 6, 2011 11:03
rails helper to truncate a string to max 40 characters, without breaking words.
def truncate_name(name)
name.gsub(/^(.{40}[\w.]*)(.*)/) {$2.empty? ? $1 : $1 + '...'}
end