Skip to content

Instantly share code, notes, and snippets.

@vmxdev
vmxdev / wcg.cpp
Created May 26, 2015 18:46
wildcard function - search for longest common subsequence and make string with wildcards, e.g. wildcard("hello", "elo") returns "*e*lo"
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
string
wildcard(const string& a, const string& b)
{
@vmxdev
vmxdev / shent.c
Created June 6, 2015 10:37
calculate entropy of file
/*
Shannon entropy calculation
$ cc -Wall shent.c -o shent -lm
$ ./shent shent.c
*/
#include <stdio.h>
#include <stdint.h>
#include <math.h>
int
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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