Skip to content

Instantly share code, notes, and snippets.

View timkinnane's full-sized avatar

Tim Kinnane timkinnane

View GitHub Profile
@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 / functions.php
Last active August 29, 2015 14:14 — forked from MikeNGarrett/wp-3-8-replace-open-sans
Replace WP dashboard and admin bar font with your own (optional) locally hosted font. NOTE: I've used Roboto to match my theme, but called it Open Sans. This prevents error for admin plugin dependencies that expect an Open Sans style to be registered. WHY: If I'm doing local development offline page loads were always delayed by the Google Fonts …
<?php
// Reregister Open-sans as Roboto.
function replace_open_sans() {
// Replace the URL with your local or remote css
$roboto_open_sans_url = get_template_directory_uri().'/assets/fonts/roboto-hack.css';
wp_deregister_style( 'open-sans' );
wp_register_style( 'open-sans', $roboto_open_sans_url );
}
add_action( 'admin_enqueue_scripts', 'replace_open_sans' );
@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 / 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 / wp_update_url.sql
Created April 7, 2013 23:36
Wordpress, find and replace url in database.
UPDATE wp_options SET option_value = REPLACE (option_value, 'http://oldurl','http://newurl');
UPDATE wp_posts SET guid = REPLACE (guid,'http://orldurl','http://newurl');
# Change "wp_" to your database's table prefix
# Change oldurl, newurl (oldurl is the one in the database already)
@timkinnane
timkinnane / wp_install.sh
Created April 7, 2013 23:36
Wordpress, install via ssh
# First connect to host via SSH - cd to public_html or httpdocs
# Download latest WP to host (zip or tar.gz)
wget http://wordpress.org/latest.tar.gz
# Extract it
tar xzvf latest.tar.gz
# Move it out of 'wordpress' directory
mv wordpress/* ~/public_html