Skip to content

Instantly share code, notes, and snippets.

View markusfisch's full-sized avatar

Markus Fisch markusfisch

View GitHub Profile
@markusfisch
markusfisch / snip.sh
Last active June 29, 2019 00:57
Cut some text into smaller snippets without cutting words in half
#!/usr/bin/env bash
# Cut some text into smaller snippets without cutting words in half
#
# @param ... - text to cut (optional)
snip()
{
local TEXT=${*:-$(cat)} LIMIT=${LIMIT:-140} GLUE=${GLUE:-'..'}
(( LIMIT -= ${#GLUE} ))
@markusfisch
markusfisch / tweet.sh
Last active March 25, 2016 10:54
Shell script to tweet from the command line. Breaks longer messages into multiple tweets. Requires curl.
#!/usr/bin/env bash
# Post a tweet
#
# @param ... - tweet
tweet()
{
# Make a SSL request
#
# @param ... - request arguments
@markusfisch
markusfisch / README.md
Last active May 9, 2023 20:52
Generate a bar chart by reading value/label pairs from stdin

Bar charts from stdin

Put this shell script somewhere in your path and run it by feeding it value/label pairs like this:

$ bars
10 one
20 two
30 three
@markusfisch
markusfisch / README.md
Last active June 29, 2019 00:54
Show file listing as tree

Show file listing as tree structure

This is a very small and simple bash script to show a file listing as a tree structure:

$ tree /etc/apache2
+- extra
|  +- httpd-autoindex.conf
| +- httpd-dav.conf
@markusfisch
markusfisch / uuid.sh
Last active December 13, 2023 15:06
Generate a random UUID in bash
#!/usr/bin/env bash
# Generate a pseudo UUID
uuid()
{
local N B C='89ab'
for (( N=0; N < 16; ++N ))
do
B=$(( $RANDOM%256 ))
@markusfisch
markusfisch / uuid.c
Last active June 29, 2019 00:53
Generate a random UUID
#include <stdio.h>
#include <stdlib.h>
/**
* Create random UUID
*
* @param buf - buffer to be filled with the uuid string
*/
char *random_uuid( char buf[37] )
{
@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 / upnp.sh
Last active October 14, 2020 16:44
bash script to send a UPnP message
#!/usr/bin/env bash
# Send UPnP message
#
# @param 1 - host:port/query (optional when UPNP_URL is set)
# @param 2 - service#action (optional when UPNP_ACTION is set)
# @param 3 - message arguments in XML format (optional)
upnp_send()
{
# prefer arguments over presets
@markusfisch
markusfisch / androidlog.h
Last active June 29, 2019 01:02
Debug header to log to Android, don't forget to add LOCAL_LDLIBS := -llog to Android.mk
#ifndef _androidlog_h_
#define _androidlog_h_
#include <android/log.h>
#define LOG_TAG "your_tag_here"
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
@markusfisch
markusfisch / README.md
Last active July 15, 2021 14:58
bash script to build a texture atlas with a little help from ImageMagick

mkatlas

[BASH][1] script to build a [texture atlas][2] for small/medium web sites/games. Requires [ImageMagick][3].

Usage

Basic