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 / gist:8373905
Created January 11, 2014 17:28
jQuery formNavigtaion
(function ($) {
$.fn.formNavigation = function () {
$(this).each(function () {
$(this).find('input').on('keyup', function(e) {
switch (e.which) {
case 39:
$(this).closest('td').next().find('input').focus(); break;
case 37:
$(this).closest('td').prev().find('input').focus(); break;
case 40:
@omichelsen
omichelsen / gist:8464951
Created January 16, 2014 22:45
JavaScript async remote
(function (window, document) {
var settings = {
dataId: 'data-myModule-id',
url: '/api/mymodule/'
};
function load() {
var elems = document.querySelectorAll('[' + settings.dataId + ']');
if (!elems) {
@omichelsen
omichelsen / logger.js
Last active March 5, 2016 21:10
JS: Logger
export const LogLevels = {
log : 0,
info : 1,
warn : 2,
error : 3
}
function clone(arr) {
return arr.map(a => JSON.parse(JSON.stringify(a)))
}
@omichelsen
omichelsen / .editorconfig
Last active March 8, 2016 19:03
Default editorconfig with tabs and 4 spaces
root = true
[*]
indent_style = tab
indent_size = 4
@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'
@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 / 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 / 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 / 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 / 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)