Skip to content

Instantly share code, notes, and snippets.

View Jacajack's full-sized avatar
🦄

Jacek Wieczorek Jacajack

🦄
View GitHub Profile
@Jacajack
Jacajack / nsect.c
Last active September 23, 2019 15:58
N-section method benchmarking
/*
Compile with: clang -O3 -o nsect nsect.c -Wall -DCOUNT=5000000 -DNSECT=? -funroll-loops
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <sys/time.h>
@Jacajack
Jacajack / makefile-arm
Created July 31, 2019 16:34
Old liblightmodbus makefile for STM32F103
# liblightmodbus - a lightweight, multiplatform Modbus library
# Copyright (C) 2017 Jacek Wieczorek <mrjjot@gmail.com>
# This file is part of liblightmodbus.
# Liblightmodbus is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@Jacajack
Jacajack / iir.c
Last active July 14, 2019 17:56
IIR filter
struct iir_filter
{
float *w; // w coefficients
float *a; // a coefficients
float *b; // b coefficients
int n; // filter size
};
float iir_push( struct iir_filter *f, float x )
{
@Jacajack
Jacajack / packages-arch.csv
Last active September 27, 2019 22:54
My favorite programs (arch version) (not tested yet)
#Group Package name Description
sudo running programs as root
ssh remote shell
sshfs for mapping filesystems over network
pv program for measuring data flow through pipes
git version control system
moreutils more utilities
rsync for making backups and copying files
tree file tree view
rename powerful renaming utility
@Jacajack
Jacajack / host-patcher.sh
Last active June 27, 2019 21:31
/etc/hosts patch generator (based on StevenBlack repo)
#!/bin/bash
BLOCK="gambling porn fakenews social"
EXCEPT=""
cp hosts hosts.new
# Base
echo "blocking adware + malware..."
curl -s "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" | sed -ne '/# Start StevenBlack/,$p' >> hosts.new
@Jacajack
Jacajack / c_exceptions.c
Created May 4, 2019 21:39
C setjmp/longjmp based exception system
#include <setjmp.h>
#include <stdio.h>
union exception_data
{
const char *string;
double d;
int i;
};
@Jacajack
Jacajack / .clang-format
Created April 26, 2019 14:39
Almost satisfying clang-format-9 config file
---
BasedOnStyle: LLVM
TabWidth: 4
IndentWidth: 4
UseTab: Always
ColumnLimit: 0
---
Language: Cpp
AccessModifierOffset: 0
@Jacajack
Jacajack / utils.md
Last active November 10, 2019 21:20
Cool commands I keep forgetting about

Cool commands I keep forgetting about

  • pandoc file.md -t beamer -o out.pdf - create beamer presentation from markdown file
  • nm - list symbols from object file
  • sending file with Xmodem (requires lrzsz):
    • screen /dev/tty* 115200
    • Ctrl + A, :exec !! sx file.txt
  • sudo getty -L 115200 ttyUSB0 vt102 - terminal over serial line (persistent)
  • objdump -D -b binary -mi386 -Maddr16,data16 -Mintel file.bin - disassemble raw 16-bit i386 binary file with Intel syntax
  • ffmpeg ... -vcodec hevc_nvenc/h264_nvenc - use Nvidia GPU for video encoding with ffmpeg
  • echo "file.txt" | entr command - run command each time file changes
@Jacajack
Jacajack / url_request.cpp
Created April 22, 2019 22:17
CURL-based, easy to use C++ URL request class
#include "url_request.hpp"
#include <algorithm>
#include <stdexcept>
// The write callback function
size_t url_request::write_callback( void *contents, size_t size, size_t nmemb, void *userp )
{
size_t realsize = size * nmemb;
url_request *rq = static_cast<url_request*>( userp );
std::uint8_t *b = static_cast<std::uint8_t*>( contents );
@Jacajack
Jacajack / flags.md
Created March 12, 2019 16:53
My list of useful compilation flags

Warnings:

  • -Weverything - even more than -Wpedantic in Clang

Debugging:

  • -g - Preserve debugging symbols
  • -fno-omit-frame-pointer - if some symbols remain broken
  • -fno-builtin - Do not perform some printf, scanf, malloc, etc. optimizations (debugging is easier)
  • -fsanitize=address - Use address sanitizer
  • -fsanitize=thread - Use thread sanitizer
  • -fsanitize=undefined - Use UB sanitizer