Skip to content

Instantly share code, notes, and snippets.

@vmxdev
vmxdev / ip-range-to-nets.c
Created October 3, 2023 11:45
Split a range of IP addresses into subnets
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <errno.h>
#include <string.h>
static void
print_cidr(uint32_t addr, int mask)
{
@vmxdev
vmxdev / hello.asm
Created July 11, 2022 10:57
8086 16-bit helloworld in GNU assembly
# as --32 hello.s -o hello.o
# ld -melf_i386 -Ttext=0x100 --oformat=binary hello.o -o hello.com
.code16
.globl _start
.section .text
_start:
# print question
movw $ask, %dx
@vmxdev
vmxdev / hello.asm
Last active June 23, 2022 15:49
8086 16-bit helloworld.com
; nasm hello.asm -fbin -o hello.com
; to run in DosBox: dosbox hello.com
org 100h
section .text
start:
mov ax, 13h
int 10h
@vmxdev
vmxdev / fact.c
Last active February 3, 2021 05:48
Calculate factorials using gmp
/*
* $ cc -O3 -Wall -pedantic -Wextra fact.c -lgmp
*/
#include <stdio.h>
#include <gmp.h>
static void
factorial(long n, mpz_t r)
{
@vmxdev
vmxdev / fizzbuzz.s
Last active October 14, 2020 10:24
fizzbuzz in GNU assembly
/*
* To compile and link:
*
* $ gcc -Wall -pedantic -Wextra fizzbuzz.s -no-pie -o fizzbuzz
*/
.data
/* Strings to print */
fizz: .asciz "fizz\n"
@vmxdev
vmxdev / qtst.c
Last active October 24, 2019 15:29
/*
* $ cc -O3 -Wall -pedantic -Wextra qtst.c -o qtst
* $ time ./qtst
real 0m39,543s
user 0m37,288s
sys 0m0,732s
*/
#include <stdio.h>
@vmxdev
vmxdev / atest.cc
Last active September 11, 2019 13:18
Atomics vs ordinary variables
/*
* Compile:
* $ gcc -O3 -g -Wall -pedantic -Wextra atest.cc -o atest -lstdc++ -pthread
*/
#include <atomic>
#include <cinttypes>
#include <iostream>
#include <thread>
#include <chrono>
#include <cstdlib>
@vmxdev
vmxdev / instr_trace.c
Created June 25, 2017 12:23
Trace function calls using -finstrument-functions
#define _GNU_SOURCE
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <errno.h>
/* ========================================================================= */
static int indent_level = 0;
@vmxdev
vmxdev / hmap.c
Created November 19, 2016 06:46
t1ha hash function map
#include <stdio.h>
#include <stdlib.h>
#include <png.h>
#include <stdint.h>
#include "t1ha.h"
#define STRLEN 10
#define NITER 1000000
/*#define SQRSIDE 842*/
@vmxdev
vmxdev / qu.sh
Created July 18, 2015 12:32
translate to qulinxao
#!/bin/bash
USAGE="Usage:
$0 \"так говорил кулинксао\"
"
if [ "$#" == "0" ]; then
echo "$USAGE"
exit 1
fi