Skip to content

Instantly share code, notes, and snippets.

@maxpeterson
maxpeterson / rename-jekyll.sh
Created November 24, 2015 18:16
Rename slides in a jekyll edetail project
#!/bin/sh
from=$1; shift
to=$1; shift
echo rename $from $to;
grep -rl --exclude-dir _site "$from" jekyll-project sass | xargs perl -pi -e "s|\Q$from|$to|g"
find jekyll-project sass -name \*"$from"\* -not -path jekyll-project/_site/\* -type d | while read path ; do
@maxpeterson
maxpeterson / hammer-veevaify.sh
Last active August 29, 2015 14:26
Prepare a Hammered project for Veeva.
#!/bin/sh
for filename in *.html ; do
basename="${filename%.*}";
echo "$filename"
mkdir -p "$basename/slides";
ln -s "../assets" "$basename/assets";
git mv "$filename" "$basename/$filename";
git mv assets/images/slides/2x/$basename* "$basename/slides/";
# Thumbs
@maxpeterson
maxpeterson / twoWayBind.js
Created June 29, 2015 19:37
AngularJs - bind the local variable name to the remote variable name in the parent scope.
// Bind the local variable name to the remote variable name in the parent scope.
module.factory('twoWayBind', function ($parse) {
return function (scope, local, remote) {
// 2-way bind the model attribute
if (angular.isUndefined(remote)) {
remote = local;
}
var parentAssign = $parse(remote).assign;
var localAssign = $parse(local).assign;
scope.$watch(remote, function(value) {
#!/bin/bash
root=$( cd -P "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd)
usage="
Usage: `basename $0` [source] [ratio]
Generate video poster images.
Arguments
@maxpeterson
maxpeterson / pdf-reduce.sh
Created March 8, 2015 19:58
Reduce pdf quality to screen (72dpi)
# Reduce screen : 72dpi
mkdir -p _72dpi
cd _Cropped;
find . -name \*.pdf|while read file; do
src="$file";
dst="../_72dpi/$src"
if [[ $dst != */_old/* ]] ; then
if [ ! -f "$dst" ] ; then
echo $dst;
@maxpeterson
maxpeterson / angular-ie8debug
Created November 21, 2014 18:59
Angular factory for debugging IE8 by prepending `compiled` templates to the body
angular.module('ie8debug').factory('prepend', [
'$rootScope',
'$compile',
function($rootScope, $compile) {
return function (template, context) {
var scope = $rootScope.$new(true);
angular.extend(scope, context);
angular.element(document).find('body').prepend(
$compile(template)(scope)
);
@maxpeterson
maxpeterson / channgelog.sh
Created January 31, 2014 10:20
Bash function to build a changelog based on the tags and commit entries of a git repo
changelog_entry() {
# Output individual changelog entry
usage="changelog_entry <since> <until>"
since=${1}
until=${2}
if [ "${since}" == "" ] ; then
echo "No 'since' version"
echo ${usage}
return 1
@maxpeterson
maxpeterson / gist:7168948
Last active December 26, 2015 14:49
Backup raspberrypi card
  • Find the disk

diskutil list

   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *320.1 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            319.2 GB   disk0s2
 3: Apple_Boot Recovery HD 650.0 MB disk0s3
@maxpeterson
maxpeterson / gist:6122758
Last active December 20, 2015 11:19
Update key messages ins slides.yaml from key messages downloaded from Veeva report.
# Split key messages data
awk -F "\",\"" '{print $3 " " substr(substr($4, 0, match($4, /.zip/)-1), 26)}' keymessages.csv
# sed
awk -F "\"*,\"*" '{print " -e \"s/keyMessageId: "substr(substr($4, 0, match($4, /.zip/)-1), 26)"/keyMessageId: "$3"/\"\\"}' keymessages.csv \
| xargs -J % sed % -i '' project/data/slides.yaml
@maxpeterson
maxpeterson / gist:6116613
Created July 30, 2013 20:28
Queue to ensure that functions are not called concurrently. Created to wrap Veeva API calls that can not be called concurrently.
// The Veeva API can only accept one call at a time.
// A queue is used to avoid calling the API while an earlier call is in progress.
var Queue = (function () {
var queue = [];
var empty = true;
return {
// Add a function to the queue
// (it will be called immediately if the queue is empty)
push: function (fn) {
queue.push(fn);