Skip to content

Instantly share code, notes, and snippets.

@vi
vi / 0001-Strace-based-speed-limiter.patch
Created November 29, 2011 16:33
Simple process IO read/write rate limiter based on strace
From 7959a97980894e1a47361e566d234a5f341dd05d Mon Sep 17 00:00:00 2001
From: Vitaly _Vi Shukela <vi0oss@gmail.com>
Date: Tue, 29 Nov 2011 19:29:50 +0300
Subject: [PATCH] Strace-based speed limiter
Apply to strace-4.6
Set env SPEEDLIMIT_READ=1000 and slow down other process with strace
Example: SPEEDLIMIT_READ=$((200*1024)) ./strace -o /dev/null -p `pidof wget`
---
@vi
vi / cputime.patch
Created February 16, 2012 18:45
A patch for [Yappi](http://code.google.com/p/yappi/) to measure CPU time instead of wall time
From vi0oss@gmail.com Thu Feb 16 21:43:27 2012
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [PATCH] Switch between measuring wall-clock time and CPU time with
YAPPI_CPUTIME environment variable
X-Mercurial-Node: f73ffd1c1bed66f0a95b39460788cc411ddc1003
Message-Id: <f73ffd1c1bed66f0a95b.1329417806@localhost>
User-Agent: Mercurial-patchbomb/1.6.4
Date: Thu, 16 Feb 2012 21:43:26 +0300
@vi
vi / gist:1987652
Created March 6, 2012 17:34
Bug with git v1.8
v@l:20:30:10:/tmp/gittest$ git init
Initialized empty Git repository in /tmp/gittest/.git/
v@l:20:30:12:/tmp/gittest$ echo q > q && git add q && git commit -m q
[master (root-commit) 9d49ad5] q
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 q
v@l:20:30:16:/tmp/gittest$ echo q2 > q && git add q && git commit -m q2
[master 27cc7c1] q2
1 files changed, 1 insertions(+), 1 deletions(-)
v@l:20:30:23:/tmp/gittest$ git rebase -i HEAD^
@vi
vi / gist:1997196
Created March 7, 2012 23:28
"git diff --no-index" beheviour on special files
$ diff -ur <(printf 'a\nb\nc\n') <(printf 'a\nd\nc\n')
--- /dev/fd/63 2012-03-08 02:27:23.088325870 +0300
+++ /dev/fd/62 2012-03-08 02:27:23.088325870 +0300
@@ -1,3 +1,3 @@
a
-b
+d
c
$ git diff --no-index <(printf 'a\nb\nc\n') <(printf 'a\nd\nc\n')
diff --git a/dev/fd/63 b/dev/fd/62
@vi
vi / mkv2udp.c
Created June 22, 2012 02:16
udp2mkv and mkv2udp
/*
* Read limited subset of matroska files (generated by udp2mkv) and stream them to network as UDP packets
*
* Limitations:
* 1. cluster size is 5 bytes: 08 NN NN NN NN
* 2. Each cluster have only two elements: Timecode and SimpleBlock
* 3. Timecode have size 8 bytes and it is microseconds (timecode scale = 1000)
* 4. SimpleBlock have size as 5 bytes: 08 NN NN NN NN
* 5. There is only one track and it is track number 1
* 6. No lacing
@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 / git
Created November 24, 2015 16:17
Hacky git wrapper to automatically supply --reference for `git clone` based on URL
#!/bin/bash
# git wrapper, to auto-supply --reference to `git clone`
# edit the table below to suit your setup
LOG=/tmp/git.log
echo git: "$@" >> "$LOG"
CLONE=0
@vi
vi / dct.hs
Last active December 5, 2015 18:27
Simple command-line Discrete Cosine Transform in Haskell
-- "cabal install vector-fftw split"
import qualified Numeric.FFT.Vector.Unnormalized as FFT
import Data.Vector (fromList, toList)
import Data.List.Split (splitOneOf)
import Data.List (intersperse)
import Control.Monad (forever)
import Control.Arrow ((>>>))
main = forever $
@vi
vi / uksm_tease.c
Created March 26, 2013 17:15
Test [UKSM][1]: fill up memory pages with the same blocks of random data. [1]:http://kerneldedup.org/en/projects/uksm/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
if (argc<3) {
fprintf(stderr, "Usage uksm_tease page_size number_of_pages < /dev/urandom\n");
return 1;
}
@vi
vi / y.rs
Last active December 16, 2015 08:49
Y combinator in Rust
/* Y combinator for Rust.
Implemented by Vitaly "_Vi" Shukela.
$ rustc --version
rustc 0.6 (5f13e9c 2013-04-02 13:36:51 -0700)
host: i686-unknown-linux-gnu
*/
type Yfunc<T> = @fn(x:T) -> T;
type Yfunc2<T> = @fn(f: Yfunc<T>, x:T) -> T;