Skip to content

Instantly share code, notes, and snippets.

View qwertie's full-sized avatar

David Piepgrass qwertie

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / app.tsx
Last active June 30, 2018 05:34
Minimal React+TypeScript example
import * as React from 'react';
import * as ReactDOM from 'react-dom';
class App extends React.Component<{greeting: string}, {count:number}> {
state = {count: 0};
render() {
return (
<div>
<h2>{this.props.greeting}</h2>
<button onClick={() => this.setState(
@qwertie
qwertie / StringBuilderExt.cs
Created November 10, 2016 02:10
StringBuilderExt.cs extension methods for StringBuilder
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Loyc
{
/// <summary>Extension methods that add some functionality of <c>string</c> to <c>StringBuilder</c>.</summary>
public static class StringBuilderExt
{
@qwertie
qwertie / UndoStack.cs
Last active November 8, 2016 07:36
UndoStack.cs
/* I wrote an application-agnostic UndoStack class for my own diagramming tool. It's easy to use, for example here's how you might write code to delete a shape:
UndoStack _undoStack = new UndoStack();
...
void DeleteShape(GraphicElement el)
{
_undoStack.Do(@do => {
if (@do) {
// Code to delete the shape
} else {
@qwertie
qwertie / InternalList.cs
Last active June 28, 2021 03:05
InternalList<T>, the low-level List<T> (standalone version: does not require Loyc.Essentials.dll, is compatible with .NET 3.5)
// from Loyc.Essentials.dll. Licence: MIT
namespace Loyc.Collections.Impl
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Linq;
/// <summary>A compact auto-enlarging array structure that is intended to be
@qwertie
qwertie / SimpleTimer.cs
Created September 25, 2013 21:36
A fast, simple alternative to System.Diagnostics.Stopwatch based on Environment.TickCount. Its resolution is typically 10-16 ms.
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace Loyc
{
/// <summary>
/// A fast, simple timer class with a more convenient interface than
/// System.Diagnostics.Stopwatch. Its resolution is typically 10-16 ms.