Skip to content

Instantly share code, notes, and snippets.

@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 / 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,
@vi
vi / 0001-libbpg-Implement-noalpha-option-to-skip-PNG-s-alpha-.patch
Created September 3, 2015 16:56
Patch for libbpg's bpgenc v0.9.5 to add -noalpha option like in cwebp
From fd121ea3730530289422566bdae6e77a45402e34 Mon Sep 17 00:00:00 2001
From: Vitaly _Vi Shukela <vi0oss@gmail.com>
Date: Wed, 26 Aug 2015 02:22:50 +0300
Subject: [PATCH] libbpg: Implement -noalpha option to skip PNG's alpha channel
pngenc command line tool loves PNG.
Sometimes users need to convert the picture to png in order
to feed it to pngenc.
While converting to png, alpha channel may creep in.
This makes bpgenc to fail to work in x265 mode and also produce
@vi
vi / 1_git-http-push-bug.txt
Created November 8, 2010 01:01
The Git I built from source code fails while the git from binary distribution works.
vi@vi-notebook:/tmp/mod$ git config remote.origin.url
http://127.0.0.1/gitmod/
vi@vi-notebook:/tmp/mod$ ~/src/git/git/git push origin master:refs/heads/master
Counting objects: 5, done.
Writing objects: 100% (3/3), 288 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
# it freezes
^C
vi@vi-notebook:/tmp/mod$ /usr/bin/git push origin master:refs/heads/master
Counting objects: 5, done.
@vi
vi / gist:753796
Created December 24, 2010 01:35
Attempt to use --split-submodule
vi@vi-notebook:~/_/gittest$ tar -czf /tmp/gittest.tar.gz .git
vi@vi-notebook:~/_/gittest$ git reset --hard
HEAD is now at 70cd7a6 fix assoc/auth event parsing
vi@vi-notebook:~/_/gittest$ git filter-branch --split-submodule headers
Rewrite a16340b152a6d3df3a3204adcbfb8d4c7670afa6 (1/261)cat: /home/vi/_/gittest/.git-rewrite/t/../map/: Is a directory
Rewrite cf98a6eae1681faa32d0da9fbabfc99707181a61 (6/261)fatal: 90272c0d8b3efd04a5e0666da6d8b8db1be16253 is not a valid 'commit' object
vi@vi-notebook:~/_/gittest$
@vi
vi / git-extract-submodule
Created December 24, 2010 02:31
Script to extract submodules from git repositories. Depends on --split-submodule filter.
#!/bin/bash
# Extract subdirectory into a submodule.
if [ -z "$1" ]; then
echo "Usage: extract-submodule subdirectory"
echo "No trailing slash"
echo "Should be run from the root directory of repository"
echo "Everything should be clean prior to running this script"
echo "You need to manually copy submodule somewhere and update .gitmodules file appropriately"
exit 1;
vi@vi-notebook:~/_$ git clone -b valgrind-failure git://github.com/vi/tcplim.git
Cloning into tcplim...
...
vi@vi-notebook:~/_$ cd tcplim/
vi@vi-notebook:~/_/tcplim$ make
gcc -O2 tcplim.c -o tcplim
vi@vi-notebook:~/_/tcplim$ socat tcp-l:9998,reuseaddr,fork file:/dev/zero&
[1] 11525
vi@vi-notebook:~/_/tcplim$ valgrind ./tcplim 127.0.0.1 9999 127.0.0.1 9998 10000000 10000000 1000000000 1000000000 50 2> log&
[2] 11550
@vi
vi / gimp
Created February 18, 2011 00:17
memory allocation errors in gtk programs
vi@vi-notebook:~/_$ gimp-2.7 2.jpg
This is a development version of GIMP. Debug messages may appear here.
GLib-ERROR **: /build/buildd-glib2.0_2.24.2-1-i386-AScyie/glib2.0-2.24.2/glib/gmem.c:137: failed to allocate 4096 bytes
aborting...
gimp-2.7: terminated: Aborted
(script-fu:5118): LibGimpBase-WARNING **: script-fu: gimp_wire_read(): error