Skip to content

Instantly share code, notes, and snippets.

View miklcct's full-sized avatar

Michael Tsang miklcct

View GitHub Profile
@miklcct
miklcct / station_distances.php
Last active July 13, 2023 14:09
Get the shortest eNRT distances from a station to another station / every station in the National Rail network
<?php
declare(strict_types = 1);
$station_names = [
'AAP' => 'Alexandra Palace',
'AAT' => 'Achanalt',
'ABA' => 'Aberdare',
'ABC' => 'Altnabreac',
'ABD' => 'Aberdeen',
'ABE' => 'Aber',
@miklcct
miklcct / shack_attack_underground.sql
Last active November 23, 2023 18:51
shack attack (Underground)
-- use with miklcct/journey_recorder
select rank() over (order by `first visited`) as sequence, station, `first visited`, `last visited`, `number of visits`
from (
select station
, convert_tz(min(`time stamp`), @@session.time_zone, 'Europe/London') as `first visited`
, convert_tz(max(`time stamp`), @@session.time_zone, 'Europe/London') as `last visited`
, count(0) as `number of visits`
from (
select case
@miklcct
miklcct / shack_attack_national_rail.sql
Last active November 24, 2023 01:00
shack attack (National Rail)
select rank() over (order by `first visited`) as sequence, full_station as station, `first visited`, `last visited`, `number of visits`
from (
select case
when station = 'Adlington' then (select 'Adlington (Cheshire)' union select 'Adlington (Lancashire)')
when station = 'Bentley' then case route
when 'South Western Railway' then 'Bentley (Hampshire)'
when 'Northern' then 'Bentley (South Yorkshire)'
else (select 'Bentley (Hampshire)' union select 'Bentley (South Yorkshire)')
end
when station = 'Bramley' then case route
@miklcct
miklcct / virus.bash
Last active October 20, 2022 12:48
A shell script virus
#!/bin/bash
{
contains() {
for item in $1
do
if
[ "$item" = "$2" ]
then
return 0
@miklcct
miklcct / channel_distance.cpp
Last active September 2, 2020 01:54
Measure the distance done by a channel swimmer
// code adopted from https://stackoverflow.com/a/53147219/272733
#include <iostream>
#include <cmath>
const double degToRad = std::acos(-1) / 180;
struct vec3
{
double x, y, z;
@miklcct
miklcct / trading_fee_i-access.hs
Created September 5, 2019 14:08
I-Access trading fee
import System.IO
import Text.Printf
round' :: (RealFrac a, Integral b) => a -> b
round' x = truncate (x + 0.5)
roundAmount :: (RealFrac a) => a -> a
roundAmount x = fromIntegral ((round' (x * 100)) :: Integer) / 100
inputItem :: (Read a) => String -> IO a
@miklcct
miklcct / .htaccess
Created April 21, 2018 13:48
Remove index and .php from URL
# This .htaccess will hide your index and .php in your URL, and serve the corresponding .php file
# Examples:
# /index.php -> / (index.php served if it is the DirectoryIndex)
# /abc.php -> /abc (abc.php served if abc does not exist)
# /path/to/app.php/path/info -> /path/to/app/path/info (/path/to/app.php served)
#
# Unsupported scenarios:
# file.php and file coexist (file.php can't be served)
# index.php not set as DirectoryIndex
# multiple index.* exist in a directory (don't know which to serve after it is rewritten out)