Skip to content

Instantly share code, notes, and snippets.

View qwertie's full-sized avatar

David Piepgrass qwertie

View GitHub Profile
@qwertie
qwertie / index.html
Created June 30, 2018 05:35
index.html for Parcel
<!DOCTYPE html>
<html>
<head>
<title>App</title>
<meta charset="utf-8"/>
</head>
<body>
<h1>Mini React app ❤</h1>
<div id="app"></div>
<script src="app.tsx"></script>
@qwertie
qwertie / tsconfig.json -- not .js
Last active June 30, 2018 05:37
Suggested tsconfig.json
{ // TypeScript configuration file: provides options to the TypeScript
// compiler (tsc) and makes VSCode recognize this folder as a TS project,
// enabling the VSCode build tasks "tsc: build" and "tsc: watch".
"compilerOptions": {
"target": "es5", // Compatible with older browsers
"module": "umd", // Compatible with both Node.js and browser
"moduleResolution": "node", // Tell tsc to look in node_modules for modules
"sourceMap": true, // Creates *.js.map files
"jsx": "react", // Causes inline XML (JSX code) to be expanded
"strict": true, // Strict types, eg. prohibits `var x=0; x=null`
@qwertie
qwertie / server.js
Created June 30, 2018 05:41
Simple Node.js file server
var http = require("http"); // http server
var fs = require("fs"); // file system access
var url = require("url"); // url parser
var path = require("path"); // file path parser
// You can choose the port via command line, e.g. node server.js 3000
const port = process.argv[2] || '1234';
const folderToServe = 'app';
const mimeTypes = {
'.ico': 'image/x-icon',
'.html': 'text/html',
@qwertie
qwertie / index.html
Last active June 30, 2018 05:55
index.html for using compiled TypeScript without additional tools
<!DOCTYPE html>
<html>
<head>
<title>App</title>
<meta charset="utf-8"/>
<script src="node_modules/react/umd/react.development.js"></script>
<script src="node_modules/react-dom/umd/react-dom.development.js"></script>
<script src="node_modules/preact/dist/preact.dev.js"></script>
<script>
module = {exports:{}}; exports = {};
@qwertie
qwertie / package.json
Created June 30, 2018 06:07
scripts section for webpack
"scripts": {
"test": "echo \"Error: no tests installed\" && exit 1",
"build": "webpack app/app.tsx --module-bind tsx=awesome-typescript-loader -o app/app.bundle.js --mode=production",
"build:dev": "webpack app/app.tsx --module-bind tsx=awesome-typescript-loader -o app/app.bundle.js --mode=development",
"watch": "webpack app/app.tsx --module-bind tsx=awesome-typescript-loader -o app/app.bundle.js --mode=development --watch",
"start": "node server.js"
},
@qwertie
qwertie / package.json
Created June 30, 2018 06:10
scripts section for webpack + webpack.config.js
"scripts": {
"test": "echo \"Error: no tests installed\" && exit 1",
"build": "webpack --config webpack.config.js --mode=production",
"build:dev": "webpack --config webpack.config.js --mode=development",
"watch": "webpack --config webpack.config.js --mode=development --watch",
"start": "node server.js"
},
@qwertie
qwertie / expand_using.ecs - not .cs
Last active July 19, 2018 03:40
LeMP macro to expand the C# `using` statement
// Define a macro recognized by LeMP ( http://ecsharp.net/lemp )
define #using($type $varname = $expression, $block) {
{
$type $varname = $expression;
try $block
finally {
if ($varname != null)
((IDisposable)$varname).Dispose();
}
}
var y;
// Math.random() is a random number between 0 and 1
if (Math.random() < 0.5)
y = "Why?";
else
y = 25;
y = [y, y];
console.log(y); // print [25,25] or ["Why?","Why?"] in browser's console
class Box {
constructor(width, height) { // initializer
this.width = width;
this.height = height;
}
get area() { return this.width*this.height; } // getter function
setSquare(side) { // normal function
// set the Box's width and height to side, representing a square
this.width = this.height = side;
}
class Box {
width: number;
height: number;
constructor(width: number, height: number) {
this.width = width;
this.height = height;
}
get area() { return this.width*this.height; }
setSquare(side: number) {
this.width = this.height = side;