Skip to content

Instantly share code, notes, and snippets.

View timkinnane's full-sized avatar

Tim Kinnane timkinnane

View GitHub Profile
@timkinnane
timkinnane / move_db.sh
Created June 21, 2013 01:09
SSH, export and move MySQL database to remote host
mkdir -p db_export_tmp
mysqldump --add-drop-table -efK -u DB_USER -pPASS DB_NAME > tmp/DB_NAME.sql
mysql -h host -u DB_USER -pPASS DB_NAME < tmp/DB_NAME.sql
rm -rf db_export_tmp
@timkinnane
timkinnane / Remove old uploads.sh
Last active December 22, 2015 04:48
Remove old uploads in gravity forms. e.g. Schedule as cron job after backups.
# find uploads > not web files > files only > older than 6 months
find ~/public_html/wp-content/uploads/gravity_forms/* -not -name "*.html" -not -name "*.php" -type f -mtime +182
# Find > delete
find ~/public_html/wp-content/uploads/gravity_forms/* -not -name "*.html" -not -name "*.php" -type f -mtime +182 -exec rm {} \;
@timkinnane
timkinnane / date_range_regex.php
Created April 7, 2013 23:37
Generate date range regex, PHP.
function get_daterange_regex( $from, $to, $input_format ) {
// get the difference in months
$date1 = DateTime::createFromFormat( $from, $input_format );
$date2 = DateTime::createFromFormat( $to, $input_format );
$interval = $date1->diff($date2);
$months = $interval->m;
// get an array of the interveening months
$all_months = array();
@timkinnane
timkinnane / wpadmin_data_table.js
Last active January 25, 2017 10:36
dataTable takes an array of key/value objects and return table of elements. e.g from parsed JSON. Requires jQuery. Widefat class is used for Wordpress admin pages, but its not a WP specific function.
jQuery(document).ready(function($) {
function dataTable(data) {
var response_table = $('<table class="widefat"></table>');
var header = $('<thead><tr></tr></thead>');
for(var k in data[0]) {
header.append('<th>'+k+'</th>');
}
response_table.append(header);
@timkinnane
timkinnane / blockstack_verification.txt
Created January 18, 2018 02:51
Blockstack verification
Verifying my Blockstack ID is secured with the address 1Htvmm5DbsDJCSSRuHByX4YJbEkGHtpTY7 https://explorer.blockstack.org/address/1Htvmm5DbsDJCSSRuHByX4YJbEkGHtpTY7
@timkinnane
timkinnane / shortcode.php
Created April 7, 2013 23:36
Wordpress shortcode example
<?php
// MyShortcode usage [myshortcode greeting="Hello" who="World"]
function myshortcode_func( $atts, $content = null ) {
// use given attributes or defined defaults
extract( shortcode_atts( array(
'greeting' => '',
'who' => ''
), $atts ) );
@timkinnane
timkinnane / clientcommands.md
Last active June 26, 2018 00:28 — forked from mikaelmello/clientcommands.md
Client Commands

I'd like to introduce a new utility called Client Commands, a solution created to allow the Rocket.Chat server to trigger actions in subscriber clients (bots and possibly other websocket clients). This is handled at the adapter and/or SDK level, not by final users (e.g. normal bot developers).

The problem

Bots subscribe to a message stream and respond to message events, but there's no way for the server to prompt them to do anything other than that.

In order to provide a range of new management features for administrating bot clients, getting data or triggering any non message response action, we need to send data to be interpreted by the client as a command. Such data, identified here by ClientCommands, could not be sent through the normal message stream, because:

  • a) it would go to everyone, not just bot clients
  • b) it would need hack workarounds to filter commands from normal message data
  • c) it would be kept forever, bloating message collection storage
@timkinnane
timkinnane / dynamic_image_downsize.php
Created February 2, 2015 08:49
Filter the output of image_downsize() to return dynamically generated images for intermediate or inline sizes. Long description in php doc block.
<?php
/**
* Filter the output of image_downsize() to return dynamically generated images for intermediate or inline sizes.
*
* <p>Because Wordpress generates all image sizes on first upload, if you change
* theme or size settings after the upload, there won't be a matching file for
* the requested size.<br/>
* This filter addresses the problem of the default downsize process laoding
* a large file and scaling it down in the browser if it doesn't find the right
* size image. This can cause large files to be loaded unnecessarily and will
@timkinnane
timkinnane / construct.ts
Created March 16, 2022 05:23
AWS CDK SSM: A construct for accessing SSM values from a stack as Cloud Formation tokens to resolve on deploy.
import { Construct } from 'constructs'
import { aws_ssm as SSM } from 'aws-cdk-lib'
/**
* Create a resource for accessing SSM values (as Cloud Formation tokens to resolve on deploy).
*/
export class ParamsConstruct extends Construct {
private configPath: string
private secretPath?: string