Skip to content

Instantly share code, notes, and snippets.

Alex King alexkingorg

Block or report user

Report or block alexkingorg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@alexkingorg
alexkingorg / jquery-disable-button-after-submit.js
Last active Oct 10, 2017
After form submit, disable submit button.
View jquery-disable-button-after-submit.js
jQuery(function($) {
// set data-after-submit-value on input:submit to disable button after submit
$(document).on('submit', 'form', function() {
var $form = $(this),
$button,
label;
$form.find(':submit').each(function() {
$button = $(this);
label = $button.data('after-submit-value');
if (typeof label != 'undefined') {
@alexkingorg
alexkingorg / laravel-5-mail-example.php
Last active Aug 18, 2016
Sane Laravel Mail example code
View laravel-5-mail-example.php
<?php
// note, to use $subject within your closure below you have to pass it along in the "use (...)" clause.
$subject = 'Welcome!';
Mail::send('emails.welcome', ['key' => 'value'], function($message) use ($subject) {
// note: if you don't set this, it will use the defaults from config/mail.php
$message->from('bar@example.com', 'Sender Name');
$message->to('foo@example.com', 'John Smith')
->subject($subject);
@alexkingorg
alexkingorg / isp-uptime.sh
Last active Aug 29, 2015
Script to check the uptime of my ISP - I run this from a CRON job on a local box.
View isp-uptime.sh
#!/bin/bash
# try 3 times - sometimes getting an initial DNS failure that clears up
COUNTER=0
while [ $COUNTER -lt 3 ]; do
ping -c 1 google.com &> /dev/null
if [ $? -ne 0 ]; then
echo "`date`: ping failed, isp is down!" >> /Users/aking/Dropbox/Temp/isp-ping-result.log
echo "`date`: ping failed, isp is down!" >> /Users/aking/Dropbox/Temp/isp-downtime.log
@alexkingorg
alexkingorg / jquery-textarea-form-submit-cmd-enter.js
Last active Jun 23, 2018
Submit a form on Command+Enter when in a textarea field.
View jquery-textarea-form-submit-cmd-enter.js
jQuery(function($) {
// add a handler for form submit (makes an AJAX call)
$(document).on('submit', 'form.my-class', myFormSubmitHandler);
// submit form on command + enter if in a textarea
$(document).on('keydown', 'body', function(e) {
if (!(e.keyCode == 13 && e.metaKey)) return;
var $target = $(e.target);
if ($target.is('textarea')) {
View gist:e8c5f5abad59f96eb837
// readable and easily re-orderable
$(document).on('submit', '#foo', myCallback1);
$(document).on('submit', '#bar', myCallback2);
$(document).on('click', '.baz', myCallback3);
// performant
$(document).on('submit', '#foo', myCallback1)
.on('submit', '#bar', myCallback2)
@alexkingorg
alexkingorg / .gitconfig
Created Jul 22, 2014
.gitconfig alias for recursively updating submodules
View .gitconfig
[alias]
subup = "!f() { git submodule sync; git submodule update --init --recursive; }; f"
@alexkingorg
alexkingorg / gist:11220299
Created Apr 23, 2014
RAMP Session Token Debugging
View gist:11220299
In classes/deploy.class.php find this code on or around line 426:
<p>'.__('The batch session token does not match.', 'cf-deploy').'</p>
Replace that with:
<p>'.sprintf(__('The batch session token does not match. Expected "%s", received "%s"', 'cf-deploy'), esc_html($session_token), esc_html($args['batch_session_token'])).'</p>
This will show you the expected and received tokens.
@alexkingorg
alexkingorg / wp-post-content-tweet.php
Created Feb 9, 2014
Replace post content with tweet URL using Twitter Tools data.
View wp-post-content-tweet.php
<?php
function aktt_replace_tweet_content($posts) {
foreach ($posts as $post) {
if ($post->post_type == AKTT::$post_type && !empty($post->tweet)) {
$post->post_content = esc_url(AKTT::status_url($post->tweet->username(), $post->tweet->id()));
}
}
}
add_action('the_posts', 'aktt_replace_tweet_content', 11);
@alexkingorg
alexkingorg / google-spreadsheet-colors.js
Created Feb 7, 2014
Google Spreadsheet coloring code
View google-spreadsheet-colors.js
function onEdit(e) {
setColors();
};
function setColors() {
var activeSheet = SpreadsheetApp.getActiveSheet();
var numRows = activeSheet.getMaxRows();
var numCols = activeSheet.getMaxColumns();
var row, cell, value;
@alexkingorg
alexkingorg / cf-favorites.php
Created Feb 6, 2014
Some starter WordPress code for saving pages/posts as favorite.
View cf-favorites.php
<?php
/*
Plugin Name: Favorites
Plugin URI:
Description: Let users save posts/pages as favorites - then access them through a quick menu.
Version: 1.0
Author: Crowd Favorite
Author URI: http://crowdfavorite.com
*/
You can’t perform that action at this time.