Skip to content

Instantly share code, notes, and snippets.

David Piepgrass qwertie

Block or report user

Report or block qwertie

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View whatAmI.ts
function whatAmI(thing: string|RegExp|null|number[]|Date) {
if (thing instanceof RegExp || typeof thing === "string") {
// Here, TypeScript knows that thing is RegExp|string
if (typeof thing !== "string")
console.log("Ahh, so it's a RegExp: " + thing.toString());
else
console.log("It's a string of length " + thing.length);
} else {
// Here, TypeScript knows that thing is null|number|Date
if (thing == null)
View (incomplete) b+tree.ts
// Type parameters can have default values,
// so `var t: BTree` means `var t: BTree<any,any>`
export class BTree<K=any, V=any>
{
// Root node (key-value pairs are stored in here)
private _root: BNode<K, V>;
// Total number of items in the collection
_size: number = 0;
// Maximum number of items in a single node
_maxNodeSize: number;
View IBox.ts
interface IBox {
readonly width: number;
readonly height: number;
}
interface IArea {
readonly area: number;
}
View private-box.ts
class PrivateBox {
constructor(private width: number, private height: number) {}
area() { return this.width * this.height; }
}
let x = new PrivateBox(4, 5);
console.log(x.area()); // OK
console.log(x.width); // ERROR: 'width' is private and only
// accessible within class 'PrivateBox'.
View box.ts
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;
View box.js
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;
}
View ytypes.js
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
@qwertie
qwertie / expand_using.ecs - not .cs
Last active Jul 19, 2018
LeMP macro to expand the C# `using` statement
View expand_using.ecs - not .cs
// 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();
}
}
@qwertie
qwertie / package.json
Created Jun 30, 2018
scripts section for webpack + webpack.config.js
View package.json
"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 / package.json
Created Jun 30, 2018
scripts section for webpack
View package.json
"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"
},
You can’t perform that action at this time.