Skip to content

Instantly share code, notes, and snippets.

@delputnam
delputnam / file_check.go
Created February 23, 2016 21:01
Check for existence of file using golang
if _, err := os.Stat("/path/to/file/or/dir"); os.IsNotExist(err) {
// /path/to/file/or/dir does not exist
}
if _, err := os.Stat("/path/to/file/or/dir"); err == nil {
// /path/to/file/or/dir exists
}
sudo lsof -i
sudo netstat -lptu
sudo netstat -tulpn

Keybase proof

I hereby claim:

  • I am delputnam on github.
  • I am delputnam (https://keybase.io/delputnam) on keybase.
  • I have a public key whose fingerprint is 0BF0 8C2E 24F4 9CA1 11AC C4D7 D2DD BB94 503E E5F0

To claim this, I am signing this object:

mkdir repo_name
cd repo_name
git init
git remote add origin [email protected]:username/repo_name.git
git config core.sparsecheckout true
echo "dir_to_clone/*" >> .git/info/sparse-checkout
git pull origin master
@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'
@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 / 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 / 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)
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 / 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