Skip to content

Instantly share code, notes, and snippets.

View CunningFatalist's full-sized avatar

Stefan Bauer CunningFatalist

View GitHub Profile
@CunningFatalist
CunningFatalist / mixin.ts
Created April 11, 2021 09:45
Typesafe mixins in TypeScript. Source: "Programming TypeScript" by Boris Cherny.
// How to write typesafe mixins in TypeScript
// This type is required and basically includes all classes.
// Remember: We use `new` instead of `constructor` in types,
// and everything that is `new`-able is a class in TypeScript.
type ClassConstructor = new(...args: any[]) => {};
// This mixin safely adds new methods to any class.
function myMixin<C extends ClassConstructor>(Class: C) {
return class extends Class {
@CunningFatalist
CunningFatalist / _media-queries.scss
Last active October 25, 2018 09:23
SCSS mixins for easy Bootstrap 4 based responsiveness. Can also be used as standalone utility in other projects.
// Either import Bootstrap variables or use these:
$xs-lower-bound: 0px !global;
$xs-upper-bound: 575px !global;
$sm-lower-bound: 576px !global;
$sm-upper-bound: 767px !global;
$md-lower-bound: 768px !global;
$md-upper-bound: 991px !global;
$lg-lower-bound: 992px !global;
$lg-upper-bound: 1199px !global;
// Based on: https://gist.github.com/MoOx/9137295
@mixin reset-button {
// Opinionated cursor style
cursor: pointer;
border: none;
margin: 0;
padding: 0;
width: auto;
overflow: visible;
background: transparent;
@CunningFatalist
CunningFatalist / extending-factory.js
Created January 26, 2018 07:44
A nice little pattern for class factories. Can be used to create classes, extend classes, mix in methods... I like it.
class BaseClass {
constructor(name) {
this.name = name;
this.someFlag = true;
}
}
function factory(name) {
class ExtendedClass extends BaseClass {
constructor() {
@CunningFatalist
CunningFatalist / http-status-codes.enum.ts
Created January 16, 2018 09:59
An enum of HTTP status codes
enum HttpStatusCodes {
Ok = 200,
Created = 201,
Accepted = 202,
NonAuthoritativeInformation = 203,
NoContent = 204,
ResetContent = 205,
PartialContent = 206,
MultiStatus = 207,
AlreadyReported = 208,