Skip to content

Instantly share code, notes, and snippets.

View Sebbyastian's full-sized avatar

Sebastian Ramadan Sebbyastian

View GitHub Profile
#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <Windows.h>
#define _tmain main
#define TCHAR char
@Sebbyastian
Sebbyastian / fshuffle.c
Last active August 10, 2016 06:32
fshuffle.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int fswap(FILE *file, off64_t x, off64_t y, size_t size) {
unsigned char i[size], o[size];
return fseeko64(file, x * size, SEEK_SET) || fread(i, size, 1, file) != 1 ||
fseeko64(file, y * size, SEEK_SET) || fread(o, size, 1, file) != 1 ||
fseeko64(file, y * size, SEEK_SET) || fwrite(i, size, 1, file) != 1 ||
@Sebbyastian
Sebbyastian / living_being.c
Created March 28, 2016 23:42
Opaque type example
#include "living_being.h"
struct living_being {
int meaning;
};
#include <stdlib.h>
void give_birth(living_being **toilet) {
*toilet = malloc(sizeof **toilet);
@Sebbyastian
Sebbyastian / get_network_params.c
Last active January 28, 2016 20:40
get_network_params.c
/* gcc -std=c11 get_network_params.c -lws2_32 -liphlpapi -o get_network_params.exe */
#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
int main(void) {
FIXED_INFO *fixed_info = (FIXED_INFO[]) { 0 };
ULONG fixed_info_size = 0;
GetNetworkParams(fixed_info, &fixed_info_size);
@Sebbyastian
Sebbyastian / finsert.c
Last active November 14, 2015 14:01
finsert, a function to insert data into the middle of a file...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int finsert(FILE *file, fpos_t position, void *object, size_t size) {
unsigned char i[size], o[size];
memcpy(o, object, size);
if (fsetpos(file, &position)) {
return -1;
@Sebbyastian
Sebbyastian / automatic_test.c
Last active August 29, 2015 14:18
Generic linked lists
// To compile: cc -c -std=c99 linked_list.c
// cc -std=c99 automatic_test.c linked_list.o -o automatic_test
#include <stdio.h>
#include <string.h>
#include "linked_list.h"
struct apple_linked_list {
struct automatic_linked_list_node linked_list;
/* (c) 2015 Sebastian Ramadan *
* May you perish in court if this makes its way into turnitin software, *
* ... for it is my intellectual property ;) *
*/
#include <stdint.h>
#include <stdio.h>
int main(int argc, char **argv) {
uintmax_t y;
@Sebbyastian
Sebbyastian / some_challenge.c
Created February 13, 2015 10:55
some_challenge.c
int main(void) {
unsigned char *value = NULL;
size_t size = 0;
for (;;) {
int c = getchar();
if (c == EOF) {
break;
}
@Sebbyastian
Sebbyastian / stupid_shit.c
Created December 22, 2014 15:52
Benchmark for @wesen
#include <assert.h>
#include <stdio.h>
int main(void) {
unsigned int criteria[2] = { 0 };
#ifndef UNBUFFERED
int n = setvbuf(stdin, NULL, _IOFBF, 65536);
assert(n == 0);
@Sebbyastian
Sebbyastian / BR_password_challenge_scanf.c
Created December 15, 2014 21:58
BR password challenge (using scanf)
int main(void) {
int lower_length = 0,
upper_length = 0,
digit_length = 0,
length = 0;
puts("Please enter a password and I'll judge its security...");
# define LOWER_FMT "%*[qwertyuiopasdfghjklzxcvbnm]%n"