Skip to content

Instantly share code, notes, and snippets.

View AndreLouisCaron's full-sized avatar

André Caron AndreLouisCaron

View GitHub Profile
@AndreLouisCaron
AndreLouisCaron / amend alias
Created May 19, 2015 20:12
Alias for "git commit --amend -C HEAD"
git config --global alias.amend "commit --amend -C HEAD"
import heapq
def merge(*queues):
"""Merge N sorted sequences."""
queues = map(iter, queues)
# Build a heap containing the next item in each queue.
ready = []
for queue in queues:
heapq.heappush(ready, (next(queue), queue))
# Process until all items are consumed.
#include <cstdlib>
#include <iostream>
#include <map>
#include <memory>
#include <http.hpp>
#include <zmq.hpp>
// Peer identity, for use as a key type in `std::map`.
@AndreLouisCaron
AndreLouisCaron / http-header-ext.py
Last active December 31, 2015 00:09
Parse HTTP header extensions in Python
import re
def parse_extension(x):
"""Extract the key and value (without quotes)."""
m = re.match(r'\s*(\S+)\s*=\s*(?:"([^"]+)"|(\S+))', x)
if not m:
pass
return m.group(1), m.group(2) or m.group(3)
def parse_header(h):
@AndreLouisCaron
AndreLouisCaron / win-swap.el
Created August 7, 2013 17:00
Shows how to swap left and right buffers in Emacs.
(require 'buffer-move)
(defun win-swap ()
"Swap windows using `buffer-move`."
(interactive)
(if (null (windmove-find-other-window 'right))
(buf-move-left)
(buf-move-right)))
@AndreLouisCaron
AndreLouisCaron / create-tags.el
Created July 12, 2013 12:26
Create tags using ExuberantCTags, with convenient auto-lookup of ".ctags" file!
(defun create-tags (dir-name)
"""Create tags file (index code using ExuberantCTags).
Prompts for 1 input:
- root folder for recursive code indexing, defaults to first instance of
`.ctags` file when recursively walking back from the directory
containing the current buffer's file until the root is reached, or
the directory containing the current buffer's file if no match is
found.
"""
@AndreLouisCaron
AndreLouisCaron / grep-helpers.el
Last active December 19, 2015 14:09
Helpers for using recursive grep from Emacs, with context induced from current buffer.
(defun recursive-grep (args file-pattern search-root)
"""Useful recursive-find function based on grep.
Prompts for 3 inputs:
- grep arguments, defaults to the current selection or
the word at current position in buffer or \"-i \";
- file pattern, defaults to current buffer's file extension;
- search root, defaults to folder containnig the current buffer's file.
Use `find-grep-match` (C-x C-n) to goto result location."""
@AndreLouisCaron
AndreLouisCaron / build-pcrexx.sh
Created October 10, 2012 00:26
Instructions for building PCREXX.
git clone git://github.com/AndreLouisCaron/pcrexx.git
cd pcrexx
git submodule init
git submodule update
mkdir work
cd work
cmake ..
cmake ..
make
@AndreLouisCaron
AndreLouisCaron / 412-response.py
Created October 1, 2012 11:23
Cornice/Pyramid application with 412 response.
# -*- coding: utf-8 -*-
from pyramid.config import Configurator
from pyramid.httpexceptions import HTTPPreconditionFailed
from cornice.resource import resource, view
from webtest import TestApp
@resource(path='/hello')
class Hello(object):
def __init__(self, request):
@AndreLouisCaron
AndreLouisCaron / 201-response.py
Created October 1, 2012 11:22
Cornice/Pyramid application with 201 response.
# -*- coding: utf-8 -*-
from pyramid.config import Configurator
from cornice.resource import resource, view
from webtest import TestApp
@resource(path='/hello')
class Hello(object):
def __init__(self, request):
self.request = request