Skip to content

Instantly share code, notes, and snippets.

Avatar

Tom Chapman chappy84

  • UK
View GitHub Profile
@chappy84
chappy84 / linode-longview-centos8.sh
Created Jun 5, 2020
Install script for Linode's Longview on CentOS 8 .... until they stop supporting it completely
View linode-longview-centos8.sh
#!/bin/sh
####################################################################################################
#
# Install Linode's LongView on CentOS 8
#
# Copyright (c) 2020, Tom Chapman (http://tom-chapman.uk)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
@chappy84
chappy84 / xbrowsersync_api_centos.sh
Last active Jul 9, 2020
Setup xBroswerSync API on a CentOS box
View xbrowsersync_api_centos.sh
#!/bin/sh
####################################################################################################
#
# Setup xBrowserSync API on CentOS
#
# Copyright (c) 2020, Tom Chapman (http://tom-chapman.uk)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
@chappy84
chappy84 / Dockerfile
Last active Feb 20, 2020
Velominati Slack Bot - Names the rule that someone is quoting in slack (Quickly hacked together script)
View Dockerfile
FROM python:2-alpine3.7
ARG slack_api_token
ENV SLACK_API_TOKEN $slack_api_token
WORKDIR /local/bot
COPY velominati-slack-bot.py ./
RUN apk update && \
@chappy84
chappy84 / packtPubDownloader.php
Last active Mar 2, 2020
Packt Pub Downloader - Quick hacky script to download all your e-books from packtpub.com. This may not always work, they may change their api calls etc.
View packtPubDownloader.php
<?php
define('DS', DIRECTORY_SEPARATOR);
// config values
$saveParentDir = __DIR__; // Parent dir of the ebooks and extras directories
$ebooksDir = 'ebooks'; // path of the ebooks directory relative to $saveParentDir
$extrasDir = 'ebooks' . DS . 'extras'; // path of the extras directory relative to $saveParentDir
$sleepDuration = 4; // Time to delay between page requests / different book downloads
$booksPerListPage = 25; // Book details to try requesting from the PacktPub API. This can be max 25
@chappy84
chappy84 / githubStarred.php
Last active Nov 20, 2016
Github Starred Dates - displays when you starred repos, which seems to have disappeared from GitHub's UI :(
View githubStarred.php
<?php
function errorAndDie($message) {
echo $message . PHP_EOL;
die(1);
}
$url = 'https://api.github.com/user/starred';
do {
@chappy84
chappy84 / convert_stravactivity_to_gpx
Last active Jun 29, 2020
Quick and dirty PHP script to convert .stravactivity file to basic gpx xml
View convert_stravactivity_to_gpx
#!/usr/bin/env php
<?php
function dateInFormat($timestamp)
{
return date('Y-m-d\TH:i:s\Z', $timestamp);
}
function latLongInFormat($reference)
{
return round((float) $reference, 6);
@chappy84
chappy84 / mysql_pivot.sql
Created Aug 31, 2014
MySQL Pivot Stored Procedure
View mysql_pivot.sql
DROP PROCEDURE IF EXISTS pivot_user_preferences;
DELIMITER $$
CREATE PROCEDURE pivot_user_preferences(IN user_id INT)
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE definition_label CHAR(255);
DECLARE label_cursor CURSOR FOR SELECT DISTINCT label FROM example_db.user_preferences;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
@chappy84
chappy84 / multiple_query_deugger.php
Last active Aug 29, 2015
PHP PDO Mysql Multiple Query Bug Debugger. Bug Page: https://bugs.php.net/bug.php?id=61613
View multiple_query_deugger.php
<?php
$myConn = new PDO(
'mysql:host=localhost;dbname=dbname',
'username',
'password'
);
$myConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$multiSqlStatement = '
INSERT INTO users (username) VALUES (:username);
@chappy84
chappy84 / cloudflare_dyn_dns.sh
Last active May 11, 2020
CloudFlare Dynamic DNS Shell Script
View cloudflare_dyn_dns.sh
#!/bin/sh
#
# CloudFlare Dynamic DNS
#
# Updates CloudFlare records with the current public IP address
#
# Takes the same basic arguments as A/CNAME updates in the CloudFlare v4 API
# https://www.cloudflare.com/docs/client-api.html#s5.2
#
# Use with cron jobs etc.
@chappy84
chappy84 / date_iso.php
Last active Dec 11, 2015
Format a local time/date using an ISO Format
View date_iso.php
<?php
function date_iso($format, $timestamp = null)
{
if ($timestamp === null) {
$timestamp = time();
}
$convert = array(
'a' => 'A' , 'B' => 'B', 'D' => 'z', 'ddd' => 't', 'dd' => 'd', 'd' => 'j',
You can’t perform that action at this time.