Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am markrose on github.
* I am markrose (https://keybase.io/markrose) on keybase.
* I have a public key ASBwls4s0qiUunhReloVUOmQLK8Qw0J5EY2Mr9t0RrmQfwo
To claim this, I am signing this object:
@MarkRose
MarkRose / gist:2577408
Created May 2, 2012 15:19
Count matching lines per second in a log file
# Use a command like this to watch the number of matching lines in a log file
tail -f logfile | grep whatever | pv -lr 2>&1 >/dev/null
@MarkRose
MarkRose / find_broken_php.sh
Created March 23, 2012 18:36
Recursively find PHP files with syntax errors, stopping at first one
#!/bin/bash
for i in $(find -name "*php" | sort) ; do php -l $i ; if [ $? -gt 0 ] ; then break ; fi ; done
@MarkRose
MarkRose / space_to_tabs.sh
Created March 20, 2012 21:44
Convert spaces to tabs
#!/bin/sh
# Have to work with coders who use 4 spaces indentation instead of tabs? This is my shortcut to mending their ways.
for i in $(ls) ; do expand -t4 $i > $i.broken ; unexpand -t4 --first-only $i.broken > $i ; rm $i.broken ; done
@MarkRose
MarkRose / reuse_agent.sh
Last active September 11, 2023 06:42
Reuse existing ssh-agent or start a new one
# Reuse an existing ssh-agent on login, or create a new one. Append this to your .bashrc
# I have no idea who the author of the original concept was for reusing agents. This
# version also handles the case where the agent exists but has no keys.
GOT_AGENT=0
for FILE in $(find /tmp/ssh-* -type s -user ${LOGNAME} -name "agent.[0-9]*" 2>/dev/null)
do
SOCK_PID=${FILE##*.}
@MarkRose
MarkRose / fast_php_merge.php
Created September 16, 2011 04:31
A faster way to merge sorted PHP arrays by a value of a key in the arrays
<?php
/**
* I've yet to come across a fast way to merge sorted arrays by a user value.
* Merging the arrays and using PHP's usort isn't efficient, as it doesn't take
* advantage of the existing sorting. So I wrote my own merge sorted arrays by user
* value function. The limit parameter can be used be used to limit the number of
* results (there is no point sorting more results than needed). This sort is stable:
* values will be taken preferentially from the first, then second, etc., array
* inside $merge_arrays.