Skip to content

Instantly share code, notes, and snippets.

🤖
Making bots.

Tim Kinnane timkinnane

🤖
Making bots.
Block or report user

Report or block timkinnane

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
View clientcommands.md

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
View blockstack_verification.txt
Verifying my Blockstack ID is secured with the address 1Htvmm5DbsDJCSSRuHByX4YJbEkGHtpTY7 https://explorer.blockstack.org/address/1Htvmm5DbsDJCSSRuHByX4YJbEkGHtpTY7
View demo.html
<div id="wrapper">
<header class="group">
<h1>Email auto-suggest</h1>
<p id="author" class="group">By Stuart Tayler</p>
<a href="https://twitter.com/share" class="twitter-share-button" data-via="stuarttayler1" data-count="none">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</header>
<p>Email address</p>
<div id="placement">
View require_image.php
add_action('save_post', 'wpds_check_thumbnail');
add_action('admin_notices', 'wpds_thumbnail_error');
function wpds_check_thumbnail($post_id) {
// change to any custom post type
if(get_post_type($post_id) != 'post')
return;
if ( !has_post_thumbnail( $post_id ) ) {
@timkinnane
timkinnane / database_table_example.php
Last active Nov 1, 2017
Take a WPDB query result and display it as a table, with headers from data keys. Creates demo menu page to show example table. #wordpress Basic example for previewing results, handy for debugging etc, but doesn't provide much validation, sorting, pagination etc.
View database_table_example.php
<?php
/**
* Take a WPDB query result and display it as a table, with headers from data keys.
* This example only works with ARRAY_A type result from $wpdb query.
* @param array $db_data Result from $wpdb query
* @return bool Success, outputs table HTML
* @author Tim Kinnane <tim@nestedcode.com>
* @link http://nestedcode.com
*/
@timkinnane
timkinnane / dynamic_image_downsize.php
Created Feb 2, 2015
Filter the output of image_downsize() to return dynamically generated images for intermediate or inline sizes. Long description in php doc block.
View dynamic_image_downsize.php
<?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 / functions.php
Last active Aug 29, 2015 — 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 …
View functions.php
<?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 / nested_custom_background_cb.php
Last active Aug 29, 2015
Apply custom background style on an element within the body. e.g. If you're using off-canvas and on-canvas containers, you may want the background only on the #canvas. It overwrites the theme support feature array value with a custom callback, but I haven't tested what happens if other key/values are defined elsewhere. There are no filters yet f…
View nested_custom_background_cb.php
function nested_custom_background_cb() {
ob_start();
_custom_background_cb();
$bg_style_tag = ob_get_contents();
ob_end_clean();
$bg_style_tag = str_replace( 'body.custom-background', 'body.custom-background #canvas', $bg_style_tag );
echo $bg_style_tag;
}
add_theme_support( 'custom-background', array( 'wp-head-callback' => 'nested_custom_background_cb' ) );
@timkinnane
timkinnane / change_passwd.sh
Last active Aug 29, 2015
Change .htpasswd setting (specifically on Digital Ocean droplets). Note This is a shell snippet but it can't be executed as is. Step 2 is manual.
View change_passwd.sh
# 1. Use htapasswd to set new pass for admin
sudo htpasswd /etc/apache2/.htpasswd admin
# 2. Update /etc/apache2/apache2.conf with folders to be protected
<DirectoryMatch ^.*/protected-folder/>
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</DirectoryMatch>
You can’t perform that action at this time.