Skip to content

Instantly share code, notes, and snippets.

View jandk's full-sized avatar

Jan De Kock jandk

View GitHub Profile
public sealed class UnionFind<T>
{
private sealed class Link<TLink>
{
public TLink parent;
public int rank = 0;
public Link(TLink parent)
{
this.parent = parent;
@jandk
jandk / Raster.cs
Created December 16, 2013 10:06
Simple image processing in a generic way (just an idea)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace Util
{
public struct Position
{
@jandk
jandk / ConvertBytes.cs
Last active December 31, 2015 00:39
Remove unneeded brackets and casts
using System;
class ConvertBytes
{
public static void Convert08to08(byte[] src, int srcOff, short[] dst, int dstOff, int dstLen)
{
ValidateRange(src, srcOff, dst, dstOff, dstLen, 8);
int n = dstLen / 4;
for (int i = 0; i < n; i++)
@jandk
jandk / IconManager.java
Created December 5, 2013 15:22
IconManager
package com.cmosis.iconlib;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
static T Parse<T>(string value)
where T : struct
{
var type = typeof(T);
if (!type.IsEnum)
throw new ArgumentException("T is not an enum");
var enumValue = Enum.Parse(type, value);
return (T)enumValue;
}
static class LinearRegression
{
double[] independent;
double[] independentDiff;
double independentDiffSquaredSum;
double independentMean;
double[] calculate(double[] values)
{
if (values.length != independent.length)
@jandk
jandk / md5_sse2.c
Created April 10, 2013 08:27
Calculate 4 MD5 hashes at the same time. ~2.5x speedup.
#include <emmintrin.h>
typedef unsigned char uint8;
typedef unsigned int uint32;
typedef unsigned long long uint64;
typedef struct MD5Data
{
__m128i h0, h1, h2, h3;
} MD5Data;
@jandk
jandk / PermuteEnumerator`1.cs
Created April 10, 2013 08:05
Permutes a sequence of a specific type, and lets you enumerate through them
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class PermuteEnumerator<T>
: IEnumerator<IEnumerable<T>>
where T : IComparable
{
@jandk
jandk / jpeg.cs
Created October 14, 2012 21:09
(Almost) JPEG Decoder in C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
namespace Jpeg
{
@jandk
jandk / problem001.c
Created June 18, 2012 22:02
Project Euler #1
#include <stdio.h>
int main(int argc, char** argv) {
int i, sum = 0;
for(i = 0; i < 1000; i++)
if(i%3 == 0 || i%5 == 0)
sum += i;
printf("%d\n", sum);
}