Skip to content

Instantly share code, notes, and snippets.

Attractive Chaos attractivechaos

Block or report user

Report or block attractivechaos

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ksort.h
/* The MIT License
Copyright (c) 2008, 2011 Attractive Chaos <attractor@live.co.uk>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
@attractivechaos
attractivechaos / clist.h
Last active Jan 19, 2020
Demonstration of a circular doubly linked list
View clist.h
#pragma once // or use the #ifndef guard
#include <stddef.h> // for offsetof()
typedef struct cl_head_s {
struct cl_head_s *prev, *next;
} cl_head_t;
static inline void cl_insert_after(cl_head_t *q, cl_head_t *p)
{ // insert _p_ after _q_; _q_ is in the list
p->prev = q, p->next = q->next, q->next = p, p->next->prev = p;
@attractivechaos
attractivechaos / dlist.h
Created Jan 19, 2020
Demonstrating an intrusive doubly linked list
View dlist.h
#pragma once // or use the #ifndef guard
#include <stddef.h> // for offsetof()
typedef struct dl_head_s { // this struct can't be hidden
struct dl_head_s *p[2]; // p[0] points the previous record; p[1] points to the next
} dl_head_t;
// Given a pointer to a struct member, get the pointer to the struct
#define dl_container_of(ptr, type, member) ((type*)((char*)(ptr) - offsetof(type, member)))
@attractivechaos
attractivechaos / getopt.c
Created Feb 18, 2018
Implementation of getopt() and getopt_long() from musl
View getopt.c
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "getopt.h"
char *optarg;
int optind=1, opterr=1, optopt, __optpos, optreset=0;
#define optpos __optpos
View rc-test.py
#!/usr/bin/env python
import random
import timeit
import string
import sys
import seqpy
global complement
complement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A'}
View rsort.c
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#define rstype_t uint64_t // type of the array
#define rskey(x) (x) // specify how to get the integer from rstype_t
#define RS_MIN_SIZE 64 // for an array smaller than this, use insertion sort
typedef struct {
View for-test.c
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#if HAVE_CILK
#include <cilk/cilk.h>
#include <cilk/cilk_api.h>
#endif
typedef struct {
int max_iter, w, h;
@attractivechaos
attractivechaos / get_votes.pl
Created Mar 24, 2012
Plot HackerNews polls on favorite and disliked programming languages
View get_votes.pl
#!/usr/bin/env perl
# This script collects voting from HackerNews and outputs a plot votes.eps
# You need to have gnuplot installed for plotting.
use strict;
use warnings;
use IO::Socket::INET;
sub http_get {
@attractivechaos
attractivechaos / compile-d.mak
Created Feb 16, 2012
Compile the D compiler
View compile-d.mak
MODEL=64
PROTO=git
all:bin/dmd.conf bin/rdmd
@echo "Now add the following to .bashrc: export PATH=\"`pwd`/bin:"'$$PATH"'
# Compile the D compiler
dmd/src/posix.mak:
git clone $(PROTO)://github.com/D-Programming-Language/dmd.git
You can’t perform that action at this time.