Skip to content

Instantly share code, notes, and snippets.

AWK

High-level language for text processing and pattern matching. Has C-like syntax and many built-in functions for working with strings.

Example programs

To better understand, here are some example programs.

/* Display lines between 42 and 666 */
[[ "$TMUX" != "" ]] && TERM=xterm-256color
alias tmux='TERM=xterm-256color /usr/bin/tmux'
@dalibor-drgon
dalibor-drgon / float.c
Last active June 15, 2022 21:16
Floating point hacking
/**
Compile and run with: gcc float.c -lm && ./a.out
Output:
Float 13.000000 deconstructed as [+ (1.10100000000000000000000) * 2^3]
Float -3.250000 deconstructed as [- (1.10100000000000000000000) * 2^1]
Float 0.375000 deconstructed as [+ (1.10000000000000000000000) * 2^-2]
Multiplication: [+ (1.00000000000000000000000) * 2^1] * [+ (1.10000000000000000000000) * 2^-2] = [+ (1.10000000000000000000000) * 2^-1]
AKA 2.000000 * 0.375000 = 0.750000
Multiplication: [+ (1.10100000000000000000000) * 2^3] * [- (1.10100000000000000000000) * 2^1] = [- (1.01010010000000000000000) * 2^5]
AKA 13.000000 * -3.250000 = -42.250000 [got instead -42.250000]
@dalibor-drgon
dalibor-drgon / recip14.c
Created September 7, 2021 08:15
Reciprocal algorithms
/* Copyright (c) 2015, Intel Corporation Redistribution and use in source and
binary forms, with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors may
@dalibor-drgon
dalibor-drgon / openssl_2way_auth.sh
Created August 7, 2021 11:11 — forked from zapstar/openssl_2way_auth.sh
Steps to create CA, server and client keys + certificates for SSL 2-way authentication
# Move to root directory...
cd /
mkdir keys
cd keys
# Generate a self signed certificate for the CA along with a key.
mkdir -p ca/private
chmod 700 ca/private
# NOTE: I'm using -nodes, this means that once anybody gets
# their hands on this particular key, they can become this CA.
@dalibor-drgon
dalibor-drgon / bt.sh
Created August 4, 2021 16:13
A2DP vs HSP toggle for PulseAudio PipeWire Linux Fix
#! /bin/bash
# Script that finds connected bluetooth device (must be exactly 1 device!)
# and switches between a2dp and hsp (the second option also set default source
# to the newly created hsp microphone.)
STATE_FILE=~/bt.txt # where to store the state (2 bytes)
DEVICE=$(pactl list cards | grep "Name: bluez" | sed "s/[ \t]*Name: //")
CUR=$(cat $STATE_FILE)
echo "Card: $DEVICE"
if [ $CUR = "1" ]; then
@dalibor-drgon
dalibor-drgon / InverseKinematics.c
Created May 30, 2017 16:42
Inverse kinematics test
#include <math.h>
typedef struct {
double x, y, z;
} Position3;
typedef struct {
double l1, l2;
double base, j1, j2;
@dalibor-drgon
dalibor-drgon / PageInfo.java
Created April 18, 2017 10:39
Residence PageInfo.java temporal fix
package com.bekvon.bukkit.residence.text.help;
public class PageInfo {
private int totalEntries = 0;
private int totalPages = 0; //ceil(totalEntries / perPage)
private int start = 0; //start index in array
private int end = 0; //last accessed index in array (in loop use <=)
private int currentPage = 0;