Skip to content

Instantly share code, notes, and snippets.

@yurial
yurial / hax.c
Created June 24, 2020 15:20 — forked from apsun/hax.c
Hook main() using LD_PRELOAD
/*
* Hook main() using LD_PRELOAD, because why not?
* Obviously, this code is not portable. Use at your own risk.
*
* Compile using 'gcc hax.c -o hax.so -fPIC -shared -ldl'
* Then run your program as 'LD_PRELOAD=$PWD/hax.so ./a.out'
*/
#define _GNU_SOURCE
#include <stdio.h>
let main_pubkey = base58'qweqwe'
let main_address = addressFromPublicKey(main_pubkey)
match tx {
case t:ExchangeTransaction => sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
case t:TransferTransaction => main_address == addressFromRecipient(t.recipient)
case t:SetScriptTransaction => sigVerify(tx.bodyBytes, tx.proofs[0], main_pubkey)
case _ => false
}
@yurial
yurial / reshard.py
Created March 24, 2018 19:35
consistent sharding
def generate_keysets(n_shards, keys):
n_keys = len(keys)
shards = []
shards.append(keys)
elements_required = n_keys
shard_to_pop = 0
for step in xrange(1,n_shards):
need_count = n_keys // (step+1)
new_shard = []
for i in xrange(0,need_count):
@yurial
yurial / libfunc
Created July 9, 2015 06:17
libfunc
#/usr/bin/env bash
$(readelf -V $1 |sed -n "/.gnu.version_r.*/,/#/p" | while read LINE; do
echo $LINE |grep -q 'File: ';
if [ $? -eq 0 ]; then
CURLIB=`echo $LINE |egrep -o "([a-zA-Z0-9\.]+?\.so(\.[a-zA-Z0-9\.]+?)?)"`;
else
echo $LINE |grep -q 'Version: ';
if [ $? -eq 0 ]; then
VER=`echo $LINE |egrep -o "Version: [0-9]+" |egrep -o "[0-9]+"`;
#include <stdlib.h>
#include <stdio.h>
#include <iterator>
#include <iostream>
#include "../ext/strtok.h"
using ext::strtok;
using ext::uniqtok;
@yurial
yurial / strtok.cpp
Last active December 15, 2015 09:19
#ifndef EXT_TOKH
#define EXT_TOKH
#include <string>
#include <vector>
#include <set>
namespace ext
{
@yurial
yurial / git-rebase--interactive.patch
Created February 25, 2012 16:29
show author on rebase
fix:
/usr/libexec/git-core/git-rebase--interactive
-git rev-list $merges_option --pretty=oneline --abbrev-commit\
+git rev-list $merges_option --pretty=">%h (%an <%ae>) %s"\
result:
1 pick 19f43c1 (Yuri Dyachenko <yurial@gplvote.org>) add: gcrypt::noerr
2 pick 990a7e8 (Yuri Dyachenko <yurial@gplvote.org>) add: gcrypt::throwif( err ) throw if err != noerr
3 pick cb03f3b (Yuri Dyachenko <yurial@gplvote.org>) add: ext::move<T> move semantic
@yurial
yurial / ssh-sc
Created November 21, 2011 09:06
ssh - screen
$ cat .bin/ssh-sc
#!/bin/bash
RET=1
PARAMS=
SESSION="auto-$RANDOM$RANDOM"
until [ -z "$1" ]; do
case "$1" in
'-S')
RET=1
#!/bin/bash
N=0
HOST=$1
while [ 0 ]; do
START=`expr $N \* 33`
STOP=`expr $START + 16`
START2=`expr $STOP + 1`
@yurial
yurial / swapfile.c
Created June 30, 2011 17:22
swap the file bytes
#include <stdio.h>
#define BUFF_SIZE (4*1024)
void swap(char* buff, size_t count)
{
char* begin = buff;
char* end = buff + count - 1;
while ( begin < end )
{