Skip to content

Instantly share code, notes, and snippets.

@alanbriolat
alanbriolat / gist:630048
Created October 16, 2010 17:20
Checking an IP address is within a range, the correct way (NOT using regular expressions!)
>>> ip = "192.168.75.10"
>>> a, b, c, d = map(int, ip.split('.'))
>>> a == 192 and b == 168 and 72 <= c <= 79 and 1 <= d <= 254
True
@alanbriolat
alanbriolat / default.conf
Created September 28, 2011 14:01
nginx userdir + PHP-FPM
server {
listen 80;
server_name localhost;
# ... other default site stuff, document root, etc. ...
location ~ ^/~(?<userdir_user>.+?)(?<userdir_uri>/.*)?$ {
alias /home/$userdir_user/public_html$userdir_uri;
index index.html index.htm index.php;
autoindex on;
@alanbriolat
alanbriolat / fcgiwrap_gitolite.conf
Created October 3, 2011 15:38
fcgiwrap setup for gitweb + gitolite
; Spawn fcgiwrap as the user owning the git repositories, with a socket writeable by nginx
[fcgi-program:fcgiwrap_gitolite]
command = /usr/sbin/fcgiwrap
user = gitolite
socket = unix:///var/run/supervisor/%(program_name)s.sock
socket_owner = gitolite:nginx
socket_mode = 0770
@alanbriolat
alanbriolat / redmine.conf
Created October 6, 2011 09:25
nginx configuration for redmine
server {
listen 80;
server_name projects.hexi.co redmine.codescape.net;
root /home/alan/www/redmine.codescape.net/public;
include global/restrictions.conf;
location / {
try_files $uri @redmine_fcgi;
}
@alanbriolat
alanbriolat / sshroute.py
Created October 11, 2011 22:48
SSH tunnel script generator
#!/usr/bin/python
import getopt, sys, pprint
pp = pprint.PrettyPrinter(indent=4)
shortopts = 'h:l:r:'
locals = []
remotes = []
-- A simple IRC bot using http://www.haskell.org/haskellwiki/Roll_your_own_IRC_bot
-- as a starting point
module HBot where
import Data.List
import Network
import System.IO
import System.Console.ANSI
import Control.Applicative ((<$))
import Control.Monad.Reader hiding (join)
@alanbriolat
alanbriolat / foo.f90
Created February 8, 2012 00:08
gfortran matrix multiplication result size bug
program foo
real, parameter :: A(2, 3) = reshape((/ 0, 0, 0, 0, 0, 0 /), (/ 2, 3 /))
real, parameter :: B(2) = (/ 0, 0 /)
real, parameter :: C(3) = matmul(B, A)
! 1
!Error: Different shape for array assignment at (1) on dimension 1 (3 and 2)
!f951: internal compiler error: in gfc_simplify_reshape, at fortran/simplify.c:5104
! This works in some versions of gfortran:
@alanbriolat
alanbriolat / schm.py
Created March 19, 2012 11:40
file schmile
def schm(word):
return 'schm' + word.lstrip("y").lstrip("bcdfghjklmnpqrstvwxz")
if __name__ == '__main__':
import sys
print sys.argv[1], schm(sys.argv[1])
@alanbriolat
alanbriolat / etcX11Xsession.d74gnome-keyring-daemon
Created April 27, 2012 16:41
Enabling gnome-keyring-daemon in Xubuntu (12.04)
# This file is sourced by Xsession(5), not executed.
STARTGKD=
GNOME_KEYRING_DAEMON=/usr/local/bin/start-gnome-keyring-daemon.sh
#if has_option use-gnome-keyring-daemon; then
STARTGKD=yes
#fi
if [ -n "$STARTGKD" ]; then
@alanbriolat
alanbriolat / gist:2519542
Created April 28, 2012 14:39
Remove HDMI audio so pulseaudio doesn't get confused
echo "blacklist snd_hda_intel_hdmi" >> /etc/modprobe.d/blacklist.conf