Skip to content

Instantly share code, notes, and snippets.

View AndreLouisCaron's full-sized avatar

André Caron AndreLouisCaron

View GitHub Profile
#include <Windows.h>
namespace w32 { namespace tp {
class Hints;
class Queue;
// Dispatches calls to a function with a painful signature (see PTP_TIMER).
class Timer
{
@AndreLouisCaron
AndreLouisCaron / gist:1786056
Created February 10, 2012 03:15
partial_sort() for std::list<int> based on suggestion by Scott Meyers in Effective STL, item 31.
// partial_sort() implementation for std::list<int> based on suggestion
// by Scott Meyers in Effective STL, item 31.
//
// See <http://stackoverflow.com/questions/9220750>.
#include <cstddef>
#include <list>
#include <iostream>
#include <set>
@AndreLouisCaron
AndreLouisCaron / factorial.bat
Created February 14, 2012 21:56
Recursive factorial function using Windows Batch Files
@echo off
call:factorial "%~1"
echo result: %ErrorLevel%
exit /b 0
:factorial
if "%~1" LEQ "2" (
set ErrorLevel=%~1
exit /b 0
@AndreLouisCaron
AndreLouisCaron / gist:1841061
Created February 16, 2012 02:23
Redirect std::cerr to log file.
namespace {
// redirect outputs to another output stream.
class redirect_outputs
{
std::ostream& myStream;
std::streambuf *const myBuffer;
public:
redirect_outputs ( std::ostream& lhs, std::ostream& rhs=std::cout )
: myStream(rhs), myBuffer(myStream.rdbuf())
@AndreLouisCaron
AndreLouisCaron / gist:1895114
Created February 23, 2012 21:22
Proposed HTTP parser interface for unbuffered body.
// Parses headers just like it did before, but allows custom handling
// for body contents. Just inherit and implement 'accept_body()' to
// suit your needs.
class Request
{
// Same as before, minus the 'myBody' string.
// ...
protected:
// Implement in derived classes for custom body handling.
@AndreLouisCaron
AndreLouisCaron / gist:1902779
Created February 24, 2012 18:27
Bypass httpxx request body for proxying.
class RequestHeaders :
public Request
{
protected:
virtual void accept_body ( const char *, std::size_t ) {}
};
class ResponseHeaders :
public Response
{
@AndreLouisCaron
AndreLouisCaron / git-archive-all.bat
Created April 18, 2012 15:44
git-archive-all for Windows
@echo off
git-ls-all-submodules | zip -@ ../source-code.zip
std::vector<int> multiply (std::vector<int> input, int value)
{
for (auto& i : input )
i *= value;
return input;
}
int main (int, char**)
{
std::vector<int> foo;
@AndreLouisCaron
AndreLouisCaron / which.bat
Created September 12, 2012 20:02
Unix "which" utility for Windows.
@echo off
rem -- Unix "which" utility.
rem --
rem -- Usage: which <program>
rem -- Shows absolute path to "program", if it exists.
rem --
rem -- The utility can find any program that satisfies all of these conditions:
rem -- 1) the program's extension is registered in %PathExt%;
rem -- 2) the program is found under a folder in %Path%.
rem --
@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