Skip to content

Instantly share code, notes, and snippets.

@MrTrick
MrTrick / stars.c
Last active February 23, 2016 12:54
//----------------------------------------------------------------------------------------------
//
// starsII
//
// Ver 0.1 - written in sourceboost c for the 16F628
//
// Author : MrTrick
// Date : 2010-12-25
// License : GPLv2
//
@MrTrick
MrTrick / part of a json-schema otherfile.json
Created February 3, 2016 05:41
Making a general swagger parameter definition more specific, by adding json-schema information.
...
"definitions": {
"special_id_csv": {
"description": "One or more of a particular kind of id separated by comma \",\"",
"type": "string",
"pattern": "^...regrexregexregexregexregex...$"
},
}
...
function ncmp(a, b) { return a - b; }
function format(set) { return JSON.stringify(set).replace(/\],\[/g,') (').replace('[[','[(').replace(']]','])'); }
function generate_combinations(dims) {
"use strict";
function next(el) { for(var i=dims.length-1;i>=0;i--) { if (++el[i]<dims[i]) return true; else el[i]=0; } return false; }
function first() { return Array.apply(null, Array(dims.length)).map(function() { return 0; }); }
function upperlimit() { var _ds = dims.slice().sort(ncmp); return _ds[0]*_ds[1]; }
function valid(set,n) { for(var i=0;i<n;i++) { for(var c=0,di=0;di<set[n].length;di++) if (set[n][di]===set[i][di]) if (++c>1) return false; } return true; }
@MrTrick
MrTrick / ba.sh
Last active December 11, 2015 16:31
awk <50knouns.txt '{print $1}' | sort -u > N.txt
aspell -len_GB dump master | sort -u > A.txt
tr <sowpods.txt '[:upper;]' '[:lower;]' | sort -u > S.txt
alias D=diff --new-line-format="" --unchanged-line-format=""
D A.txt N.txt > A_notN.txt
D A.txt S.txt > A_notS.txt
D N.txt A.txt > N_notA.txt
D S.txt A.txt > S_notA.txt
D N.txt S.txt > N_notS.txt
@MrTrick
MrTrick / bash.sh
Last active December 6, 2015 21:01
Words found in the 50knouns file that were not in the aspell en_gb file.
awk <50knouns.txt '{print $1}' | sort -u > 50knouns.txt.prepped
aspell -len_GB dump master | sort -u > aspell_en_gb.prepped
diff --new-line-format="" --unchanged-line-format="" 50knouns.txt.prepped aspell_en_gb.prepped > in_50knouns_notin_aspell_en_gb.txt
# Note: Deliberately doesn't lower-case the aspell file, so that names 'Fred' and etc are considered invalid.
wc -l *
# 49996 50knouns.txt
# 39235 50knouns.txt.prepped
# 135331 aspell_en_gb.txt
# 135331 aspell_en_gb.txt.prepped
july
april
africa
iii
jim
sci
phys
iraq
mrs
cir
#define PUMP_A 2
#define PUMP_B 3
#define WATER 12
#define BUZZER 13
#define BUZZER_OFF LOW
#define BUZZER_ON HIGH
#define WATER_LOW LOW //Short-circuit when 'dropped'.
#define WATER_HIGH HIGH
#define PUMP_OFF HIGH
@MrTrick
MrTrick / app.js
Last active October 30, 2015 06:03
//package.json: {"dependencies": {"xml2js": "~0.4.13","underscore": "~1.8.3"}}
var xml2js = require('xml2js');
var fs = require('fs');
var _ = require('underscore');
_.isScalar = function(o) { return o===null || (typeof o !== "object"); };
function summarizeXMLObject(obj, context) {
//Assume that array elements all have the same internals
if (_.isArray(obj)) {
@MrTrick
MrTrick / gist:aabdbb9ae8afb1f108b2
Last active August 29, 2015 14:18
Travelling MrTrick Problem

I'd like to embark on a walking tour of Sydney's light rail stations.
I want to visit 10 stations then return back to the place I started.
I won't actually be catching any services! I just want to admire each station's amenities.

However, there's a certain set of rules I must follow:

  1. I will be starting and ending at the corner of Thomas St & Jones St; https://goo.gl/maps/jgar0
  2. A station can be visited any number of times, or never!
  3. After visiting an odd station (the 1st, 3rd, 5th, 7th, 9th), I can visit any station next. (even)
  4. After visiting an even station (the 2nd, 4th, 6th, 8th), the next (odd) station must be at least THREE stops away.
FROM php:5.4-apache
# Install Python (needed for node.js)
RUN \
apt-get update && \
apt-get install -y python python-dev python-pip python-virtualenv && \
rm -rf /var/lib/apt/lists/*
# Install phpunit
RUN \