Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
if [ "$#" -ne 1 ]; then
echo "Usage: $0 your-service-prefix" >&2
exit 1
fi
fleetctl list-units | grep $1@ | cut -f1 -d. | while read -r unit ; do
unit_index=`echo $unit | cut -f2 -d@`
#!/usr/bin/nodejs
var http = require('http');
var latestCaptchaJson = JSON.stringify({
'q':'Is ice hot or cold?',
'a':['75e52a0ecfafeda17a34fc60111c1f0b'] });
var apiUrl = 'http://api.textcaptcha.com/mirror.json';
var refreshCaptchaEveryXSeconds = 5;
<?php
$salt = 'MySecretSalt';
// ... [snip] ...
// output hidden form fields
foreach ($captcha['answers'] as $checksum) {
$salted = md5($checksum.$salt);
echo '<input type="hidden" name="ans[]" value="'.$salted.'" />';
}
<?php
session_start();
$ans = $_POST['captcha']; // .. or whatever!
$checksum = md5(strtolower(trim($ans)));
if (in_array($checksum,$_SESSION['captcha_ans'])) {
// passed..!
} else {
// error: redisplay form, etc.
}
<?php
session_start();
$url = 'http://api.textcaptcha.com/example.json';
$captcha = json_decode(file_get_contents($url),true);
if (!$captcha) {
$captcha = array( // fallback challenge
'question'=>'Is ice hot or cold?',
'answers'=>array(md5('cold'))
);
[ {
"uuid":"dd172c56-5c99-4cc9-b334-49973e6c406e",
"time":1353605834,
"author":"Phil Dean",
"text":"Did this in river racers at around 0.65 and it was a decent level. scraped the tail a couple of times but nothing major."
} ]
{
"status":202,
"meta": {
"mediatype":"vnd.rainchasers-ack"
},
"data": {
"geocode":"Llangollen",
"ack":"ACTION:GEOCODE",
"message":"the snippet 'Llangollen' must be geocoded and replaced with <lat>,<lng>"
}
@robtuley
robtuley / resync.js
Last active December 11, 2015 07:48
node snippet to create a local river data cache from Rainchasers API
var rivers = [];
function parseUrl(url){
var parsed = require('url').parse(url);
return {
host: parsed.host,
path: parsed.pathname+(parsed.search||'')
};
}
@robtuley
robtuley / river.json
Last active December 11, 2015 03:58
JSON river section definition from Rainchasers API.
{
"uuid":"c28497e9-b662-4df1-8698-c8ffc4f57817",
"url":"http:\/\/rainchasers.com\/river\/colwyn\/hafod-ruffydd-isaf-beddgelert",
"river":"Colwyn",
"section":"Hafod Ruffydd Isaf to Beddgelert",
"km":"4",
"grade": {
"text":"4 (5)",
"value":"4",
"max":"5"
@robtuley
robtuley / resync.php
Last active December 11, 2015 03:58
PHP snippet to create a local river cache from the Rainchasers API.
<?php
$rivers = array();
$next = 'http://api.rainchasers.com/v1/river';
while ($next) {
$chunk = json_decode(file_get_contents($next),true);
if (!$chunk || $chunk['status']!=200) exit("resync fail at $next");
$rivers = array_merge($rivers,$chunk['data']);
fwrite(STDOUT,'.');
$requests[] = $next = isset($chunk['meta']['link']['next']) ? $chunk['meta']['link']['next'] : false;
}