View watchdog.sh
#!/bin/bash | |
# | |
# Watchdog watches a process passed in as the first argument waits until | |
# it finishes and then sends a text message to the number provided. | |
# | |
PID=$1 | |
NUMBER=$2 | |
MESSAGE=$3 |
View chunked_mysql_dump.sh
#!/bin/bash | |
# Connects to a MySQL database to dump data in batches. | |
# Great for dumping large datasets. | |
LIMIT=1000000 | |
OFFSET=0 | |
MAX_ROWS=1000000000 | |
# This loops until it has read MAX_ROWS |
View isPrime.swift
extension Int { | |
func isPrime() -> Bool { | |
if (self == 1) { return false } | |
if (self == 2) { return true } | |
var sqr = Int(sqrt(Float(self))) + 1 | |
for i in 2...sqr { | |
if self % i == 0 { | |
return false | |
} |
View replace-missing-images-with-kittens.js
function kittenizeAllImages() { | |
var images = document.getElementsByTagName('img'); | |
for (var i = 0; !!images[i]; i++) { | |
if (!! images[i].dataset.notChecked) | |
continue; | |
checkImage(images[i]); | |
} | |
} |
View get_products_of_all_ints_except_at_index.js
function get_products_of_all_ints_except_at_index(arr) { | |
var numbersBeforeIndex = []; | |
var numbersAfterIndex = []; | |
for (var i = 0; i < arr.length; i++) { | |
numbersBeforeIndex[i] = arr.slice(0, i); | |
if (numbersBeforeIndex[i].length) { | |
numbersBeforeIndex[i] = numbersBeforeIndex[i].reduce(function (a, b) { |
View inspectHelper.js
Handlebars.registerHelper('inspect', function(context) { | |
return JSON.stringify(context, null, 2) || JSON.stringify(this, null, 2); | |
}); | |
// Usage: <pre>{{inspect}}</pre> or <pre>{{inspect variableName}}</pre> for nicely formatted code |
View resizeImages.jsx
// A Photoshop script to process a folder of images. It creates 3 versions of each image | |
// e.g. some-image-name.jpg will produce | |
// * some-image-name-full.jpg | |
// * some-image-name-mobile.jpg | |
// * some-image-name-thumbnail.jpg | |
var IMAGE_QUALITY = 5; | |
var VALID_IMAGE_TYPES = Array( "jpg", "png", "gif"); |
View bash-cheatsheet.sh
#!/bin/bash | |
##################################################### | |
# Name: Bash CheatSheet for Mac OSX | |
# | |
# A little overlook of the Bash basics | |
# | |
# Usage: | |
# | |
# Author: J. Le Coupanec | |
# Date: 2014/11/04 |
View gist:2a033900ed57e59da5b2
# http://stackoverflow.com/questions/13793836/how-to-detect-if-a-git-clone-failed-in-a-bash-script | |
# Here are some common forms. | |
# Which is the best to choose depends on what you do. | |
# You can use any subset or combination of them in a single | |
# script without it being bad style. | |
if ! failingcommand | |
then | |
echo >&2 message |
View gist:172b42192ce609a45144
var internetExplorerVersion = (function (){ | |
if (window.ActiveXObject === undefined) return null; | |
if (!document.querySelector) return 7; | |
if (!document.addEventListener) return 8; | |
if (!window.atob) return 9; | |
if (!document.__proto__) return 10; | |
return 11; | |
})(); | |
if (internetExplorerVersion) { |
OlderNewer