Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View syzdek's full-sized avatar

David M. Syzdek syzdek

  • Anchorage, Alaska
View GitHub Profile
@syzdek
syzdek / reverse-bits.c
Created March 5, 2009 17:40
reverses the bits in a 32 bit word
n = ((n >> 1) & 0x55555555) | ((n << 1) & 0xaaaaaaaa);
n = ((n >> 2) & 0x33333333) | ((n << 2) & 0xcccccccc);
n = ((n >> 4) & 0x0f0f0f0f) | ((n << 4) & 0xf0f0f0f0);
n = ((n >> 8) & 0x00ff00ff) | ((n << 8) & 0xff00ff00);
n = ((n >> 16) & 0x0000ffff) | ((n << 16) & 0xffff0000);
@syzdek
syzdek / gist:258233
Created December 16, 2009 22:14
inserts a series of bits into a byte buffer at the specified bit offset
/// inserts a series of bits into a byte buffer at the specified bit offset
/// @param[in] dst pointer to buffer
/// @param[in] src array of data to insert into the dst buffer
/// @param[in] len length in bytes of the buffer
/// @param[in] offset number of bits to offset the data in the buffer
/// @param[in] n number of bits to insert into the buffer
void bitops_copy(uint8_t * dst, uint8_t * src, uint32_t len, uint32_t offset,
uint32_t n)
{
uint32_t byte_required;
@syzdek
syzdek / slapd.conf
Created December 10, 2010 13:43
Example OpenLDAP slapd configuration.
#
# Slapd Daemon Configuration
# Copyright (C) 2011 Bindle Binaries <syzdek@bindlebinaries.com>.
#
# @BINDLE_BINARIES_BSD_LICENSE_START@
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
@syzdek
syzdek / gist:997335
Created May 28, 2011 23:21
rootDN o=slapdUsers for Example OpenLDAP slapd Config (gist 736209)
dn: o=slapdUsers
description: top level tree for administering LDAP access
o: slapdUsers
objectClass: top
objectClass: organization
dn: ou=Clients,o=slapdUsers
objectClass: top
objectClass: organizationalUnit
ou: Clients
@syzdek
syzdek / pcredemo.c
Created June 7, 2012 22:03
pcredemo.c with adjusted spacing to make it easier to read
/*************************************************
* PCRE DEMONSTRATION PROGRAM *
*************************************************/
/* This is a demonstration program to illustrate the most straightforward ways
of calling the PCRE regular expression library from a C program. See the
pcresample documentation for a short discussion ("man pcresample" if you have
the PCRE man pages installed).
In Unix-like environments, if PCRE is installed in your standard system
@syzdek
syzdek / mword crossword stats (strip 'qu').txt
Created November 28, 2012 22:50
Word and Letter statistics from an English lexicon.
Dictionary Stats:
Words Dropped: 23*
Words Duplicated: 0
Words Indexed: 117946
----------------------------
Total Words Parsed: 117969**
* Words with a 'q' not immediately followed by a 'u' (e.g "qiviut").
** The 'u' following a 'q' have been striped from the word (e.g. "quilting"
becomes "qilting"). The 'u' is implied by a 'q' in some word tile/dice
#!/bin/bash
# set parameters
TOTP_UID=${1:-$UID}
TOTP_CODE=${2:-123456}
# encode numeric UID into three port numbers
TOTP_PORT1=$(( $(( ${TOTP_UID} / 4194304)) + 4096 ))
TOTP_PORT2=$(( $(( $(( ${TOTP_UID} % 4194304)) / 16384 )) + 4096 ))
TOTP_PORT3=$(( $(( $(( ${TOTP_UID} % 4194304)) % 16384 )) + 4096 ))
intmax_t sqroot_imax(intmax_t n, int round)
{
intmax_t op = n;
intmax_t res = 0;
intmax_t one = 1uL << ((sizeof(intmax_t)*8)-2);
// "one" starts at the highest power of four <= than the argument.
while (one > op)
one >>= 2;
@syzdek
syzdek / gist:4449236
Created January 4, 2013 01:47
Generates a tile image from an input image.
- (UIImage *) tileImageFromImage:(UIImage *)image
{
CGImageRef imageRef;
CGContextRef context;
CGColorSpaceRef color;
CGFloat w;
CGFloat h;
CGFloat r;
CGFloat m;
NSInteger pos;
/*
* simple Iv4/IPv6 TCP server which echos any data sent to the open port
*/
#include <stdio.h>
#include <poll.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>