This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
// | |
// Create entries for a boolean lookup table. | |
// | |
// Example output from list[], below: | |
// 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
// 0,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1, | |
// 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <time.h> | |
#include <stdint.h> | |
#include <sys/types.h> | |
#include <stdio.h> | |
#include <ctype.h> | |
/* | |
Character-by-character comparisons for equality and lowercasing. | |
Custom functions vs tolower. | |
Spoiler: lookup table is the fastest. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int i; | |
float tStart, tDiff; | |
uint32_t runs = 1000; | |
tStart = (float)clock()/CLOCKS_PER_SEC; | |
for ( i=0; i<runs; ++i ) { | |
func(); | |
} | |
tDiff = (float)clock()/CLOCKS_PER_SEC - tStart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://github.com/bitly/dablooms/blob/master/src/test_dablooms.c | |
static void chomp_line(char *word) | |
{ | |
char *p; | |
if ((p = strchr(word, '\r'))) { | |
*p = '\0'; | |
} | |
if ((p = strchr(word, '\n'))) { | |
*p = '\0'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned short timestamp = <some value>; // Bits: DDDDDHHHHHMMMMMM | |
int day = (timestamp >> 11) & 0x1F; | |
int hour = (timestamp >> 6) & 0x1F; | |
int min = (timestamp) & 0x3F; | |
unsigned short dup_timestamp = (short)((day << 11) | (hour << 6) | min); | |
// Alternative using macros |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/mman.h> | |
#include <sys/stat.h> | |
#include <errno.h> | |
int main(int argc, char *argv[]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> //lseek, write, close | |
#include <stdlib.h> //exit | |
#include <fcntl.h> //open | |
#include <sys/mman.h> | |
#define Mapmalloc(number, type, filename, fd) load_mmap(filename, &(fd), (number)*sizeof(type), 'y') | |
#define Mapload(number, type, filename, fd) load_mmap(filename, &(fd), (number)*sizeof(type), 'n') | |
#define Mapfree(number, type, fd, pointer) releasemmap(pointer, (number)*sizeof(type), fd) | |
#define Stopifnot(assertion, ...) if (!(assertion)){printf(__VA_ARGS__); exit(1);} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* $Id: simple-tcp-proxy.c,v 1.6 2002/11/27 00:40:31 wessels Exp $ | |
*/ | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
#include <netdb.h> | |
#include <string.h> | |
#include <signal.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright (c) 2001 Matej Pfajfar. | |
* Copyright (c) 2001-2004, Roger Dingledine. | |
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. | |
* Copyright (c) 2007-2013, The Tor Project, Inc. */ | |
/* See LICENSE for licensing information */ | |
/** | |
* \file connection.c | |
* \brief General high-level functions to handle reading and writing | |
* on connections. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $Id: simple-proxy.c,v 1.4 2005/02/25 04:23:24 dean Exp $ | |
// | |
// simple-proxy.c: simple tcp proxy for async bi-directional data transfer | |
// | |
// usage: simple-proxy host port | |
// | |
// this will open a socket to host:port and copy data from stdin to the socket, | |
// and from the socket to stdout. errors may appear on stderr. | |
// |