Skip to content

Instantly share code, notes, and snippets.

local function sample(it, count, random)
local answer = {}
do
-- first element
local element = it()
if element == nil then
return answer
end
answer[1] = element
@calind
calind / agent_type.conf
Created October 12, 2011 17:44
nginx user agent type detection (requires nginx >= 1.0.4)
# agent type detection, based on idea from from http://notnotmobile.appspot.com/
map $http_user_agent $agent_type_phase1 {
default 'mobile';
'' 'unknown';
~*iphone|ipod|blackberry|palm|windows\s+ce 'mobile';
~*windows|linux|os\s+[x9]|solaris|bsd 'desktop';
~*spider|crawl|slurp|bot|feedburner 'bot';
}
map $http_x_skyfire_phone $agent_type_phase2 {
default 'mobile';
@ferrouswheel
ferrouswheel / move_to_github.sh
Created November 8, 2015 06:30
Move a launchpad repository to github
#!/bin/bash
# Destination must exist as empty repo on github
GIT_REPO="git@github.com:opencog/opencog.git"
TEMP_PATH=~/src/opencog_bzr_to_git
echo "Using $TEMP_PATH as working dir"
BRANCHES=(trunk UnityEmbodiment)
mkdir -p ${TEMP_PATH}
cd ${TEMP_PATH}
@starius
starius / count_chars.c
Created December 14, 2015 16:53
Print chars' counts as C array of ints
/* Print chars' counts as C array of ints */
#include <stdio.h>
// https://en.wikipedia.org/wiki/C_preprocessor#Token_stringification
#define xstr(s) str(s)
#define str(s) #s
#define NLETTERS 256
#define BUFSIZE (1024 * 1024)