Skip to content

Instantly share code, notes, and snippets.

@smugen
smugen / constructor.js
Created December 25, 2013 10:14
constructor compatible with be calling as ordinary function
// check the prototype
function init(args){
if (Object.getPrototypeOf(this) !== init.prototype) {
// called without `new`
return new init(args);
}
this.args = args;
}
// check the constructor
@smugen
smugen / NSObjectExtension.h
Created January 27, 2015 08:54
Add `performSelector` back to swift
//
// NSObjectExtension.h
// KeyOUcare
//
// Created by CYWang on 2015/1/27.
// Copyright (c) 2015年 OUcare. All rights reserved.
//
#ifndef KeyOUcare_NSObjectExtension_h
#define KeyOUcare_NSObjectExtension_h
@smugen
smugen / ClassAndInstances.swift
Last active August 29, 2015 14:17
Swift 1.2 notes
class ClassName : NSObject {
static var i = 0
// static / class function (seems the same)
static func fn() {}
class func fn2() {}
init() {}
@smugen
smugen / remove_youtubePlayer.js
Created April 2, 2017 15:17
Remove YouTube Player on SHOWROOM
javascript:void document.getElementById('youtubePlayer').remove();
@smugen
smugen / flattenObject.js
Created November 6, 2022 11:44
221103 Practice
const SEP = '.';
/**
* traversal an object and flatten its nested objects property keys,
* concatted by a `.` into a single level non-nested object
*
* @param obj object
*
* @returns object
*/
@smugen
smugen / compositeDesignPattern.ts
Created December 3, 2022 12:21
221203 Composite Design Pattern
abstract class Asset {
abstract getDetails(): string[];
}
class Machine implements Asset {
constructor(
private readonly machineId: number,
private readonly machineModel: string,
private readonly machineName: string,
) {}