Navigation Menu

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 / 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(" ")+"}";
@FireNeslo
FireNeslo / hardly-functional
Last active December 19, 2015 21:58
Weird string to function thing using to-Function
var fn = require('to-function');
function toObject(keys,values) {
  var rv = {};
  for (var i = 0; i < keys.length; ++i)
    if (keys[i] !== undefined) rv[keys[i]] = values[i];
  return rv;
}
function h(f) {
var args = f.split("=>")[0].split(",");
var func = f.split("=>")[1].split('-').map(function(fs){
@FireNeslo
FireNeslo / ObjMap
Last active December 20, 2015 01:19
An object with map and array like methods that keeps references to the same object for as long as possible; if you attatch a promise it will also resolve that promise before attempting to run any other chained functions. Useful for keeping references in for example angularjs while executing async logic.
function addScript(src) {
var script = document.createElement("script");
script.src = src;
document.body.appendChild(script);
return addScript;
}
addScript('//rawgithub.com/kriskowal/q/master/q.min.js');
/**
* A Object wrapper with some iteration helpers.
* @constructor
@FireNeslo
FireNeslo / Objserver.js
Created July 26, 2013 14:37
Observer like object to maintain a reference to data that can or will change a lot.
/**
Creates a new Objserver.
@class Observes an object and updates its value on changes that are applied.
@param [value] - Optional init value; -
*/
function Objserver(value) {
this.$value = value;
this.$change = [];
}
function jsonPath(obj,string) {
@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;