Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jamescridland's full-sized avatar

James Cridland jamescridland

View GitHub Profile
@jamescridland
jamescridland / indefinite_article.php
Created February 21, 2011 23:01 — forked from samstarling/indefinite_article.php
A little bit of PHP to return "a" and "an" correctly.
<?
// Usage:
echo "I have ".return_indefinitearticle("apple")." apple, and ".return_indefinitearticle("slice of bread")." slice of bread.";
function return_indefinitearticle($thing) {
return (preg_match('/^[aeiou]|s\z/i', strtolower($thing))) ? "an" : "a";
}
?>
@jamescridland
jamescridland / Amazon S3 expiry date
Created March 24, 2011 00:27
Here's what to set a good expiry date for Amazon S3 to...
Sun, 17 Jan 2038 14:26:09 GMT
@jamescridland
jamescridland / gist:1008014
Created June 4, 2011 16:01
Extracting phpBB private messages
/* 1. Search in discussions_users for user, and remember their ID and email. */
/* Here's the SQL query... */
SELECT username AS from_user, FROM_UNIXTIME(`privmsgs_date`) AS sent, privmsgs_subject, privmsgs_text FROM `discussions_privmsgs` LEFT JOIN discussions_privmsgs_text on privmsgs_id=privmsgs_text_id LEFT JOIN discussions_users ON privmsgs_from_userid=user_id WHERE `privmsgs_to_userid` = 28861
/*... export this as PDF, then send it to user's ID.*/
/* posts are */
SELECT topic_title,post_subject,post_text,post_time FROM `discussions_posts` JOIN discussions_posts_text ON discussions_posts.post_id = discussions_posts_text.post_id JOIN discussions_topics ON discussions_topics.topic_id=discussions_posts.topic_id WHERE `poster_id` = 18852
@jamescridland
jamescridland / stopit
Created April 9, 2012 17:44
Stop people nicking .png images from your server
#put this bit in your .htaccess file
RewriteCond %{HTTP_REFERER} ^http://(www\.)?godalmingtownfc.co.uk.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?mallulive.com.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?allegro.pl.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?lawiki.org.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?pcworld.com.*$ [NC]
ReWriteRule .*\.png$ - [F]
@jamescridland
jamescridland / extract_info_from_googleplus.php
Last active December 29, 2015 07:59
This will scrape information from a Google+ page, if given a URL. The "followers" uses a class that doubtless will change; but you can hopefully see how it works.
<?
$url['url']='https://plus.google.com/107170242245169064947/posts';
if (isset($url['url'])) {
$d = new DOMDocument();
@$d->loadHTML(file_get_contents($url['url']));
$xpath = new DOMXPath($d);
@jamescridland
jamescridland / gist:a0783283b90550046f87
Created September 15, 2015 18:10
The easiest EU cookie solution code ever?
<!--
Put this just under your <HEAD> in HTML.
Note - it displays once, and once only.
It requires you to run Google Analytics on your website.
If a user deletes their cookies, it'll appear again.
You can test it by going into Incognito Mode.
-->
<script type='text/javascript'>
@jamescridland
jamescridland / private.xml
Last active September 14, 2016 06:37
Disable the bottom two buttons on a Logitech Presenter R700. Part of a piece at https://medium.com/@JamesCridland/disabling-logitech-r800-remote-buttons-for-keynote-5412c5ef2e88#.jkcf8n4t2
<?xml version="1.0"?>
<root>
<devicevendordef>
<vendorname>LOGITECH</vendorname>
<vendorid>0x046d</vendorid>
</devicevendordef>
<deviceproductdef>
<productname>LOGITECH_R800</productname>
<productid>0xc538</productid>
@jamescridland
jamescridland / ofcom.php
Created October 16, 2016 06:49
A quick check to see if Ofcom's txparams have updated themselves
<?php
// A small piece of code to check the Last-Modified header in PHP
// The below currently (on 16 October) returns:
// "Tue, 11 Oct 2016 11:26:59"
// ... so that's when it was last updated.
// I'm told that this URL is a permanent link. My assumption is that any update to the
// DAB, FM or AM data will produce an update for this main file; even though my own code
// actually just uses the .csv files.
$re = '/[\*].*(gimlet)(.+?\n\n)/';
$str = '* Google Play Music have [buttons for your podcasts](https://play.google.com/intl/en_us/badges-music/). Note, however, that outside the US, they just redirect to the front page of Google Play. One step forward, one step back.
* Recommended: [ReplyAll investigates Facebook](https://gimletmedia.com/episode/109-facebook-spying/) using your phone\'s microphone to spy on your conversations. And, how to stop them doing it, even though they\'re not.
* Event: on now in Austin TX, USA: [Media Tech Week](https://mediatechweek.live/)';
preg_match($re, $str, $matches);
var_dump($matches);
@jamescridland
jamescridland / reports.php
Last active January 18, 2023 02:23
An additional API for Sendy, that offers a report for a specific sent campaign
<?php include('../_connect.php');?>
<?php include('../../includes/helpers/short.php');?>
<?php
/*
---Little helper function from james@crid.land for reporting
Put this file in a new folder within the /api/ folder, called "reporting", and call it "reports.php". (Or whatever you like).
Call by POST to api/reporting/reports.php with the following mandatory elements
'api_key' => (your API key)