Skip to content

Instantly share code, notes, and snippets.

@vi
vi / genetic_regex.pl
Created November 24, 2014 11:42
Generate regular expressions using genetic algorithm.
#!/usr/bin/perl -w
use strict;
$|=1;
if ($#ARGV != 3) {
print STDERR "Usage: genetic_regex.pl file_with_passing_lines file_with_failing_lines {file_with_hints|''} {file_with_bans|''} \n";
print STDERR "Created by Vitaly '_Vi' Shukela, in 2014. License is LGPLv2+.\n";
exit 1;
R! 16.0403 l=4 PPCG
R! 15.0236 l=2 ^P
R! 14.0646 l=6 ^[P^]P
R! 13.0919 l=9 [^?][PG]$
R! 12.1617 l=16 (?<!\\..)(?!]).$
R! 8.19108 l=19 ^[\w^]*$|!|]P|G]\$$
R! 8.17125 l=17 !|[^?]P(CG|G..)?$
R! 5.25195 l=25 !|((G.|P|\.)\$|[^?]P|CG)$
R! 4.2402 l=24 ^[(!P]|G..$|]..\||[^?]P$
R! 3.29278 l=29 ^.{3,23}[.-~]..\$$|[^P?][PG]$
@vi
vi / directfbtext.c
Created November 26, 2014 23:23
DirectFB simple text outputter
/*
directfbtext, implemented by Vitaly "_Vi" Shukela in 2014.
Based on:
DirectFB Tutorials
(c) Copyright 2000-2002 convergence integrated media GmbH.
(c) Copyright 2002 convergence GmbH.
All rights reserved.
@vi
vi / copy_with_links
Created December 18, 2014 16:20
Copy a file with accompanying symlinks
#include <stdio.h>
void hash(const unsigned char* buf, size_t len, unsigned long long *hash1, unsigned long long *hash2)
{
unsigned long long &h=*hash1;
unsigned long long &j=*hash2;
size_t l = len;
const unsigned char* b = buf;
h=0xC0CC3051F486B191;
@vi
vi / bpg93_remove_alpha.pl
Last active October 21, 2015 10:17
Alpha channel remover from old BPG pictures
#!/usr/bin/perl
# Removes alpha channel from BPG v0.9.3- image, so it can be decoded with libbpg v0.9.4+.
# Implemented by Vitaly "_Vi" Shukela in 2015
# License: MIT
read STDIN,$_,4;
my $magic=unpack("N", $_);
printf STDERR "magic: %08X\n", $magic;
print STDOUT pack("N", $magic);
@vi
vi / cgroup_memory_pressure_monitor.c
Created July 19, 2015 22:51
Simple command-line tool use cgroup's memory.pressure_level
#include <sys/eventfd.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
// Implemented by Vitaly "_Vi" Shukela in 2015, License=MIT.
@vi
vi / vmtouchpoll
Last active April 9, 2019 06:04
Keep files locked in memory by periodically restarting vmtouch
#!/bin/bash
# vmtouchpoll: Keep some files locked in memory (including new files, dropping deleted files)
# Usage: vmtouchpoll '/path/to/some/files/*.idx'
# Works by periodically restarting vmtouch with a new set of files
# Implemented by Vitaly "_Vi" Shukela in 2015, License=MIT
@vi
vi / selectfuzz.c
Created July 22, 2015 22:25
Intentionally cause select/poll spurious activations for testing, LD_PRELOAD-based
#define _GNU_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <dlfcn.h>
#include <sys/time.h>
#include <sys/select.h>
#include <time.h>
#include <sys/stat.h>
@vi
vi / inhibitseekfail.c
Created July 22, 2015 22:28
Inhibit seek failures to force programs to continue when writing to pipes/sockets, LD_PRELOAD-based
#define _GNU_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <dlfcn.h>
#include <errno.h>
static int (*orig_llseek)(
unsigned int fd, unsigned long offset_high,