Skip to content

Instantly share code, notes, and snippets.

@magnusjt
magnusjt / ramblings.md
Last active November 25, 2018 13:03
Making good software: Ramblings

Dependency Injection

Pros:

  • Easy unit tests
  • Decoupling - Dependencies can be configured, wrapped, changed, mocked, all without changing the parent
  • Coding towards an interface - We can depend on only the things we need, no more and no less
  • Ability to write code using the dependency you wish you had. Make that thing later.

Cons:

  • Indirection
  • Too much decoupling. Sometimes, things should stay together.
@magnusjt
magnusjt / createWebComponent.js
Last active February 28, 2019 13:07
Create react app inside webcomponent (v1) with shadow dom fallback
const ReactDOM = require('react-dom')
const retargetEvents = require('react-shadow-dom-retarget-events')
function getStyleElementsFromReactWebComponentStyleLoader(){
try{
return require('react-web-component-style-loader/exports').styleElements
}catch(e){
return []
}
}
@magnusjt
magnusjt / container.js
Created January 16, 2017 11:01
Simple IOC container
class Container{
constructor(){
this.services = {};
}
service(name, cb){
Object.defineProperty(this, name, {
get: () => {
if(!this.services.hasOwnProperty(name)){
this.services[name] = cb(this);
@magnusjt
magnusjt / motd.sh
Created April 22, 2016 07:27
Message of the day CentOS 7
# Message of the day script based on various other scripts around the interwebs
# Works on Centos 7
# Toss it in /etc/profile.d
USER=`whoami`
REDHAT_RELEASE=`cat /etc/redhat-release`
KERNEL_VERSION=`uname -r`
NUMBER_OF_USERS=`users | wc -w`
ROOT_DISK_AVAILABLE=`df -Ph | grep root | awk '{print $4}' | tr -d '\n'`
@magnusjt
magnusjt / FileTransport.php
Last active August 29, 2015 14:07
Transport for swiftmailer that simply stores all emails as files instead of sending them
<?php
class FileTransport implements Swift_Transport{
private $path;
public function __construct($path = ""){
$this->path = $path;
}
public function isStarted(){