Programming – Buster Collings https://www.bustercollings.com build, measure, learn, share & enjoy Sun, 27 Dec 2020 17:50:26 +0000 en-US hourly 1 Simple Countdown Timer and Stopwatch with Laps for Bash https://www.bustercollings.com/blog/2016/03/03/simple-countdown-timer-and-stopwatch-with-laps-for-bash/ Thu, 03 Mar 2016 22:18:23 +0000 http://www.bustercollings.com/?p=1156 Continue reading Simple Countdown Timer and Stopwatch with Laps for Bash ]]> There are a lot of decent, small shell scripts for creating a simple timer or simple stopwatch. Yet, I needed a bit more than the ones I found on Google, so of course, I made some of my own.

My simple stopwatch for Bash lets you create laps, pause and gives you a total elapsed time. Keep in mind, it’s all presented in seconds.

stopwatch with laps for bash

#!/bin/bash
function stopwatch() {
local n=0
local t=0
local continuing="true"
local lap=1
local key="~"
local pausing="~"
cat <<EOF
* type "p" to pause and "r" to resume
* hit the spacebar to start a new lap
* if paused you will resume with a new lap
* type "q" or "x" or Ctrl-c to stop
EOF
function summary() {
continuing="false" # break the while loop
local elapsed=$(($t-$lap+1))
printf "\r\033[0KLap ${lap}: $n seconds\n"
printf "\nTotal Elapsed: $elapsed seconds\n"
}
trap "summary" SIGINT
while [[ $continuing = "true" ]]; do
key="~"
pausing="~"
printf "\r\033[0KLap ${lap}: $n seconds"
read -s -t 1 -n 1 key
case "$key" in
"")
printf "\r\033[0KLap ${lap}: $n seconds\n"
key=""
n=-1
((lap++))
;;
q|x)
summary
break
;;
p)
function paused() {
read -s -n 1 pausing
case "$pausing" in
"")
printf "\r\033[0KLap ${lap}: $n seconds\n"
key=""
n=-1
((lap++))
;;
q|x)
summary
break
;;
r)
: # noop
;;
*)
paused
;;
esac
}
paused
;;
esac
((t++))
((n++))
done
}
view raw stopwatch.sh hosted with ❤ by GitHub

My simple timer for Bash just countdowns the number of seconds you provide and then beeps. Like my stopwatch script, it’s all based on seconds so that there aren’t a bunch of command line arguments to deal with.

countdown timer for bash

#!/bin/bash
function timer() {
if [[ $1 -lt 1 ]]; then
cat <<EOF
Usage: timer <seconds>
EOF
return 1
fi
local n="$1"
while [[ $n -gt 0 ]]; do
printf "\r\033[0K==> $n"
sleep 1
((n--))
done
printf "\r\a"
}
view raw timer.sh hosted with ❤ by GitHub

]]>
Cordova Tip: Automatically Open Web Inspector for iOS Simulator https://www.bustercollings.com/blog/2016/02/03/cordova-tip-automatically-open-web-inspector-for-ios-simulator/ Wed, 03 Feb 2016 17:44:06 +0000 http://www.bustercollings.com/?p=1138 Continue reading Cordova Tip: Automatically Open Web Inspector for iOS Simulator ]]> How many times have you painfully, manually opened Safari Web Inspector after starting the iOS Simulator with `cordova emulate`? Too often. Me too. No more.

I found a nifty osascript gist then tweaked it a little and put it inside a shell script `ios-sim-inspector`.

Then, I added a couple of new Cordova aliases to my bash profile (leveraging a couple of existing aliases)


## Existing Aliases ##

# Run iOS Simulator
alias corem="killall Simulator || echo && cordova emulate"

# Build and Run iOS Simulator
alias corbem="killall Simulator || echo && cordova build && cordova emulate"


## New Aliases with Web Inspector'ing ##

# Run iOS Simulator with Safari Web Inspector (for Debugging)
alias coremd="corem && ios-sim-inspector"

# Build and Run iOS Simulator with Safari Web Inspector (for Debugging)
alias corbemd="corbem && ios-sim-inspector"

Now you know how to painlessly open Safari Web Inspector after starting the iOS Simulator with Cordova emulate from the command line.

]]>
jsFiddle Player to run, save and download combined CSS, JS and HTML https://www.bustercollings.com/blog/2012/05/15/jsfiddle-player-to-run-save-and-download-combined-css-js-html/ Wed, 16 May 2012 02:27:24 +0000 http://www.bustercollings.com/blog/?p=583 I created a very simple Chrome extension, jsFiddle Player, that allows you to save the combined CSS, JS & HTML output of a jsFiddle. I personally wanted an easy way to download the resulting rendered web page.

jsFiddle is a great tool, hopefully you find jsFiddle Player to be a helpful Chrome extension.

]]>
Yes, No, Don’t Care – Urtak Asks Simple Questions https://www.bustercollings.com/blog/2011/10/19/yes-no-dont-care-urtak-asks-simple-questions/ Wed, 19 Oct 2011 21:26:17 +0000 http://www.bustercollings.com/blog/?p=567 Urtak is a nifty little tool. It’s free and I must say can be a little bit addictive.

I’ve created a simple feedback collection for Buying Concert & Sports Tickets Online


Scope it out here!

]]>