Skip to content

Instantly share code, notes, and snippets.

View davidrhyswhite's full-sized avatar
💭
🚀

David Rhys White davidrhyswhite

💭
🚀
View GitHub Profile
interface Node {
id: ID!
title: String!
}
interface Navigatable {
slug: ID!
sectionNavigation: String!
}
let decoder = JSONDecoder()
if let decoded = try? decoder.decode(Episode.self, from: encoded) {
print(decoded.title)
}
@davidrhyswhite
davidrhyswhite / String.captureGroups.swift
Created June 21, 2017 01:03
Playing with regex in Swift...
extension String {
func capturedGroups(withRegex pattern: String) -> [String] {
var results = [String]()
var regex: NSRegularExpression
do {
regex = try NSRegularExpression(pattern: pattern, options: [])
} catch {
return results
}
// Conditionals
if (myVar == 'Hello') {
true
}
// if (myVar === 'Hello') {
// return true;
// }
// Only strict equality allowed for simplicity. Conditional expression returns by default the last expression.
@davidrhyswhite
davidrhyswhite / person.js
Last active August 25, 2016 23:04
For the Medium article on Object.defineProperty
var Person = function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
Object.defineProperty(this, 'fullName', {
get: function get() {
return this.firstName + ' ' + this.lastName;
}
});
};
@davidrhyswhite
davidrhyswhite / financial-year.js
Last active August 25, 2016 22:43
For the Medium article on Object.defineProperty
class FinancialYear {
constructor(turnover, costOfGoods) {
this.turnover = turnover;
this.costOfGoods = costOfGoods;
Object.defineProperty(this, 'grossProfitMargin', {
get () {
const gpm = ((this.turnover - this.costOfGoods) / this.turnover) * 100;
return `${gpm}%`;
}
const privateMethod = Symbol('privateMethod');
export default class Service {
constructor () {
this.say = "Hello";
}
[privateMethod] () {
console.log(this.say);
}
const privateMethods = {
privateMethod () {
console.log(this.say);
}
}
export default class Service {
constructor () {
this.say = "Hello";
}
var Service = (function () {
var Service = function () {
this.say = "Hello";
}
Service.prototype.publicMethod = function () {
privateMethod.call(this);
}
var privateMethod = function () {
@davidrhyswhite
davidrhyswhite / README.md
Last active August 29, 2015 14:17
GoCD Server & Agent with Docker.io
$ brew install docker docker-compose boot2docker
$ docker-compose up
$ open http://$(boot2docker ip):8153