Skip to content

Instantly share code, notes, and snippets.

View stelcheck's full-sized avatar

Marc Trudel stelcheck

View GitHub Profile
@stelcheck
stelcheck / app.js
Created June 2, 2017 07:18
require cache behaviour on throw
try {
require('./bad-require')
} catch (error) {
console.error('first error:', error.message)
}
try {
require('./bad-require')
} catch (error) {
console.error('second error:', error.message)
@stelcheck
stelcheck / usercommands-hello.ts
Created May 26, 2017 06:45
User commands in mage-validator
import * as mage from 'mage'
import { Acl } from 'mage-validator'
import { IsInt, Max, ValidateNested } from 'class-validator';
import PlayerData from '../types/PlayerData'
export default class {
@IsInt()
@Min(1)
public gemRegisterBonus: number
@stelcheck
stelcheck / Post.ts
Created May 24, 2017 00:56
class-validator example
import {validate, Contains, IsInt, Length, IsEmail, IsFQDN, IsDate, Min, Max} from "class-validator";
export class Post {
@Length(10, 20)
title: string;
@Contains("hello")
text: string;
@stelcheck
stelcheck / compile.ts
Last active May 24, 2017 00:07
TypeScript Compiler API
import * as path from 'path'
import * as ts from 'typescript'
const glob = require('glob')
const globPattern = path.join(this.projectPath, 'lib/modules/**/usercommands/*.ts')
const userCommandFiles = glob.sync(globPattern)
// Build a program using the set of root file names in fileNames
const program = ts.createProgram(this.userCommandFiles, {
@stelcheck
stelcheck / package.json
Created April 22, 2017 11:01
An alternative way to document package.json scripts
{
"name": "my-game",
"description": "Super duper",
"version": "0.0.1",
"repository": "...",
"author": "Marc Trudel <mtrudel@...jp>",
"license": "See LICENSE%",
"scripts": {
"help": " echo 'Display help information (this screen)' && npm run",
"mage": " echo 'Run the mage binary' && mage",
@stelcheck
stelcheck / bootstrap.sh
Created April 22, 2017 10:44
MAGE Bootstrap command, final form
npm install mage --bootstrap --prefix my-project
cd my-project
@stelcheck
stelcheck / bootstrap.sh
Created April 22, 2017 10:29
New MAGE Bootstrap command
mkdir my-project
cd my project
npm install mage --bootstrap
@stelcheck
stelcheck / install.sh
Created April 22, 2017 10:14
MAGE Bootstrap command, version 1
npm install mage -- --bootstrap
@stelcheck
stelcheck / bootstrap.js
Last active April 22, 2017 09:59
Extracting NPM command arguments from within an NPM script
var npmArgs = JSON.parse(process.env.npm_config_argv);
if (npmArgs.original.indexOf('--bootstrap') === -1) {
process.exit(0);
}
@stelcheck
stelcheck / nix.sh
Created April 22, 2017 09:51
Previous MAGE Bootstrap command
mkdir my-project
cd my-project
BOOTSTRAP=true npm install mage