Skip to content

Instantly share code, notes, and snippets.

@jzwinck
jzwinck / gist:5787359
Created June 15, 2013 08:12
A port of the prime number example program of Offbrand, here: http://theck01.github.io/offbrand_lib/index.html Note that my first version here is incomplete, as it doesn't properly create new candidate numbers at the beginning of each iteration, so it will just run forever. Patches welcome.
#include <stdio.h>
#include <stdint.h>
#include <glib.h>
#include <gmp.h>
int main(){
uint64_t i, maybe_prime;
mpz_t candidate, next, remainder;
GArray *primes;
@jzwinck
jzwinck / purge-directory.c
Created June 2, 2013 03:29
Inspired by http://linuxnote.net/jianingy/en/linux/a-fast-way-to-remove-huge-number-of-files.html this program removes all regular files within a directory, using multiple processes to work faster. Timings from my system are in a comment below; feel free to leave your own. Easily create lots of empty files with "seq 10000 | xargs touch".
#include <dirent.h>
#include <stdio.h>
#include <unistd.h>
/* filter for regular files only */
static int dirent_select(const struct dirent* ent)
{
return ent->d_type == DT_REG;
}
@jzwinck
jzwinck / npm-install-order-test.sh
Created February 2, 2013 02:05
Test case for npm install of a module, then something that depends on it, then remove the first and try to fix up the second. It doesn't work well as of this writing (node.js 0.8.18).
#!/bin/bash -eux
cat <<EOF >package.json
{
"name": "npm-install-order-test",
"private": true,
"version": "0.0.0",
"dependencies" : {
"express" : "*"
}