Skip to content

Instantly share code, notes, and snippets.

@delputnam
delputnam / bash-file-loop.sh
Created December 27, 2016 13:30
Loop through files in bash script
for file in /dir/*
do
# command
done
@delputnam
delputnam / get_dir.sh
Created December 27, 2016 13:29
Get directory of bash script
pushd `dirname $0` > /dev/null
SCRIPT_DIR=`pwd`
popd > /dev/null
@delputnam
delputnam / remove_empty_descendants.php
Created December 23, 2016 17:41
Iterative post-order traversal of the DOM to remove empty nodes.
<?php
/**
* Post-order traversal of the dom starting at given node. Remove any
* nodes that have no children and no attributes. Nodes named in the
* AMP_Rule_Spec::node_types_to_allow_empty array will not be removed.
*/
private function remove_empty_descendants( $node ) {
$stack = array();
$next_traversal = 'child';
$nodes_to_remove = array();
@delputnam
delputnam / Dockerfile
Created December 7, 2016 18:45 — forked from withinboredom/Dockerfile
WordPress plugin
FROM wordpress:4.6.1-php5.6-apache
RUN yes | pecl install xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.idekey=bonkers" >> /usr/local/etc/php/conf.d/xdebug.ini
mkdir <repo>
cd <repo>
git init
git remote add -f origin <url>
# This creates an empty repository with your remote, and fetches all objects
# but doesn't check them out.
# Then do:
git config core.sparseCheckout true
@delputnam
delputnam / TextColor.swift
Created June 25, 2016 12:27
Determine if a UIColor is light or dark
// Returns black if the given background color is light or white if the given color is dark
func textColor(bgColor: UIColor) -> UIColor {
var r: CGFloat = 0.0
var g: CGFloat = 0.0
var b: CGFloat = 0.0
var a: CGFloat = 0.0
var brightness: CGFloat = 0.0
bgColor.getRed(&r, green: &g, blue: &b, alpha: &a)
@delputnam
delputnam / uicolorExtension.swift
Created June 23, 2016 12:10
UIColor extension to convert UIColor to RGB, HSB, or String values.
extension UIColor {
var rgbComponents:(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
var r:CGFloat = 0
var g:CGFloat = 0
var b:CGFloat = 0
var a:CGFloat = 0
if getRed(&r, green: &g, blue: &b, alpha: &a) {
return (r,g,b,a)
}
return (0,0,0,0)
@delputnam
delputnam / googleforms2slack.gs
Created May 23, 2016 13:04
Google Forms Slack Notification
// Google Forms Slack Notification
// Andy Chase <github.com/andychase>
// License: CC0 1.0 Universal <creativecommons.org/publicdomain/zero/1.0>
// Install 1: This code goes in ( tools > script editor... ) of your google docs form
// Install 2: ( resources > current project triggers ) ( [onSubmit], [from Form], [On form submit] )
// Setup 1: Put your slack api url below
var POST_URL = "https://hooks.slack.com/services/";
function onSubmit(e) {
@delputnam
delputnam / replace.sh
Created May 12, 2016 14:49
replace this with that recursively
find /home/www -type f -print0 | xargs -0 sed -i 's/replace this string/with that string/g'
mkdir repo_name
cd repo_name
git init
git remote add origin git@github.com:username/repo_name.git
git config core.sparsecheckout true
echo "dir_to_clone/*" >> .git/info/sparse-checkout
git pull origin master