Skip to content

Instantly share code, notes, and snippets.

View omichelsen's full-sized avatar

Ole Bjørn Michelsen omichelsen

View GitHub Profile
@omichelsen
omichelsen / emojis.js
Created April 27, 2016 18:51
JS: ascii smiley to emoji mapping
export const keys = Object.freeze({
'o/': '👋',
'</3': '💔',
'<3': '💗',
'8-D': '😁',
'8D': '😁',
':-D': '😁',
'=-3': '😁',
'=-D': '😁',
'=3': '😁',
@omichelsen
omichelsen / backup.sh
Created February 20, 2015 17:35
bash: backup mysql
#!/bin/sh
PATH=/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin
#----------------------------------------------------
# a simple mysql database backup script.
# version 2, updated March 26, 2011.
# copyright 2011 alvin alexander, http://devdaily.com
#----------------------------------------------------
# This work is licensed under a Creative Commons
# Attribution-ShareAlike 3.0 Unported License;
@omichelsen
omichelsen / cheatsheet.js
Last active November 20, 2021 16:51
JavaScript cheat sheet
// Random 0 to max (excl)
const random = (max) => Math.floor(Math.random() * max)
// Random between (min incl, max excl)
const random = (min, max) => Math.floor(Math.random() * (max - min) + min)
// Fill array
const arr = new Array(42).fill(0).map(() => random(1, 5))
// Remove duplicates from Array (tip: fallback using indexOf)
let chars = ['A', 'B', 'A', 'C', 'B']
@omichelsen
omichelsen / split-string-columns-to-table.sql
Created October 18, 2014 14:26
Split strings in columns to a new table
declare @table table(id int, strings nvarchar(400))
insert into @table (id, strings)
select 1, 'abc,def,ghi'
union all
select 2, 'jkl'
union all
select 3, 'mno,pqr'
select * from @table
@omichelsen
omichelsen / ReactEntry.ts
Created January 29, 2020 00:31
Creates a function that will render a React component into a target element and return an unmount function.
import React from 'react'
import { render, unmountComponentAtNode } from 'react-dom'
/**
* Creates a function that will render a React component into a target element and return an unmount function.
* The entry point should be loaded async by a ReactLoader component to ensure code splitting.
* @param component Root component to render
*/
export default <P>(component: React.ComponentType<P>) => (domElement: Element, props: P) => {
render(React.createElement(component, props), domElement)
@omichelsen
omichelsen / ReactLoader.ts
Last active January 28, 2020 21:31
ReactLoader
import { OnDestroy, OnInit } from '@angular/core'
export type VoidFunction = () => void
export interface ReactAppInit {
default(component: Element, ...args: any[]): VoidFunction
}
export default class ReactLoaderComponent<T extends {}> implements OnInit, OnDestroy {
constructor(
@omichelsen
omichelsen / guid.js
Created October 6, 2015 11:45
JS guid
export function create() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0,
v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
var guid = require('js/guid');
@omichelsen
omichelsen / running-total-sql-server-2012.sql
Created October 17, 2014 08:13
Calculate a running total in SQL Server 2012
CREATE TABLE #TestData (
id int not null identity(1,1) primary key,
account varchar(10) not null,
deposit int not null
);
INSERT INTO #TestData (account, deposit) VALUES ('Vacation', 10)
INSERT INTO #TestData (account, deposit) VALUES ('Vacation', 20)
INSERT INTO #TestData (account, deposit) VALUES ('Vacation', 30)
INSERT INTO #TestData (account, deposit) VALUES ('Bills', 40)
INSERT INTO #TestData (account, deposit) VALUES ('Bills', 50)
@omichelsen
omichelsen / .bash_profile
Last active November 21, 2018 05:53
.bash_profile
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
# Programs
# ------------------------------------------------------------------------------
alias subl="open -a /Applications/Sublime\ Text\.app"
alias vsc="open -a /Applications/Visual\ Studio\ Code.app"
alias sim="open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app"
# less syntax highlight
LESSPIPE=`which src-hilite-lesspipe.sh`
@omichelsen
omichelsen / feature-flip-data-rules.js
Last active July 7, 2016 22:18
Feature flipping data and rules
const data = {
browser: {
name: 'Chrome',
version: '52.4.53.123',
os: 'Mac'
},
env: 'development',
settings: {
audioConference: {
release: '2016-10-23 22:34:12'