Skip to content

Instantly share code, notes, and snippets.

View richsilv's full-sized avatar

Richard Silverton richsilv

View GitHub Profile
// Utility types (required only once):
interface Phantom<T> {
__phantom: T;
}
// The idea is that you narrow the type you're going
// to use with a property which you're definitely not
// going to use, but that distinguishes this from
// any old object which matches the same base interface.
export type NewType<T, TagT> = T & Phantom<TagT>;
@richsilv
richsilv / MDX-CSS-decorators.md
Last active January 24, 2023 18:44
MDX decorators to apply alternative styles when using Markdown primitives

MDX CSS Decorators

MDX is super-cool, allowing one to include React Components in a markdown file:

# Title

A nicely formatted paragraph of text with [some links](www.blahblah.com).
@richsilv
richsilv / bsconfig.json
Last active February 21, 2018 13:12
Example bsconfig.json
{
"name": "reason-react-example",
"bsc-flags": ["-bs-no-version-header", "-bs-super-errors"],
"reason": {"react-jsx" : 2},
"bs-dependencies": [
"reason-react",
"bs-fetch",
"@glennsl/bs-json"
],
"sources": [
@richsilv
richsilv / .hyper.js
Created September 21, 2017 09:22
richsilv .hyper.js
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 12,
// font family with optional fallbacks
@richsilv
richsilv / local-replica-set-with-oplog.md
Created February 3, 2016 16:47
Setting up a local MongoDB replica set with oplog for use with Meteor

From an appropriate location:

mkdir replica-set
mkdir -p replica-set/rs0-0 replica-set/rs0-1
mongod --port 27018 --dbpath replica-set/rs0-0 --replSet rs0 --smallfiles --oplogSize 128 &
mongod --port 27019 --dbpath replica-set/rs0-1 --replSet rs0 --smallfiles --oplogSize 128 &
mongo localhost:27018
@richsilv
richsilv / meteor-template-get.js
Created August 27, 2015 12:18
Template instance `get` method for searching Template heirarchy for a named property
Blaze.TemplateInstance.prototype.get = function(key) {
var checkForKey = function(view) {
if (view && view.template instanceof Blaze.Template) {
var template = view.templateInstance()
if (typeof template[key] !== 'undefined') return template[key]
}
if (view.parentView) return checkForKey(view.parentView)
}
return checkForKey(this.view)
}
@richsilv
richsilv / randomCode.js
Last active August 29, 2015 14:18
Random code generator (numbers and letters) of prescribed format (e.g. Postcode, NI number)
var randomLetter = function() {return String.fromCharCode(Math.floor(Math.random()*26) + 65);}
var randomNumber = function() {return String.fromCharCode(Math.floor(Math.random()*10) + 48);};
var genDict = {
'l': randomLetter,
'n': randomNumber
};
// pass in a format string of the type: "4l 3n 2l", i.e. a space-delimited set of number/letter
// pairs, the first of which gives the number of characters of the given type and the second
// denotes the type: "n" for number, "l" for letter (always upper-case).
@richsilv
richsilv / generateNINO.js
Last active August 29, 2015 14:18
National Insurance Number generator
function generateNINO(style) {
var group1 = '';
var group2 = '';
var group3 = '';
var group4 = '';
var group5 = '';
var randomArrayIndex = '';
var notAllowed = new Array('GB', 'BG', 'NK', 'KN', 'TN', 'NT', 'ZZ');
var firstAllowed = new Array('A', 'B', 'C', 'E', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'W', 'X', 'Y', 'Z');
var secondAllowed = new Array('A', 'B', 'C', 'E', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', 'X', 'Y', 'Z');
@richsilv
richsilv / methods.js
Last active August 29, 2015 14:13
Demo of the difference in `this` in Meteor methods depending on whether the call was from client or server
var calledFromServer;
Meteor.methods({
'getThis': function() {
return this;
},
'getThisServer': function() {
return calledFromServer;
}