Skip to content

Instantly share code, notes, and snippets.

View jandk's full-sized avatar

Jan De Kock jandk

View GitHub Profile
@jandk
jandk / fix-raid5.c
Created January 30, 2012 12:21
Manual repair of RAID5 (Version which actually ran)
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#define STRIPESIZE (64 * 1024)
#define BUFSIZE (2 * STRIPESIZE)
#define MIB16 (16 * 1024 * 1024)
@jandk
jandk / xkcd-sql.php
Created January 31, 2012 10:02
Create an SQL from XKCD JSON feed
<?php
header('Content-type: text/plain; charset=utf-8');
$sql = <<<SQL
DROP TABLE IF EXISTS `xkcd`;
CREATE TABLE `xkcd` (
`id` int(11) NOT NULL DEFAULT '0',
`date` date DEFAULT NULL,
`image` text CHARACTER SET utf8,
`title` text CHARACTER SET utf8,
@jandk
jandk / rpn.c
Created January 31, 2012 10:18
Simple RPN calculator in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
typedef struct stack
{
int data;
struct stack *next;
} stack;
@jandk
jandk / TimSort.cs
Created June 10, 2012 12:03
TimSort port of java version
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Sorting
{
/// <summary>
/// A stable, adaptive, iterative mergesort that requires far fewer than
/// n lg(n) comparisons when running on partially sorted arrays, while
@jandk
jandk / cleanup.sh
Last active December 21, 2018 14:30
Clean up some gentoo files
#!/bin/sh
echo "Space free"
df -h | head -n 2
echo "Removing foreign man pages"
find /usr/share/man -type d -not -name man*
echo "Removing gtk docs"
rm -rf /usr/share/gtk-doc
@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);
}
@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 / 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 / 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;
static class LinearRegression
{
double[] independent;
double[] independentDiff;
double independentDiffSquaredSum;
double independentMean;
double[] calculate(double[] values)
{
if (values.length != independent.length)