Skip to content

Instantly share code, notes, and snippets.

View xwlee's full-sized avatar
🎯
Focusing

Lee Xiang Wei xwlee

🎯
Focusing
View GitHub Profile
@xwlee
xwlee / uppercase-directive.js
Created December 23, 2018 05:14
Apollo Server Upper Case Directive
const {
ApolloServer,
gql,
SchemaDirectiveVisitor
} = require('apollo-server');
const { defaultFieldResolver } = require('graphql');
const typeDefs = gql`
directive @upper on FIELD_DEFINITION

Docker version 17.05.0-ce

Create nodes using Docker Machine

$ docker-machine create -d virtualbox --virtualbox-memory "512" manager1
$ docker-machine create -d virtualbox --virtualbox-memory "512" manager2
$ docker-machine create -d virtualbox --virtualbox-memory "512" worker1
$ docker-machine create -d virtualbox --virtualbox-memory "512" worker2

Maps

The Map Data Structure

Maps are data structure composed of a collection of key/value pairs. They are very useful to store simple data, such as property values.

Issues With Using Objects as Maps

When using Objects as maps its keys are always converted to strings.

Arrays

Reading Values With Array Destructuring

We can use destructuring to assign multiple values from an array to local variables.

let users = ["Sam", "Tyle", "Brook"];
let [a, b, c] = users; // Easy to understand and less code
console.log(a, b, c); // > Sam Tyler Brook
<?php
//////////////////////////////////
// Reddit "hot" story algorithm //
//////////////////////////////////
function hot($ups, $downs, $date)
{
if (is_string($date)) $date = strtotime($date);
$s = $ups - $downs;
<?php
abstract class enemyShip {
protected $name;
protected $amtDamage;
public function setName($newName) {
$this->name = $newName;
}
<?php
abstract class enemyShip {
protected $name;
protected $amtDamage;
public function setName($newName) {
$this->name = $newName;
}
// Card Constructor
function Card(s, n) {
var suit = s;
var number = n;
this.getNumber = function() {
return number;
};
this.getSuit = function() {
return suit;
};