Skip to content

Instantly share code, notes, and snippets.

View tomnomnom's full-sized avatar
☺️
Taking it easy

Tom Hudson tomnomnom

☺️
Taking it easy
View GitHub Profile
@tomnomnom
tomnomnom / chanscan.go
Created May 28, 2016 22:42
Using Go's channels to spread work across a bunch of worker goroutines
package main
import (
"fmt"
"net"
"sync"
"time"
)
const (
@tomnomnom
tomnomnom / find-bt-address-id.php
Created December 9, 2013 17:03
Hacky script for finding BT Address IDs
<?php
const HOUSE_NUMBER = 2;
const POSTCODE = 'LS1 4AP';
const SERVICE_URL = 'http://www.productsandservices.bt.com/consumerProducts/v1/addressSearch.do';
$query = http_build_query(array(
'postcode' => POSTCODE,
@tomnomnom
tomnomnom / fttc-check.php
Last active December 30, 2015 19:29
Hacky FTTC Check Script
<?php
// Change me
const ADDRESS_ID = 'Gold|StringOfAlphas|MY|HouseNumber'; // You can find your Address ID using this: https://gist.github.com/TomNomNom/7875919
const TO_EMAIL = 'me@example.com';
const FROM_EMAIL = 'server@example.com';
// Don't change me
const SERVICE_URL = 'http://www.productsandservices.bt.com/consumerProducts/v1/productAvailability.do';
@tomnomnom
tomnomnom / bouncy.html
Created December 27, 2015 20:34
Bouncy Ball
<html>
<head>
<style>
canvas {
border: 1px solid #666666;
}
</style>
</head>
<body>
<?php
class SayDate extends DateTime {
public function say(){
$now = new DateTime();
$now->setTime(0, 0, 0);
$interval = (int) $now->diff($this)->format('%r%a');
if ($interval < 0){
return $this->format('Y-m-d');
@tomnomnom
tomnomnom / zend_hash_rehash_annotated.c
Created April 2, 2013 16:13
Annotated version of zend_hash_rehash
ZEND_API int zend_hash_rehash(HashTable *ht)
{
Bucket *p;
uint nIndex;
IS_CONSISTENT(ht);
if (UNEXPECTED(ht->nNumOfElements == 0)) {
return SUCCESS;
}
@tomnomnom
tomnomnom / sorted-array-access.php
Last active December 15, 2015 16:49
It seems that when using sort() (i.e. the keys are re-assigned), array access slows down; but with asort() (i.e. the keys are not re-assigned) access speed is not affected.
<?php
const INT_COUNT = 1000000;
// Fill an array with random ints
$ints = [];
for ($i = 0; $i < INT_COUNT; $i++){
$ints[] = rand(0, 255);
}
// Sort the ints
@tomnomnom
tomnomnom / spec-1.2.7.json
Created February 19, 2013 14:15
Example Etherpad Lite API spec file
{
"version": "1.2.7",
"methods": [
{
"name": "createGroup",
"httpMethod": "POST",
"arguments": [
]
},
@tomnomnom
tomnomnom / tweet-fetch.php
Last active December 11, 2015 06:08
A quick and dirty way to get recent tweets
#!/usr/bin/env php
<?php
date_default_timezone_set('GMT');
$params = array(
"screen_name" => "tomnomnom",
"include_rts" => "true"
);
if (!file_exists('last-id')){
touch('last-id');
@tomnomnom
tomnomnom / cv-server.go
Created January 5, 2013 18:53
POC Go web server for online CV
package main
import (
"net/http"
"html/template"
"runtime"
"os"
"os/signal"
"syscall"
"log"