Skip to content

Instantly share code, notes, and snippets.

View perusio's full-sized avatar

António P. P. Almeida perusio

View GitHub Profile
@perusio
perusio / gist:2154235
Created March 21, 2012 23:47
High performance tuning of Nginx
## From a post on the ML, apropos this:
## http://lowlatencyweb.wordpress.com/2012/03/20/500000-requestssec-modern-http-servers-are-fast.
## For sysctl.conf
net.ipv4.tcp_slow_start_after_idle = 0
echo "2048 64512" > /proc/sys/net/ipv4/ip_local_port_range
echo "1" > /proc/sys/net/ipv4/tcp_tw_recycle
echo "1" > /proc/sys/net/ipv4/tcp_tw_reuse
@perusio
perusio / gist:1724301
Created February 2, 2012 16:13
Workaround in PHP cURL for the 100-continue expectation
<?php
// cURL obeys the RFCs as it should. Meaning that for a HTTP/1.1 backend if the POST size is above 1024 bytes
// cURL sends a 'Expect: 100-continue' header. The server acknowledges and sends back the '100' status code.
// cuRL then sends the request body. This is proper behaviour. Nginx supports this header.
// This allows to work around servers that do not support that header.
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
// We're emptying the 'Expect' header, saying to the server: please accept the body right now.
// Read here: http://pilif.github.com/2007/02/the-return-of-except-100-continue/
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 / gist:1326701
Created October 31, 2011 01:28
Mobile device detection in Nginx with just 7 lines of configuration
### Testing if the client is a mobile or a desktop.
### The selection is based on the usual UA strings for desktop browsers.
## Testing a user agent using a method that reverts the logic of the
## UA detection. Inspired by notnotmobile.appspot.com.
map $http_user_agent $is_desktop {
default 0;
~*linux.*android|windows\s+(?:ce|phone) 0; # exceptions to the rule
~*spider|crawl|slurp|bot 1; # bots
~*windows|linux|os\s+x\s*[\d\._]+|solaris|bsd 1; # OSes
@perusio
perusio / .tmux.conf
Last active October 25, 2021 17:17
My tmux.conf
## tmux configuration.
## Inspired by: https://github.com/tony/tmux-config/blob/master/.tmux.conf
# https://github.com/seebi/tmux-colors-solarized/blob/master/tmuxcolors-256.conf
set-option -g status-style bg=colour235,fg=colour136,default # bg=base02, fg=yellow
# Easy reload config.
bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded."
# set window split
@perusio
perusio / gist:1784254
Created February 9, 2012 23:33
Nginx support for rel="canonical" HTTP headers
## As explained here: http://googlewebmastercentral.blogspot.com/2011/06/supporting-relcanonical-http-headers.html
## This is the add_header incantation to make it work.
add_header Link "<$scheme://$http_host$request_uri>; rel=\"canonical\"";
@perusio
perusio / calendar.lisp
Last active December 4, 2020 12:15
Implementation in Common Lisp of the algorithms for calendrical calculations from the book ¨Calendrical Calculations" by Dershowitz and Rheingold, 3rd edition, Cambridge University Press, 2007.
;; The following Lisp code is from ``Calendrical
;; Calculations'' by Nachum Dershowitz and Edward
;; M. Reingold, Software---Practice & Experience, vol. 20,
;; no. 9 (September, 1990), pp. 899--928 and from
;; ``Calendrical Calculations, II: Three Historical
;; Calendars'' by Edward M. Reingold, Nachum Dershowitz,
;; and Stewart M. Clamen, Software---Practice & Experience,
;; vol. 23, no. 4 (April, 1993), pp. 383--404.
;; This code is in the public domain, but any use of it
@perusio
perusio / cal.lua
Last active August 16, 2020 19:15
Implementation of a Calendrical calculation algorithm
-- -*- mode: lua -*-
--
-- Stolen from http://www.cs.tufts.edu/~nr/drop/lua/cal.lua
--
-- The following Lua code is adapted from ``Calendrical Calculations'' by Nachum
-- Dershowitz and Edward M. Reingold, Software---Practice & Experience,
-- vol. 20, no. 9 (September, 1990), pp. 899--928 and from
-- ``Calendrical Calculations, II: Three Historical Calendars'' by Edward M.
-- Reingold, Nachum Dershowitz, and Stewart M. Clamen, Software---Practice
-- \& Experience, vol. 23, no. 4 (April, 1993), pp. 383--404.
@perusio
perusio / gist:1087950
Created July 17, 2011 19:13
Adding ronn to the emacs auto-mode-alist for enabling markdown-mode as the major-mode
;;; This is to enable ronn files https://github.com/rtomayko/ronn to be treated as markdown files.
(add-to-list 'auto-mode-alist '("\\.ronn$" . markdown-mode))
@perusio
perusio / data.json
Created September 19, 2019 04:49
UP42: GeoJSON TestQuery output with price estimation
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.