Skip to content

Instantly share code, notes, and snippets.

View markusfisch's full-sized avatar

Markus Fisch markusfisch

View GitHub Profile
@markusfisch
markusfisch / mkpw.rb
Last active September 25, 2015 01:57
mkpasswd in ruby
#!/usr/bin/env ruby
c = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789!-_".split( // )
(ARGV.length.zero? ? [8] : ARGV).each do |n|
puts (0...n.to_i).map{ c[rand( c.size )] }.join
end
@markusfisch
markusfisch / unpack.sh
Last active March 18, 2021 18:37
bash script to extract archives always in a directory
#!/usr/bin/env bash
# Unpack archive safely (means always in its own directory
#
# @param 1 - name and path of archive to extract
function unpack()
{
local ARCHIVE=$1
local TMP=".unpack-$USER-$$"
local NAME=${ARCHIVE##*/}
@markusfisch
markusfisch / Makefile
Last active June 29, 2019 01:01
Makefile to generate create/drop/recreate scripts from a bunch of SQL files
CREATE=create.sql
DROP=drop.sql
RECREATE=recreate.sql
all: recreate
recreate: clean create drop
cat $(DROP) $(CREATE) > $(RECREATE)
create:
@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 / mkpw.sh
Last active January 24, 2023 15:15
mkpasswd in bash
#!/usr/bin/env bash
C=${CHARSET:-'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789!-_'}
P=
for (( N=${1:-8}; N--; ))
do
P=$P${C:$(( RANDOM%${#C} )):1}
done
@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 / latestgreatest.pl
Created February 16, 2012 20:47
List all files of the given paths sorted by size or time of modification
#!/usr/bin/env perl
#
# latestgreatest - list all files of the given paths sorted by size or
# time of modification
#
# I wrote this for demonstration purposes only.
#
# On a sane system, you should use find instead:
#
# To find files that did change since yesterday:
@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 / CheckRange.js
Created March 22, 2012 22:43
A bookmarklet to check a range of checkboxes
(function( w )
{
if( w.checkRange )
return;
w.checkRange =
{
last: null,
status: false,
@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