Skip to content

Instantly share code, notes, and snippets.

@lelanthran
lelanthran / cline_test.c
Last active May 27, 2019 21:15
Single function to get command-line options in both long and short form.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
/* *****************************************************************
* A more robust command-line handling function than I normally use.
* There are only two functions, so this is suitable for copying and
* pasting into the file containing main().
@lelanthran
lelanthran / process_args_test.c
Last active August 31, 2019 22:30
More comprehensive c/line arguments processing
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
/* ********************************************************************
* An even more comprehensive command-line parsing mechanism. This method
* allows the program to have long options (--name=value) short options
* (-n value or -nvalue or -abcnvalue) mixed with non-options (arguments
* without a '-' or '--'.
// gcc -o run_inferior run_inferior.c -W -Wall
/* A function to execute a child program and feed the input line-by-line back
* to the calling program. The function mst be called with a callback function
* that will receive each line as it is read in, a program to execute and the
* command line arguments for that program.
*
* There are two versions of this function: one that takes the command line
* arguments as variadic parameters delimited with a NULL pointer and one that
* takes an array of parameters with a length specified for the array.
@lelanthran
lelanthran / reformat.c
Last active December 24, 2020 10:21
C function to reformat textual content into paragraphs
/* gcc -ggdb -W -Wall -pedantic -o reformat.elf reformat.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <ctype.h>
#include <stdbool.h>
/* ************************************************************************* *
(setq-default inhibit-startup-screen t)
(progn
(when (fboundp 'tool-bar-mode)
(tool-bar-mode -1))
(when (fboundp 'scroll-bar-mode)
(scroll-bar-mode -1))
(when (fboundp 'horizontal-scroll-bar-mode)
(horizontal-scroll-bar-mode -1)))
@lelanthran
lelanthran / gitall.sh
Last active June 22, 2021 14:40
Work with many git subdirs.
#!/bin/bash
# Tool to run git on all of the sub-repos specified. Use all the standard
# git commands with this (status, branch, checkout, reset, etc) and each
# command will be run for all of the repos.
# Replace the following list of dirname=url with your own.
export URLS='
[email protected]:lelanthran/askme.git
[email protected]:lelanthran/cgui.git
@lelanthran
lelanthran / pomodoro.sh
Last active September 13, 2022 06:40
basic pomodoro clock, requires wmctrl and zenity
#!/bin/bash
#
# vim: ts=3:sw=3:et
#
# Pomodoro - Basic Pomodoro Clock
# Copyright 2022 Lelanthran Manickum
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
@lelanthran
lelanthran / devlog-gen.sh
Last active August 17, 2023 06:43
Generate html devlog from chap1/content.md, chap2/content.md, etc
#!/bin/bash
# Usage notes:
# 1. Make sure that pandoc is installed.
# 2. Place all your contents for each chapter of your devlog into
# `./chap1/content.md`, `./chap2/content.md`, etc.
# 3. This script will source a file in each chapter called METAINFO.inc. This
# file is optional and can contain two variable declarations:
# AUTHOR="Name Of Author"
# DATE="Date or publication"
@lelanthran
lelanthran / xgit
Created March 13, 2023 05:46
Use a stack to move between git branches.
#!/bin/bash
# Stores the current branch in a file so that popbranch can restore it later.
#
# Find the root of the git repo
while [ `ls -lad .git 2>&1 | grep -v 'No such file' | wc -l` -eq 0 ]; do
if [ $PWD == '/' ]; then
echo Not a git repo
@lelanthran
lelanthran / verbose_proxy.c
Last active June 5, 2024 16:02
A small program to proxy and record all traffic to a server.
/* ********************************************************
* Copyright ©2024 Rundata Systems. All rights reserved.
* This project is licensed under the GPLv3 License. You
* can find a copy of this license at:
* https://www.gnu.org/licenses/gpl-3.0.en.html
*
* More detail (1m read):
* https://www.rundata.co.za/rundata/products/verbose_proxy
*
* Example usage (3m video):