Skip to content

Instantly share code, notes, and snippets.

@lnicola
lnicola / spiral.cpp
Created June 20, 2014 16:14
walk over a square matrix in a spiral shape
#include <stdio.h>
#include <tchar.h>
int main()
{
int a[100][100];
FILE *f = fopen("spiral.in", "rt");
int n;
fscanf(f, "%d", &n);
@lnicola
lnicola / units-of-measure.cpp
Created June 20, 2014 16:15
C++ TMP units of measure POC
#include "stdafx.h"
class m { };
class kg { };
class s { };
template<typename T, int pm, int pkg, int ps>
class unit
{
public:
@lnicola
lnicola / FunctionDepsGraph.cs
Created June 20, 2014 16:17
some code to graph function dependencies, using Mono.Cecil and GLEE
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections.Generic;
using System.Collections.Specialized;
using Microsoft.Glee.GraphViewerGdi;
using Microsoft.Glee.Drawing;
using Mono.Cecil;
using Mono.Cecil.Cil;
@lnicola
lnicola / CRT.cpp
Created June 24, 2014 09:04
Some Chinese Remainder Theorem code
#include <iostream>
#include <string>
#include <vector>
int gcd(int u, int v) {
int t;
while (v) {
t = u;
u = v;
v = t % v;
@lnicola
lnicola / EG.cs
Created June 24, 2014 09:06
An expression generator
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace EG
{
@lnicola
lnicola / RegexGen.cpp
Created June 24, 2014 09:42
A data generator for regular expressions
#include <functional>
#include <iostream>
#include <string>
#include <vector>
const int repetition_limit = 10;
template<typename F>
void do_times(size_t count, const F &f)
{
@lnicola
lnicola / correlation.nb
Created June 24, 2014 10:05
Mathematica cross-correlation
(* Content-type: application/vnd.wolfram.mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 9.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
@lnicola
lnicola / latency.nb
Created June 24, 2014 10:05
Mathematica latency graph
(* Content-type: application/vnd.wolfram.mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 9.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
@lnicola
lnicola / IsAxial.cpp
Last active August 29, 2015 14:02
Slow SSE code for vector-on-axis test
#include <stdio.h>
#include <tchar.h>
#include <emmintrin.h>
#include <xmmintrin.h>
#include <smmintrin.h>
#include <iostream>
#include <chrono>
__declspec(noinline)
bool is_axial(__m128 vec)
@lnicola
lnicola / garbage.cpp
Created June 24, 2014 10:36
LeaF garbage can
#define fatal(msg, ...) do \
{ \
char message[512]; \
wsprintf(message, msg, __VA_ARGS__); \
MessageBox(NULL, message, "Fatal error", MB_OK); \
DebugBreak(); \
ExitProcess(-1); \
} while(false)
#define assert(cond) do \
{ \