Skip to content

Instantly share code, notes, and snippets.

View robatwilliams's full-sized avatar

Robat Williams robatwilliams

View GitHub Profile
@robatwilliams
robatwilliams / index.html
Last active August 29, 2015 13:57
Binding the document head with KnockoutJS: http://bl.ocks.org/robatwilliams/raw/9833970/
<!doctype html>
<html>
<head>
<title data-bind="text: title">App: Loading ...</title>
<link rel="stylesheet" id="themeLink" data-bind="attr: { href: selectedTheme().url }"
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/black-tie/jquery-ui.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.4/jquery-ui.js"></script>
@robatwilliams
robatwilliams / gist:4318053
Created December 17, 2012 12:48
Get the username part of the SVN repository url. Doesn't echo anything unless there is one.
# e.g from svn+ssh://username@myrepo.internal
svn info | grep URL: | cut -d / -f 3 | cut -d @ -s -f 1
# output: username
@robatwilliams
robatwilliams / gist:4318481
Created December 17, 2012 14:01
Make a Bash script source another script from the same folder as it itself is located
source `dirname $BASH_SOURCE`/otherscript.sh
@robatwilliams
robatwilliams / gist:4318429
Created December 17, 2012 13:53
Processing shell script options
unset OPTSTRING
unset OPTIND
local opt
while getopts "ab:c" opt; do
case $opt in
a)
aSpecified=true
;;
b)
@robatwilliams
robatwilliams / gist:4318465
Created December 17, 2012 13:58
Get process id based on some identifier used in the command that started it
# $1 is the identifier
local idStart=`echo $1 | cut -c 1`
local idEnd=`echo $1 | cut -c 2-`
local idComplete="[$idStart]$idEnd"
ps -f -u $USER | grep -i "identifier=$idComplete" | awk '{ print $2}'
@robatwilliams
robatwilliams / gist:4318580
Created December 17, 2012 14:14
Loop over files in a directory, which might be empty
# in case of empty dir
shopt -s nullglob
local fullPath
local fileName
for fullPath in directory/*
do
fileName=`baseName $fullPath`
done
@robatwilliams
robatwilliams / gist:4318604
Created December 17, 2012 14:17
Send commands to an interactive program (e.g. ftp / lftp) from a shell script
lftp hostname <<SCRIPT
put ~/myfile.txt
quit
SCRIPT
echo "now carry on with script (check return code etc.)"
@robatwilliams
robatwilliams / deleteOldBranches.sh
Created November 3, 2017 17:30
Delete old local Git branches
# manually
git remote update origin --prune
git branch -vv | grep "gone]"
git branch -d theBranchName anotherBranch andAnotherBranch
# automatically
git branch -vv | grep "gone]" | awk '{print $1}' | xargs git branch -d
@robatwilliams
robatwilliams / repoSize.sh
Created November 3, 2017 17:31
Get size of Git repo
git gc
git count-objects -vH
// Based on https://spectreattack.com/spectre.pdf, sections 3 mainly, 4, 4.3
// Also see: https://webkit.org/blog/8048/what-spectre-and-meltdown-mean-for-webkit/
const array1 = [1, 2, 3];
const array1_size = 3;
const array2_size = (64 * 1024) / 8;
const array2 = new Array(array2_size); // 8192 empty 8-byte entries = 64KB. 64KB is 256*256
function run() {
setup();