Skip to content

Instantly share code, notes, and snippets.

View fornellas's full-sized avatar

Fabio Pugliese Ornellas fornellas

  • Dublin, Ireland
  • 17:30 (UTC +01:00)
View GitHub Profile
This is a simple OpenVPN setup, with shared HTTPS port. To set up your own Certificate Authority, the easiest way is to follow: https://openvpn.net/index.php/open-source/documentation/howto.html#pki.
Once everything is set up, distribute client.ovpn + client's crt + client's key to each client and everything should work.
@fornellas
fornellas / flock.rb
Last active August 29, 2015 14:16
Lock concurrent command execution
def procedure
puts 'Runnig...'
sleep 10
end
File.open($0) do |io|
if io.flock(File::LOCK_EX|File::LOCK_NB)
procedure
else
puts 'Already running.'
@fornellas
fornellas / parallel_tasks.rb
Created March 21, 2015 05:26
Class to execute jobs in parallel threads, with maximum number of threads.
# Run tasks in parallel threads
class ParallelTasks
# Set max number of parallel threads
def initialize limit
@limit = limit
@ids = []
@tasks = {}
end
@fornellas
fornellas / gem.gemspec
Created April 10, 2015 18:06
Ruby Gem Template
Gem::Specification.new do |s|
# Required gemspec attributes
# author=
# authors=
# files
# name
# platform=
# require_paths=
# rubygems_version
# summary
@fornellas
fornellas / Atom Packages
Last active March 24, 2016 19:01
Atom Settings
aligner
aligner-ruby
autocomplete-plus
cucumber
file-icons
git-timecop
highlight-selected
keyboard-scroll
language-docker
language-haml
@fornellas
fornellas / socat_vpn.sh
Created February 22, 2016 18:23
socat VPN
LOCAL_TUN_ADDRESS=10.0.0.0/24
REMOTE_TUN_ADDRESS=10.0.1.0/24
REMOTE_HOSTNAME=server-name.intranet
sudo socat -d TUN:"$LOCAL_TUN_ADDRESS",up 'EXEC:ssh -i '"$HOME/.ssh/id_rsa"' '"$USER"'@'"$REMOTE_HOSTNAME"' "sudo socat - TUN:'"$REMOTE_TUN_ADDRESS"',up"'
DOMAIN=example.com
PORT=443
echo | openssl s_client -connect $DOMAIN:$PORT 2>&1 | gawk '/-----BEGIN CERTIFICATE-----/{S=1}{if(S)print}/-----END CERTIFICATE-----/{exit}' > $DOMAIN.cer
REPO="$HOME/src/dotfiles.git"
GITHUB_REPO_URL="git@github.com:fornellas/dotfiles.git"
mkdir -p "$REPO"
cd "$REPO"
git init --bare
cd -
alias dotfiles='git --git-dir="$REPO" --work-tree="$HOME"'
dotfiles remote add origin $GITHUB_REPO_URL
dotfiles pull origin
@fornellas
fornellas / Rakefile
Created June 24, 2016 17:03
simplecov with multiple Ruby executions
# Ensure that all ruby process instances use Simplecov
task :simplecov_setup do
ENV['RUBYLIB'] = "#{Dir.pwd}:#{ENV['RUBYLIB']}"
ENV['RUBYOPT'] = '-r configure_simplecov'
sh 'rm -rf coverage/'
end
# Generate a final report, with all merged results
task :simplecov_report do
require 'simplecov'
@fornellas
fornellas / tcp_tap.rb
Created July 12, 2016 16:38
Print TCP connection traffic to stdout.
#!/usr/bin/env ruby
require 'socket'
require 'thwait'
unless ARGV.size == 2
STDERR.puts "Usage: #{$PROGRAM_NAME} listen_address:listen_port target_address:target_port"
exit 1
end
listen_address, listen_port = ARGV.shift.split(':')