Skip to content

Instantly share code, notes, and snippets.

View markusfisch's full-sized avatar

Markus Fisch markusfisch

View GitHub Profile
@markusfisch
markusfisch / local_ip.c
Created July 30, 2013 06:27
Return first local IP address
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
/**
* Local IP address
*
* @param buf - buffer to take ip address
* @param len - length of buffer
@markusfisch
markusfisch / headers.sh
Created October 21, 2013 13:03
Grep sources for system includes (e.g. for AC_CHECK_HEADERS in configure.ac)
#!/usr/bin/env bash
# Grep sources for system includes; e.g. for AC_CHECK_HEADERS:
# $ echo "AC_CHECK_HEADERS([$(./headers.sh | tr '\n' ' ')])" >> configure.ac
#
# @param ... - source files/directories
grep_for_includes()
{
grep -h '#include[ ]*<' $@ | sort | uniq | while read
do
@markusfisch
markusfisch / semicolons.pl
Created October 30, 2013 11:43
Count the number of semicolons in a source file. This is a better (though still imperfect) approach to measure the complexity of a project than simply counting lines.
#!/usr/bin/env perl
print join( '', <STDIN> ) =~ tr/;// . "\n";
@markusfisch
markusfisch / fixcr.sh
Last active January 15, 2016 17:12
Deal with those needless carriage returns (CR) in text files from/for coworkers/friends on Windows
#!/usr/bin/env bash
readonly CR=$'\r'
# Add CR to given stream
add_cr()
{
while read -r
do
echo "$REPLY"$CR
@markusfisch
markusfisch / README.md
Last active January 15, 2016 17:12
A little script that helps to generate a source archive for CSS/JavaScript files.

srcar

Helps you to generate a source archive for your CSS/JavaScript files.

Compressing multiple CSS/JavaScript files in just one archive will speed up your website because it will lower the transfer volume and does minimize the number of requests.

If you're using Makefiles (or anything similar) to automate building

@markusfisch
markusfisch / vup.sh
Last active January 15, 2016 17:12
Update version number of a project. Useful for sources with autotools and doxygen.
#!/usr/bin/env bash
# check for required tools
for X in find grep sed mktemp
do
which $X &>/dev/null || {
echo "error: missing $X" >&2
exit 1
}
done
@markusfisch
markusfisch / refactor.sh
Last active January 15, 2016 17:13
bash script to exchange a literal in files and file names (can be used to completely rename a Xcode project or to refactor something throughout your whole project, use with caution!)
#!/usr/bin/env bash
# Refactor file and directory names as well as words in files
#
# @param 1 - case-sensitive pattern to replace
# @param 2 - replacement string
# @param 3 - working directory (optional)
refactor()
{
local PATTERN=$1
@markusfisch
markusfisch / depth.sh
Last active January 15, 2016 17:24
Count indent levels and echo lines that are indented over a given limit
#!/usr/bin/env bash
# Read lines from stdin and echo them if the indent is too deep
#
# @param 1 - levels of indent to consider too much (optional)
# @param 2 - indent character (optional)
check_indents()
{
local THRESHOLD=${1:-3}
local INDENT=${2:-$'\t'}
@markusfisch
markusfisch / readkey.sh
Last active January 15, 2016 17:26
Read a key from stdin in bash
#!/usr/bin/env bash
# Process literal key
process_literal_key()
{
case "$REPLY" in
$'\E')
ESCAPE=1
;;
'')
@markusfisch
markusfisch / README.md
Last active January 15, 2016 17:28
Automatically generate help output from function comments in bash scripts

Auto-help output for bash scripts

Use the attached help() function to automatically generate a help/usage output from function comments.

Example:

$ ./sample.sh
blondie - Call Blondie
help - Print help; use "help NAME" to show details