Skip to content

Instantly share code, notes, and snippets.

@lnicola
lnicola / Markov.cs
Created June 20, 2014 16:04
simple text generator based on Markov chains
using System;
using System.Collections.Generic;
using System.Linq;
static class Program
{
static void Main(string[] args)
{
var input = "foo bar baz foo bar qux".Split();
@lnicola
lnicola / memalloc.c
Created June 20, 2014 16:05
simulator for simple memory allocation algorithms
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define TotalMemoryAmount 5000 ##UL
#define MemRequestMin 40 ##UL
#define MemRequestMax 1000 ##UL
#define MemRequestSlice 20 ##UL
#define MemThreshold 1 ##UL
#define TotalTime 1000000 ##UL
@lnicola
lnicola / tuple.cpp
Created June 20, 2014 16:06
std::tuple-like class
#include <cstdio>
#include <utility>
template<typename...>
class tuple { };
template<typename T, typename... U>
class tuple<T, U...> : tuple<U...>
{
public:
@lnicola
lnicola / trace.cpp
Last active August 29, 2015 14:02
a class for tracing C++ constructors and assignment operators
struct trace
{
trace()
{
std::cout << "trace()" << std::endl;
}
trace(const trace &)
{
std::cout << "trace(const trace &)" << std::endl;
@lnicola
lnicola / peano.cpp
Created June 20, 2014 16:07
Peano numerals with C++ templates
#include "stdafx.h"
class z { };
template<typename>
class s { };
template<typename, typename>
class add { };
@lnicola
lnicola / ftp-repair.c
Created June 20, 2014 16:08
small tool to recover some files clobbered by ASCII mode conversions
#include <stdio.h>
int main(int argc, char **argv)
{
FILE *fi, *fo;
char c1, c2;
if (argc != 3)
{
printf("Usage: %s <in> <out>\n", argv[0]);
@lnicola
lnicola / RtfParser.cs
Created June 20, 2014 16:09
some code for parsing RTF files
private static string RtfToHtml(string s)
{
s = Regex.Replace(s, @"^\{\\rtf1?" +
@"\\ansi" +
@"(?:\\ansicpg)?" +
@"(?:\\lang\d+)?" +
@"(?:\\noproof\d+)?" +
@"(?:\\uc\d )?", "");
var header =
@lnicola
lnicola / torture.cpp
Created June 20, 2014 16:09
small sample of a hard to parse C++ file
#define PASTE(x,y) x##y
#define COLON :
// this class is: evil
class H;
typedef class H HH;
/*
class NotHere {};
*/
namespace
@lnicola
lnicola / turing-machine.cpp
Created June 20, 2014 16:10
C++ TMP Turing machine
#include "stdafx.h"
using namespace std;
enum class Direction
{
L,
R
};
@lnicola
lnicola / nobackspace.c
Created June 20, 2014 16:12
Windows keyboard filter driver that makes the backspace stop working
/*--
Copyright (c) Microsoft Corporation. All rights reserved.
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
PURPOSE.