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 / unique.js
Created August 13, 2014 18:09
JS: unique
function unique(value, index, self) {
return self.indexOf(value) === index;
}
@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 / 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 / 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 / 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 / feed.xml.jade
Created October 16, 2015 11:11
Jade: RSS
doctype xml
rss(version="2.0", xmlns:atom="http://www.w3.org/2005/Atom")
channel
title= title
link= url
description= description
language= language
atom:link(href="#{ url }feed.xml", rel="self", type="application/rss+xml")
each post, slug in public.blog._data
if slug !== 'index'
@omichelsen
omichelsen / PHP: AtomFeed
Created November 24, 2015 08:50
Helper class for creating an Atom feed
class AtomFeed
{
private $xml;
function __construct()
{
$this->xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" />');
}
function setFeedHeader($title, $uri, $updated, $author_name, $author_email, $author_uri)
@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 / 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': '😁',