Skip to content

Instantly share code, notes, and snippets.

View adeubank's full-sized avatar
🌳

Allen Eubank adeubank

🌳
View GitHub Profile
@adeubank
adeubank / toUSDateString.js
Created August 19, 2013 17:25
Add a method to print the United States date format to the global Date object for JavaScript.
// Add toUSDateString to global Date object, prints Mon/Day/Year
Date.prototype.toUSDateString = function () {
return (this.getMonth() + 1) + "/" + this.getDate() + "/" + this.getFullYear();
};
(new Date()).toUSDateString(); // "MM/DD/YYYY"
@adeubank
adeubank / detectCSSFeature.js
Last active December 21, 2015 13:29
Detect if a browser supports a CSS feature. Courtesy of Stack Overflow. http://stackoverflow.com/questions/10888211/detect-support-for-transition-with-javascript
/**
* Detect if a browser supports a CSS feature.
* Courtesy of Stack Overflow.
* http://stackoverflow.com/questions/10888211/detect-support-for-transition-with-javascript
*
*/
function detectCSSFeature(featurename){
var feature = false,
domPrefixes = 'Webkit Moz ms O'.split(' '),
elm = document.createElement('div'),
@adeubank
adeubank / watchdog.sh
Created July 25, 2014 00:49
Bash script to watch a process and notify you with a text when it is no longer running
#!/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
@adeubank
adeubank / chunked_mysql_dump.sh
Created August 14, 2014 23:49
Bash script that connects to a mysql DB to dump column value. It performs this in batches instead of one try. Useful when exporting large amount of data.
#!/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
@adeubank
adeubank / isPrime.swift
Last active August 29, 2015 14:05
Adds an extension to the Int class to tell return whether an integer is prime or not
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
}
@adeubank
adeubank / replace-missing-images-with-kittens.js
Last active August 29, 2015 14:07
Replaces all missing images with images of kittens instead.
function kittenizeAllImages() {
var images = document.getElementsByTagName('img');
for (var i = 0; !!images[i]; i++) {
if (!! images[i].dataset.notChecked)
continue;
checkImage(images[i]);
}
}
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) {
@adeubank
adeubank / inspectHelper.js
Last active August 29, 2015 14:12
Have handlebars output a JSON object of 'this' or passed in value. In my Googling, I didn't find anything on my first try, so I made this!
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
@adeubank
adeubank / resizeImages.jsx
Created January 7, 2015 00:54
Process all of those images before you upload them to your site. Here is a photoshop script to do that. File -> Scripts -> Browse
// 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");
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04