Skip to content

Instantly share code, notes, and snippets.

View akoskovacs's full-sized avatar

Ákos Kovács akoskovacs

View GitHub Profile
@akoskovacs
akoskovacs / libmyrand.c
Created February 3, 2024 17:52
Monkey patching in C (Linux/Unix)
/*
* Let's redefine rand() by simply compiling creating an position-independent object code:
* $ gcc -c -fPIC libmyrand.c -o libmyrand.o
*
* Then create a shared library object from it:
* $ gcc libmyrand.o -shared -o libmyrand.so
*
* As a last step, load this dynamic library, so the dynamic linker will link this rand(),
* instead of the one inside the standard library:
* $ export LD_PRELOAD=./libmyrand.so
@akoskovacs
akoskovacs / prune.sh
Created December 26, 2023 09:09
Prune all unused docker containers and images
#!/bin/bash
# Dump current disk usage
df -h
# Remove unused containers
yes | docker container prune
# Remove unused images
yes | docker image prune -a
# Dump saved disk space
df -h
@akoskovacs
akoskovacs / api.js
Last active June 14, 2023 22:09
k6 API testing Lucky Framwork template
import http from 'k6/http';
import { check, group } from 'k6';
export let options = {
stages: [
{ duration: '0.5m', target: 3 }, // simulate ramp-up of traffic from 1 to 3 virtual users over 0.5 minutes.
{ duration: '0.5m', target: 4}, // stay at 4 virtual users for 0.5 minutes
{ duration: '0.5m', target: 0 }, // ramp-down to 0 users
],
};
@akoskovacs
akoskovacs / rplace.rb
Last active April 17, 2022 15:22
Ugly/slow/unoptimized/naive PoC r/place exporter from DB to PNG
#!/usr/bin/ruby
require 'io/console'
require 'pg'
require 'chunky_png'
WIDTH = 2000
HEIGHT = 2000
ROWS = 10000
OUTFILE = 'rplace.png'
@akoskovacs
akoskovacs / server.sh
Created September 16, 2020 18:54
Server start/stop/ssh script
#!/bin/bash
# Copy this script to your /usr/local/bin/ /usr/bin, or put its path into PATH
# Customize these:
SERVER_MAC="44:8a:xx:xx:xx:xx"
CLIENT_IFACE="wlp2s0"
SSH_PARAM="user@address"
# ----
myhelp() {
@akoskovacs
akoskovacs / blinker.v
Created September 3, 2020 22:19
Spartan Edge Blinker project
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2019/08/05 11:02:11
// Design Name:
// Module Name: blinker
// Project Name:
// Target Devices:
@akoskovacs
akoskovacs / rayson.json
Created March 7, 2020 02:35
rayson.json
[
["function", ["hello", [], [
["call", ["console", "log"], ["hello, world"]],
["return", []]
]
]
],
["function", ["addTwoNums", ["a", "b"], [
["return", [
["+", ["a", "b"]]
@akoskovacs
akoskovacs / leaf.cxx
Last active January 28, 2019 21:24
Leaf function example
// Compile with: gcc -O2 leaf.c -o leaf
// Proof: https://godbolt.org/z/vg1FSS
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
// Not actually tweaking the stack (except for ret)
int leaf_me_alone(int a, int b)
{
return a*a + b*b / 2;
@akoskovacs
akoskovacs / redditer.js
Last active October 28, 2018 05:11
Plain Reddit reader for the console with Node.js
// esversion: 6;
/// SETTINGS ///
// Maximum number of posts to be showed
const MAX_COUNT = 10;
// List of the subreddits, the desired sort order (multiple is allowed)
// and count of posts
const SUBREDDITS = [
{
name: 'spacex',
@akoskovacs
akoskovacs / miner.rb
Created March 12, 2018 00:13
Example Ruby miner. The way Bitcoin miners try to find a hash for a given complexity and transaction
# Mining example
require 'benchmark'
require 'openssl'
def hash_ok?(hash, complexity)
hash.start_with?("0" * complexity)
end
# Appending a nonce the the
def create_target(str, nonce)