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 / 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 / access.lua
Last active August 29, 2015 14:27 — forked from josegonzalez/access.lua
Simple lua file enabling oauth support for nginx via nginx-lua and access_by_lua.
- certain endpoints are always blocked
if nginx_uri == "/_access_token" or nginx_uri == "/_me" then
ngx.exit(403)
end
-- import requirements
local cjson = require "cjson"
-- setup some app-level vars
local app_id = "APP_ID"
@perusio
perusio / cors-nginx.conf
Last active August 29, 2015 14:27 — forked from alexjs/cors-nginx.conf
Slightly tighter CORS config for nginx
#
# Slightly tighter CORS config for nginx
#
# A modification of https://gist.github.com/1064640/ to include a white-list of URLs
#
# Despite the W3C guidance suggesting that a list of origins can be passed as part of
# Access-Control-Allow-Origin headers, several browsers (well, at least Firefox)
# don't seem to play nicely with this.
#
@perusio
perusio / gist:e745cc08b554a14384f3
Last active August 29, 2015 14:22 — forked from leite/gist:9236fe3033d5779cdb05
Compatibility with Lua 5.2
cd /opt
sudo wget http://www.openssl.org/source/openssl-0.9.8y.tar.gz
sudo tar zxf openssl-0.9.8y.tar.gz
sudo wget http://zlib.net/zlib-1.2.8.tar.gz
sudo tar zxf zlib-1.2.8.tar.gz
cd zlib-1.2.8
sudo ./configure
sudo make -j4 && sudo make install && cd ..
@perusio
perusio / nginx.conf
Last active August 29, 2015 14:14 — forked from peterhel/nginx.conf
prerender.io service nginx configuration
# -*- mode: nginx; mode: flyspell-prog; mode: autopair; ispell-local-dictionary: "american" -*-
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
@perusio
perusio / nginx.conf
Last active August 29, 2015 14:14 — forked from thoop/nginx.conf
# Change YOUR_TOKEN to your prerender token and uncomment that line if you want to cache urls and view crawl stats
# Change example.com (server_name) to your website url
# Change /path/to/your/root to the correct value
server {
listen 80;
server_name example.com;
root /path/to/your/root;
index index.html;
#include <stdio.h>
#include <magic.h>
int main(void)
{
char *actual_file = "/file/you/want.yay";
const char *magic_full;
magic_t magic_cookie;
/*MAGIC_MIME tells magic to return a mime of the file, but you can specify different things*/
magic_cookie = magic_open(MAGIC_MIME);
#! /bin/sh
#
# description: Kyoto Tycoon is a lightweight database server.
# processname: ktserver
# config: /usr/local/etc/ktserver.conf
# pidfile: /var/run/ktserver.pid
# Source function library.
. /etc/init.d/functions