Skip to content

Instantly share code, notes, and snippets.

View dave1010's full-sized avatar

Dave Hulbert dave1010

View GitHub Profile
@dave1010
dave1010 / Tasker-launch-chatGPT-voice.xml
Created November 30, 2023 22:33
Tasker-launch-chatGPT-voice.xml
<TaskerData sr="" dvi="1" tv="6.1.32">
<Task sr="task4">
<cdate>1701381152290</cdate>
<edate>1701383416926</edate>
<id>4</id>
<nme>ChatGPT Voice</nme>
<pri>100</pri>
<Action sr="act0" ve="7">
<code>25</code>
<Int sr="arg0" val="0"/>
@dave1010
dave1010 / get-localities-from-osm.php
Created January 8, 2024 12:53
Get localities from OSM
<?php
// API details: https://wiki.openstreetmap.org/wiki/Overpass_API
// Define your bounding box [south latitude, west longitude, north latitude, east longitude]
$bbox = array(51.28, -0.489, 55.81, 1.76); // Example bounding box around London
// Construct the Overpass query
$query = "[out:json];(node[\"place\"=\"city\"](".implode(',', $bbox).");node[\"place\"=\"town\"](".implode(',', $bbox)."););out;";
@dave1010
dave1010 / gptv
Created November 22, 2023 16:59
GPT-Vision Command line script
#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 '<prompt>' '<image_url>'"
exit 1
fi
PROMPT=$1
IMAGE_URL=$2
@dave1010
dave1010 / strip_word_html.php
Created November 12, 2010 13:14
Strip MS Word HTML. From php.net
<?php
function strip_word_html($text, $allowed_tags = '<b><i><sup><sub><em><strong><u><br>')
{
mb_regex_encoding('UTF-8');
//replace MS special characters first
$search = array('/&lsquo;/u', '/&rsquo;/u', '/&ldquo;/u', '/&rdquo;/u', '/&mdash;/u');
$replace = array('\'', '\'', '"', '"', '-');
$text = preg_replace($search, $replace, $text);
//make sure _all_ html entities are converted to the plain ascii equivalents - it appears
//in some MS headers, some html entities are encoded and some aren't
@dave1010
dave1010 / php-regex-router.php
Created September 13, 2011 15:46
php-regex-router.php
<?php
// dangerously simple PHP regular expression URL router
// requires a mod_rewrite like "RewriteRule . /index.php [L]"
function get($url, $callback) {
$matches = array();
if (preg_match('~' . $url . '~', $_SERVER['REQUEST_URI'], $matches)) {
echo call_user_func_array($callback, $matches);
die();
}
@dave1010
dave1010 / pre-commit
Created October 28, 2011 12:31
pre-commit PHP link and check for merge conflicts
#!/bin/bash
conflicts=`git diff --cached --name-only -S'<<<<<<'`
for i in `git diff --cached --name-only | grep '.php'`;
do
thisphperror=`php -l $i | grep -v 'No syntax errors detected in'`
if [ -n "$thisphperror" ]; then
echo "PHP errors added in file: " $i
@dave1010
dave1010 / htaccess
Created December 14, 2011 13:07
HTTP Status Cats Apache (htaccess) config
# HTTP Status Cats
# Apache (htaccess) config created by @dave1010
# Licensed CC BY 2.0
# Images CC BY 2.0, from GirlieMac's photostream:
# http://www.flickr.com/photos/girliemac/sets/72157628409467125/with/6508023065/
# Usage: copy save this file as .htaccess or add it to your httpd.conf
ErrorDocument 404 '<a href="http://www.flickr.com/photos/girliemac/6508022985/" title="404 - Not Found by GirlieMac, on Flickr"><img src="http://farm8.staticflickr.com/7172/6508022985_b22200ced0.jpg" width="500" height="400" alt="404 - Not Found"></a>'
@dave1010
dave1010 / notify-apache-errors.sh
Created November 30, 2010 17:31
notify-apache-errors.sh
#!/bin/bash
# use ubuntu's notification system to let us know when there's something new in the apache error log
tail -n0 -f /var/log/apache2/error.log | while read line
do
body=`echo $line | cut -f 9- -d ' '`
notify-send -c im.received -i error "Apache / PHP error" "$body"
done
@dave1010
dave1010 / de-resolve-symlinks.php
Created November 5, 2013 14:23
De-resolve symlinks from PHP's __FILE__
@dave1010
dave1010 / to-string.php
Created June 10, 2011 15:02
How to throw exceptions in a PHP class' __toString method
<?php
class MyClass {
public function __toString() {
try {
return $this->render();
} catch(Exception $e) {
// the __toString method isn't allowed to throw exceptions
// so we turn them into an error instead
trigger_error($e->getMessage() . "\n" . $e->getTraceAsString(), E_USER_ERROR);