Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View perusio's full-sized avatar

António P. P. Almeida perusio

View GitHub Profile
using GeometryBasics
x(a::AbstractVector) = first(a)
y(a::AbstractVector) = last(a)
x(a::AbstractMatrix) = a[ :, 1 ]
y(a::AbstractMatrix) = a[ :, 2 ]
function orientation(p::AbstractVector, q::AbstractVector, r::AbstractVector)::Int
val = ( y(q) - y(p) ) * ( x(r) - x(q) ) - ( x(q) - x(p) ) * ( y(r) - y(q) )
return (val ≈ 0) ? 0 : ( (val > 0) ? 1 : 2 )
@perusio
perusio / sharded-balancing-nginx.txt
Created March 21, 2012 23:58 — forked from zzzcpan/sharded-balancing-nginx.txt
Sharded load balancing with nginx and perl
# Balancing over 4 nodes by hashing URI (consistently with md5)
# onto 16 shards.
upstream x0 { server 192.168.0.2; server 192.168.0.3 backup; }
upstream x1 { server 192.168.0.2; server 192.168.0.4 backup; }
upstream x2 { server 192.168.0.2; server 192.168.0.5 backup; }
upstream x3 { server 192.168.0.2; server 192.168.0.3 backup; }
upstream x4 { server 192.168.0.3; server 192.168.0.4 backup; }
@perusio
perusio / gist:4404063
Last active July 29, 2017 02:08 — forked from jpluscplusm/gist:4366287
A pirate bay proxy configuration for Nginx
server {
listen 80; # IPv4
listen [::]:80 ipv6only=on; # IPv6
server_name ~^(?<thishost>[^.]+\.)?subdomain\.example\.com$;
access_log off;
location / {
## Resolve the upstream address using this DNS server or any other.
## Choose the one that suits you.
@perusio
perusio / gitio
Created May 10, 2013 11:45 — forked from defunkt/gitio
#!/usr/bin/env ruby
# Usage: gitio URL [CODE]
#
# Turns a github.com URL
# into a git.io URL
#
# Copies the git.io URL to your clipboard.
url = ARGV[0]
code = ARGV[1]
@perusio
perusio / gist:5212090
Last active December 15, 2015 05:49 — forked from anonymous/gist:5212082

#Authorize.net test credentials

API Login ID: 2VcPa843DT6

Transaction Key: 9g5a2x66nL9RmUzv

Transaction mode: Developer test account transactions

Default credit card transaction type: Authorization only

@perusio
perusio / gist:5017911
Last active December 14, 2015 02:59 — forked from shrikeh/csrf-lua.conf
server {
listen 80;
root /root/to/your/docroot;
proxy_redirect off;
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
@perusio
perusio / clock_gettime
Created November 4, 2015 04:00 — forked from calio/clock_gettime
clock_gettime() via LuaJIT + FFI
local ffi = require("ffi")
ffi.cdef[[
typedef long time_t;
typedef int clockid_t;
typedef struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
} nanotime;
@perusio
perusio / gettimeofday.lua
Created November 4, 2015 03:48 — forked from joshthecoder/gettimeofday.lua
gettimeofday() via LuaJIT + FFI
local ffi = require("ffi")
ffi.cdef[[
typedef long time_t;
typedef struct timeval {
time_t tv_sec;
time_t tv_usec;
} timeval;
int gettimeofday(struct timeval* t, void* tzp);
@perusio
perusio / Vector.lua
Created October 29, 2012 12:16 — forked from mebens/Vector.lua
Vector class for my tutorial on Lua metatables.
Vector = {}
Vector.__index = Vector
function Vector.__add(a, b)
if type(a) == "number" then
return Vector.new(b.x + a, b.y + a)
elseif type(b) == "number" then
return Vector.new(a.x + b, a.y + b)
else
return Vector.new(a.x + b.x, a.y + b.y)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>index</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Aaron Gibralter">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js" type="text/javascript" charset="utf-8"></script>
</head>