Skip to content

Instantly share code, notes, and snippets.

@ToanTranX
ToanTranX / better-nodejs-require-paths.md
Created December 13, 2016 04:18 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@ToanTranX
ToanTranX / pagination.ts
Created November 5, 2016 21:36 — forked from mattmazzola/pagination.ts
GraphQL Pagination Implementation
var graphql = require('graphql');
export function Edge(itemType: any) {
return new graphql.GraphQLObjectType({
name: "Edge",
description: "Generic edge to allow cursors",
fields: () => ({
node: { type: itemType },
cursor: { type: graphql.GraphQLString }
})
@ToanTranX
ToanTranX / App.js
Created September 16, 2016 03:06 — forked from K3TH3R/App.js
ES6 Inheritance from ES5 Classes with EaselJS
// EaselJS still has some problems compiling with Webpack/CommonJS as of this
// publishing (01/23/2016), which makes it difficult to write modularity
// in ES6 for it. However, it's not that hard to work around:
import { Car, Mustang } from './Cars';
let createjs = window.createjs; // local reference to createjs and bypasses the current module issues
let stage = new createjs.Stage('car_canvas');
let car = new Car({
color: '#0081c9',
id: 'car1',
@ToanTranX
ToanTranX / PersistedGameOfPingPong.scala
Created December 31, 2015 09:38 — forked from jboner/PersistedGameOfPingPong.scala
A game of ping pong using two Akka Actors, persisted using Event Sourcing through Akka Persistence
package demo
import akka.actor.{Props, ActorSystem}
import akka.persistence.PeristentActor
object PingPong extends App {
case object Ball // The Command
case object BallReceived // The Domain Event, represents a Fact, something that have already happened
class Ping extends PeristentActor {