Skip to content

Instantly share code, notes, and snippets.

@rmasters
rmasters / example.jinja2
Last active June 9, 2024 23:18
Abusing annotations to add secondary-values to Python StrEnums
{% for region in regions|sort %}
<label><input type="radio" name="region" value="{{ region.value }}" required> {{ region }}</label>
{% endfor %}
@rmasters
rmasters / .gitignore
Last active May 19, 2021 14:40
Work around Pydrive's lack of support for service_account.json
# Dynamically generated files
.service_account_pkcs12.asc
@rmasters
rmasters / 1to50beater.js
Created March 29, 2020 13:47
Beats http://zzzscore.com/1to50/ in ~5 seconds. Can be made faster if your laptop isn't on it's last legs.
// http://zzzscore.com/1to50/ beater
function getPositions(root) {
const elems = new Map();
for (const elem of root.querySelectorAll('div')) {
const num = parseInt(elem.innerText);
if (num > 0) { // Ignore spacer/styling elements
elems.set(parseInt(elem.innerText), elem);
}
}

Keybase proof

I hereby claim:

  • I am rmasters on github.
  • I am rmasters (https://keybase.io/rmasters) on keybase.
  • I have a public key ASASv9o8ea4dILRtsbGKu0Ex_LN3gKivLbfGFxo0S9WipQo

To claim this, I am signing this object:

import requests
# Say the user's home station is Woolwich Arsenal and they travel by NR and DLR
search_result = requests.get('https://api.tfl.gov.uk/StopPoint/Search?query=woolwich').json()['matches'][0]
# Get the StopPoint's line data
stoppoint = requests.get('https://api.tfl.gov.uk/StopPoint/{}'.format(search_result['id'])).json()
# Set modes for each requested mode that's actually provided by the station
requested_modes = ['dlr', 'national-rail']
@rmasters
rmasters / ga.js
Created January 15, 2018 16:14
De-obfuscating the Google Analytics include snippet
window.GoogleAnalyticsObject = 'ga';
// Declare a function that keeps a memory of calls to it, in case the analytics.js loads later on (i.e. after a ga() call)
// Presumably those .q calls get replayed when analytics.js finally loads
window.ga = window.ga || function() {
(window.ga.q = window.ga.q || []).push(arguments)
}, window.ga.l = 1 * new Date();
// e.g. if you called ga('foobar') here, they'd be recorded
// Declare a script tag for the analytics include
<?php
function hashGenerator($items) {
for ($i = 0; $i < $items; $i++) {
yield rtrim(base64_encode(md5(microtime())),"=") => rtrim(base64_encode(md5(microtime())),"=");
}
}
function time_fn($name, callable $fn, ...$args) {
$start = microtime(true);
@rmasters
rmasters / gist:5c72b3564442cf2cdd8c
Created July 2, 2015 17:22
Total up columns in Assembla (bookmarklet)
javascript:(function()%7Bfunction%20callback()%7B(function(%24)%7Bvar%20jQuery%3D%24%3BjQuery(%22table.tickets%22).each(function()%7Bvar%20t%3D%7Bwork_remaining%3A0%2Cworked_hours%3A0%2Ctotal_worked_hours%3A0%2Cestimate%3A0%7D%3BjQuery(this).find(%22tbody%20%3E%20tr%22).each(function()%7Bt.work_remaining%2B%3DparseFloat(jQuery(jQuery(this).find(%22td.working_hours%22)%5B0%5D).text())%2Ct.worked_hours%2B%3DparseFloat(jQuery(jQuery(this).find(%22td.worked_hours%22)%5B0%5D).text())%2Ct.total_worked_hours%2B%3DparseFloat(jQuery(jQuery(this).find(%22td.total_invested_hours%22)%5B0%5D).text())%2Ct.estimate%2B%3DparseFloat(jQuery(jQuery(this).find(%22td.estimate%22)%5B0%5D).text())%7D)%3Bvar%20e%3D%5B%22%3Ctfoot%3E%22%2C'%3Ctr%20style%3D%22font-size%3A%2014px%3B%20font-weight%3A%20bold%3B%22%3E'%2C'%3Ctd%20colspan%3D%223%22%3ETotal%3A%3C%2Ftd%3E'%5D%3Be.push(%22%3Ctd%3E%22%2Bt.work_remaining.toFixed(1)%2B%22%3C%2Ftd%3E%22)%2Ce.push(%22%3Ctd%3E%22%2Bt.worked_hours.toFixed(1)%2B%22%3C%2Ftd%3E%22)%2Ce.push(%22%3Ctd%3E%
@rmasters
rmasters / ngrok.sh
Last active June 11, 2017 15:29
Bare-bones ngrok SysV init script
#!/bin/sh
### BEGIN INIT INFO
# Provides: ngrok
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the ngrok connection
# Description: starts ngrok using start-stop-daemon
### END INIT INFO
<?php
class PeopleController extends Controller {
public function index() {
return View::make('people.index', ['people' => []]);
}
}
class PeopleController extends Controller {
protected $view;