Skip to content

Instantly share code, notes, and snippets.

View stephencroberts's full-sized avatar

Stephen Roberts stephencroberts

View GitHub Profile
@stephencroberts
stephencroberts / log.sh
Last active May 15, 2019 18:35
Shell script function for logging with log levels and custom formatting (POSIX compatible)
##############################################################################
# Logs messages with a configurable logging level and format, accepting input
# from either stdin (such as a pipe) or as arguments
#
# Author: Stephen Roberts <stephenroberts@gmail.com>
#
# Globals:
# LOGLEVEL - arbitrary integer for desired log output level (default: 0)
#
# Arguments:
@stephencroberts
stephencroberts / twto.sh
Last active May 4, 2019 01:03
Shell script to time a command with a timeout (POSIX compliant)
#!/bin/sh
#
# Time a command with a timeout
#
# Author: Stephen Roberts <stephenroberts@gmail.com>
# Version: 1
#
# Usage: twto [OPTIONS] TIMEOUT COMMAND
#
@stephencroberts
stephencroberts / config.coffee
Created June 5, 2015 05:12
Angular head module
'use strict'
headConfig = [
{
name: 'title'
selector: 'title'
template: '<title></title>'
html: true
}
{
@stephencroberts
stephencroberts / service.coffee
Created June 4, 2015 02:12
Angular service promise caching
getResponse = (method, type, params) =>
@promises ||= {}
promiseKey = (method + type + JSON.stringify params).replace(/[\{\}",:\-\._\[\] ]/g, '')
return @promises[promiseKey] if @promises[promiseKey]
console.log promiseKey
deferred = $q.defer()
params ||= {}
params.access_token = contentfulConfig.access_token
@stephencroberts
stephencroberts / review.coffee
Created May 25, 2015 15:54
Angular object literal proto
'use strict'
reviewProto = {
getTitle: ->
@fields.title if @fields and @fields.title
getAlias: ->
@fields.alias if @fields and @fields.alias
getSuperLabel: ->
@fields.category if @fields and @fields.category
getShortDescription: ->
@stephencroberts
stephencroberts / object.js
Last active August 29, 2015 14:21
Convert json object to Review model
{
file: {
url: "http://someimage.jpg",
title: "Some Image"
}
}
{
file: {
url: "http://someimage.jpg",
title: "Some Image"
}
}
@stephencroberts
stephencroberts / data.coffee
Created May 23, 2015 05:09
AngularJS dynamic models
'use strict'
data = ($injector) ->
init = ->
registerModels()
service = {}
registerModels = ->
# This is a template .gitignore file for git-managed WordPress projects.
#
# Fact: you don't want WordPress core files, or your server-specific
# configuration files etc., in your project's repository. You just don't.
#
# Solution: stick this file up your repository root (which it assumes is
# also the WordPress root directory) and add exceptions for any plugins,
# themes, and other directories that should be under version control.
#
# See the comments below for more info on how to add exceptions for your
@stephencroberts
stephencroberts / build.xml
Last active May 25, 2017 13:55
Phing build file for Joomla! extensions
<?xml version="1.0" encoding="UTF-8"?>
<project name="digitollsoftware" default="dist">
<tstamp />
<!-- Load local properties -->
<property file="./build.properties" override="true" />
<!-- Get package version from the latest tag in git -->