Skip to content

Instantly share code, notes, and snippets.

@DaveChild
DaveChild / readable.py
Created May 24, 2018 15:24 — forked from lightstrike/readable.py
Readable.io API Python Wrapper
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 14:26
Readable.io API Example Code - VB.NET
'=====================================================================
' 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 November 23, 2011 10:45
PHP Function to Validate EANs
<?php
/*
0346745008178
Should fail - checksum should be 9
5060096384137
Should pass
5020650002112
@DaveChild
DaveChild / Querystrings.php
Created December 3, 2010 14:22
Add and remove querystring variables from URLs.
<?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 December 3, 2010 14:15
PHP SoftHyphens Function
<?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 July 24, 2009 11:33
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
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 July 24, 2009 11:31
Generate a URL portion or alias from any text - uses alphanumeric characters and hyphens only.
<?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 July 24, 2009 11:27
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).
<?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 July 24, 2009 11:24
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
function viewSource() {
var httpRequest;
try {
httpRequest = new XMLHttpRequest();
}catch(trymicrosoft) {
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch(oldermicrosoft) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");