Skip to content

Instantly share code, notes, and snippets.

View newbold's full-sized avatar

Adam Newbold newbold

View GitHub Profile
@newbold
newbold / nice_list.php
Created August 13, 2020 06:42
This function turns an array into a nice list, with list items wrapped in custom strings, separated with commas, with "and" before the final item.
<?php
function nice_list($items, $wrapper = false) {
if($wrapper) {
$wrapper = str_split($wrapper, strlen($wrapper) / 2);
foreach($items as &$item) {
$item = $wrapper[0].$item.$wrapper[1];
}
}
if(count($items) == 1) return $items[0];
@newbold
newbold / nice_list.php
Created August 13, 2020 06:41
This function turns an array into a nice list, separated with commas, with "and" before the final item.
<?php
function nice_list($items) {
if(count($items) == 1) return $items[0];
if(count($items) == 2) return $items[0].' and '.$items[1];
$last = array_pop($items);
array_push($items, 'and '.$last);
return implode(', ', $items);
}
@newbold
newbold / keybase-bot.php
Last active December 5, 2019 23:58
Keybase bot in PHP
<?php
// launch with:
// $ keybase chat api-listen --filter-channels '[{"name":"channel_name", "topic_name": "channel_name", "members_type": "team"}]' | php -f keybase.php
define('KEYBASE_TEAM', 'team_name');
define('KEYBASE_CHANNEL', 'channel_name');
if(!defined('BOT_NAME')) {
$keybase_status = `keybase status --json`;
server:80 117.51.146.97 - - [01/Dec/2019:02:17:40 -0500] "GET / HTTP/1.1" 302 449 "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"
server:80 117.51.146.97 - - [01/Dec/2019:02:17:41 -0500] "GET /robots.txt HTTP/1.1" 302 468 "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"
server:80 117.51.146.97 - - [01/Dec/2019:02:17:41 -0500] "POST /Admin624dc58a/Login.php HTTP/1.1" 302 494 "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"
server:80 117.51.146.97 - - [01/Dec/2019:02:17:42 -0500] "GET / HTTP/1.1" 302 448 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:28.0) Gecko/20100101 Firefox/28.0"
server:80 117.51.146.97 - - [01/Dec/2019:02:17:45 -0500] "GET /l.php HTTP/1.1" 302 458 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:28.0) Gecko/20100101 Firefox/28.0"
server:80 117.51.146.97 - - [01/Dec/2019:02:17:45 -0500] "GET /phpinfo.php HTTP/1.1
@newbold
newbold / watson-web-chat-custom-context.html
Created September 20, 2019 04:01
Sample Watson Assistant Web Chat with custom context variable
<!DOCTYPE html>
<body>
<script src="https://assistant-web.watsonplatform.net/loadWatsonAssistantChat.js"></script>
<script>
function preSendhandler(event) {
event.data.context = event.data.context || {};
event.data.context.skills = event.data.context.skills || {};
event.data.context.skills['main skill'] = event.data.context.skills.main_skill || {};
event.data.context.skills['main skill'].user_defined = event.data.context.skills['main skill'].user_defined || {};
event.data.context.skills['main skill'].user_defined.username = 'User';
@newbold
newbold / watson-visual-recognition-twilio-sample.php
Created May 22, 2019 17:33
Simple Watson Visual Recognition implementation with Twilio MMS in PHP. Twilio will POST an image URL through via MediaUrl0, so it's easy to grab that and send it on to Watson for recognition.
if(isset($_REQUEST['MediaUrl0'])) {
$img = $_REQUEST['MediaUrl0'];
$apikey = 'put_a_real_key_here';
$data = `curl -u "apikey:$apikey" "https://gateway.watsonplatform.net/visual-recognition/api/v3/classify?url=$img&version=2018-03-19"`;
$data = json_decode($data);
$thing = $data->images[0]->classifiers[0]->classes[0]->class;
$intros = array('Hey', 'Cool', 'Jeepers', 'Wow', 'Awesome', 'Nifty', 'Woah', 'Yikes', 'Well', 'Eh', 'Um', 'Uh', 'Zoinks');
/*
Copyright 2019 Adam Newbold <adam@neatnik.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@newbold
newbold / keymap.c
Created February 9, 2019 06:03
50% Numpad (QMK)
#include "launchpad.h"
#include "action_layer.h"
#include "eeconfig.h"
extern keymap_config_t keymap_config;
#define _QWERTY 0
#define _FUNC 15
#define _______ KC_TRNS
#define XXXXXXX KC_NO
@newbold
newbold / apache_php_macos_10.14_mojave.md
Created October 13, 2018 19:03
Simple guide to Apache + PHP on macOS 10.14 Mojave