Skip to content

Instantly share code, notes, and snippets.

Avatar

Dave Child DaveChild

View GitHub Profile
@DaveChild
DaveChild / readable.py
Created May 24, 2018 — forked from lightstrike/readable.py
Readable.io API Python Wrapper
View readable.py
import hashlib
import time
import requests
class ReadableAPIClient:
"""
API Client for Readable.io, written for Python 3
See API documentation: https://readable.io/api/docs/
@DaveChild
DaveChild / ReadableApi.vb
Created May 24, 2018
Readable.io API Example Code - VB.NET
View ReadableApi.vb
'=====================================================================
' Readable.io REST Post Test
' --------------------------
' Basic asp.net (VB.Net) 4 page with textbox, label and submit button
' Created: 25 May 2018
' Author: humanotics.co.uk
'=====================================================================
Imports System.Net
Imports System.Security.Cryptography
@DaveChild
DaveChild / ean_check.php
Created Nov 23, 2011
PHP Function to Validate EANs
View ean_check.php
<?php
/*
0346745008178
Should fail - checksum should be 9
5060096384137
Should pass
5020650002112
@DaveChild
DaveChild / Querystrings.php
Created Dec 3, 2010
Add and remove querystring variables from URLs.
View Querystrings.php
<?php
/*
Add and remove querystring variables from URLs.
*/
function addQuerystringVar($url, $key, $value) {
$url = preg_replace('/(.*)(\?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
$url = substr($url, 0, -1);
if (strpos($url, '?') === false) {
return ($url . '?' . $key . '=' . $value);
} else {
@DaveChild
DaveChild / SoftHyphens.php
Created Dec 3, 2010
PHP SoftHyphens Function
View SoftHyphens.php
<?php
/*
This function will add soft hyphens after every 3rd character in words of over 10 characters.
*/
public static function SoftHyphens($text) {
$return = '';
// Add spaces around HTML tag delimiters, to process them as individual words (to be removed later)
$text = str_replace('>', '> ', $text);
$text = str_replace('<', ' <', $text);
@DaveChild
DaveChild / gist:154029
Created Jul 24, 2009
Redirect all GET and HEAD requests to new domain (only redirecting GET and HEAD because POST, PUT, DELETE etc to old domain is almost certainly automated spam - no genuine users should ever be posting to old domain if it's been completely redirected). Ser
View gist:154029
RewriteCond %{REQUEST_METHOD} ^(GET|HEAD) [NC] # Only rewrite GET requests
RewriteCond %{HTTP_HOST} olddomain\.com [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} olddomain\.com [NC] # Otherwise block
RewriteRule ^(.*)$ - [F]
@DaveChild
DaveChild / gist:154025
Created Jul 24, 2009
Generate a URL portion or alias from any text - uses alphanumeric characters and hyphens only.
View gist:154025
<?php
function generate_url_from_text($strText) {
$strText = preg_replace('/[^A-Za-z0-9-]/', ' ', $strText);
$strText = preg_replace('/ +/', ' ', $strText);
$strText = trim($strText);
$strText = str_replace(' ', '-', $strText);
$strText = preg_replace('/-+/', '-', $strText);
$strText = strtolower($strText);
return $strText;
@DaveChild
DaveChild / gist:154015
Created Jul 24, 2009
Code will trim a string to a maximum length, and will not break sentences (will grab as many sentences from text as it can up to the maximum string length).
View gist:154015
<?php
function trim_text_in_sentences($intLength, $strText) {
$intLastPeriodPos = strpos(strrev(substr($strText, 0, $intLength)), '.');
if ($intLastPeriodPos === false) {
$strReturn = substr($strText, 0, $intLength);
} else {
$strReturn = substr($strText, 0, ($intLength - $intLastPeriodPos));
}
return $strReturn;
@DaveChild
DaveChild / View Page Source.js
Created Jul 24, 2009
JavaScript function that will fetch the source of the page being viewed. Based, I think, on http://www.astral-consultancy.co.uk/cgi-bin/hunbug/doco.cgi?11340
View View Page Source.js
function viewSource() {
var httpRequest;
try {
httpRequest = new XMLHttpRequest();
}catch(trymicrosoft) {
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch(oldermicrosoft) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");