Skip to content

Instantly share code, notes, and snippets.

View FireNeslo's full-sized avatar

Øystein Ø. Olsen FireNeslo

  • Scout Gaming Group
  • Norge/Norway
View GitHub Profile
@FireNeslo
FireNeslo / movable.css
Last active August 29, 2015 13:57
move html elements with data
ul {
min-height: 6em;
width: 100%;
text-align: center;
margin:0px;
display:-webkit-box;
display:-moz-box;
display:box;
-webkit-box-orient:horizontal;
-moz-box-orient:horizontal;
@FireNeslo
FireNeslo / Injector.js
Last active August 29, 2015 14:01
A really simple dependency injector based on promises.
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.Injector = factory();
}
}(this, function () {
return function Injector(injectors) {'use strict';
@FireNeslo
FireNeslo / typeOf.js
Last active August 29, 2015 14:04
A better typeof function
function typeOf(object) {
if(object && "name" in object.constructor) {
return object.constructor.name;
}
if(typeof object === 'number' && object !== object) {
return 'NaN';
}
var type = Object.prototype.toString.call(object);
return type.substring(8,type.length-1);
}
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['injector'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('./injector'));
} else {
root.namespace = factory(root.Injector);
}
}(this, function (Injector) {
var spaces = {};
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.Promise = factory();
}
}(this, function () {
function Promise(init) {
@FireNeslo
FireNeslo / designer.html
Last active August 29, 2015 14:06
designer
<link rel="import" href="../polymer/polymer.html">
<polymer-element name="my-element" attributes="show left right open">
<template>
<style>
:host {
display block;
width: 100%;
box-sizing: border-box;
@FireNeslo
FireNeslo / symbolic.js
Last active August 29, 2015 14:20
browserify transform for ruby style symbols
var through = require('through2');
var symbols = /¤([^\s,:;()\[\]{}=]+)/g
function strings(string, match) {
return "'" + match + "'"
}
module.exports = function (file) {
return through(function (buffer, enc, next) {
var input = buffer.toString('utf8')
@FireNeslo
FireNeslo / index.js
Created September 18, 2015 16:21
requirebin sketch
var Peer = require('simple-peer')
var client = new Peer({ initiator: true })
var server = new Peer()
var IPADDRESS = /[0-9]+(?:\.[0-9]+){3}/g
var addresses = []
function getIPs(signal) {
var result = null
Object.keys(signal||{}).forEach(function test(key) {
while(result = IPADDRESS.exec(signal[key])) {
@FireNeslo
FireNeslo / base.es6
Created October 14, 2015 08:20
Base Mdoel es6
function belongsto(Class, property, descriptor) {
return {
get() {
return descriptor.get().find(this[property+'Id'])
},
set(id) {
return this[property+'Id'] = id.id || id
}
}
}
@FireNeslo
FireNeslo / debug_object_as_string.js
Last active December 16, 2015 21:39
This is just a small function I created to see the structure of an event object in the log i recieved from phonegap. It's great for everyone that hates the "[object Object]" string in their logs.
function stringDebug(sender, method, object) {
var tostring =Object.prototype.toString;
Object.prototype.toString = function(padding) {
padding = padding || 3;
var res = Array(padding-2).join(" ")+"{";
var _self = this;
for(var attr in _self) {
res += '\n' + Array(padding).join(" ") + attr + " : " + ((this[attr] && (padding +2) < 12) ? this[attr].toString(padding +2) : "null");
}
return res+"\n"+Array(padding-2).join(" ")+"}";