Skip to content

Instantly share code, notes, and snippets.

View xwlee's full-sized avatar
🎯
Focusing

Lee Xiang Wei xwlee

🎯
Focusing
View GitHub Profile
// Card Constructor
function Card(s, n) {
var suit = s;
var number = n;
this.getNumber = function() {
return number;
};
this.getSuit = function() {
return suit;
};
<?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;
}
<?php
//////////////////////////////////
// Reddit "hot" story algorithm //
//////////////////////////////////
function hot($ups, $downs, $date)
{
if (is_string($date)) $date = strtotime($date);
$s = $ups - $downs;

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

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.

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
@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
@xwlee
xwlee / rest-directive.js
Created December 23, 2018 06:01
Apollo Server REST Directive
const {
ApolloServer,
gql,
SchemaDirectiveVisitor
} = require('apollo-server');
const fetch = require('node-fetch');
const typeDefs = gql`
directive @rest(url: String) on FIELD_DEFINITION