Skip to content

Instantly share code, notes, and snippets.

View cballou's full-sized avatar

Corey Ballou cballou

View GitHub Profile
@cballou
cballou / jquery-form-element-repeater-default-config-values.js
Last active May 17, 2016 12:21
Example usage of the jQuery Form Element Repeater Plugin
// default values
$.fn.repeater.defaults = {
groupClass: 'r-group',
btnAddClass: 'r-btnAdd',
btnRemoveClass: 'r-btnRemove',
minItems: 1,
maxItems: 0,
startingIndex: 0,
reindexOnDelete: true,
repeatMode: 'insertAfterLast', // append, prepend, insertAfterLast
/**
* Default config values. Can be overridden globally.
*
* maxLength [int] - The maximum length of the input, textarea, or editable field
* countWords [bool] - Whether to count by word or by length
* countContainer [jQuery element | DOM selector string] - The container to display the count and message
* countDown [bool] - Whether the counter displays a remaining count or current count
* errorClass [string] - The class to apply to countContainer when an overage occurs
* countWordStr [string] - The string to use after the word length
* countLengthStr [string] - The string to use after the length
// default lightbox options
$.fn.lightweight.defaults = {
height: 260,
width: 380,
color: '#fff',
bgColor: '#000',
bgOpacity: .5,
overlayColor: '#000',
overlayOpacity: .8,
fadeSpeed: 400,
@cballou
cballou / jquery-lightweight-lightbox-plugin-example.js
Created May 16, 2016 22:28
Example usage of the jQuery Lightweight Lightbox Plugin
// open the target element with ID "targetElement" (assumes it's already hidden by end user via style="display:none")
$('#targetElement').lightweight({
height: 400,
width: 400
});
// to manually close the lightbox
$('#targetElement').lightweight('close');
// an example of binding a button to close the lightbox
@cballou
cballou / wp-install.sh
Last active November 5, 2018 19:40
Handle a near auto-installation of Wordpress on Ubuntu 14.04.
#!/bin/bash
# MySQL database defaults
dbname="wordpress"
dbuser="wordpress"
# Gather user info
read -r -p "Enter your domain, e.g. mywebsite.co (no http://, no www.): " wpURL
read -r -p "Enter a secure MySQL root password to use (save this somewhere): " rootpass
read -r -p "Enter a secure MySQL WordPress password to use: " userpass
@cballou
cballou / pingdom-probe-servers.sh
Created October 6, 2015 20:44
A very simple script I found online for getting a newline delimited list of the Pingdom probe server IP addresses. Great if you need to whitelist them.
#!/bin/bash
# one liner to get all Pingdom probe server IP addresses
wget --quiet -O- https://www.pingdom.com/rss/probe_servers.xml | perl -nle 'print $1 if /IP: (([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5]));/'
@cballou
cballou / stripe-proration.php
Last active March 10, 2023 01:40
Calculate a proration percentage given the current timestamp and a current billing period
<?php
/**
* Handle calculating a percentage/fraction (proration) we should charge the
* user for based on the current day of the month before their next bill cycle.
* To use yourself, implement a getSubscription method which returns an object
* containing current_period_start and current_period_end DateTime objects.
*
* @access public
* @return float
@cballou
cballou / medusa.sh
Created December 17, 2013 17:10
Bash script to output recent activity in /var/log/auth.log which may be useful for finding nefarious users.
#!/bin/bash
#####################################################
# To run, simply: chmod +x medusa.sh && ./medusa.sh #
#####################################################
# Successful publickey connections
echo '==== Successful SSH Public Key Connections ===='
CONNECTIONS=`grep "sshd.*Accepted publickey" /var/log/auth.log`
while read -r line; do
@cballou
cballou / jquery-fix-json-hijacking-prevention-response.js
Last active May 22, 2017 15:26
Properly handle removal of JSON Hijacking prevention method responses with jQuery.
$.ajaxSetup({
dataFilter: function(data, type) {
var prefixes = ['//', 'while(true);', 'for(;;);'],
i,
l,,
pos;
if (type != 'json' && type != 'jsonp') {
return data;
}
@cballou
cballou / customize-default-error-handler.css
Created December 3, 2012 13:58
Salid - The Simple jQuery Form Validator
/* the DIV container */
#salid_wrapper { }
/* the anchor link to close the lightbox */
#salid_wrapper #salid_close { }
#salid_wrapper #salid_close:hover { }
/* the content block containing the unordered list of errors */
#salid_wrapper .salid_content { }