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
function schase(models, objects = {}) {
function resolve(data) {
for(const [ name, object ] of Object.entries(data)) {
const [ _, base, ref ] = /(.*?)(_id|Id|Ids|_ids)?$/.exec(name)
const [ plural ] = /es|s$/.exec(ref) || []
const model = base.replace(/es|s$/, '')
if(!objects[model]) objects[model] = {}
self.setImmediate = cb => Promise.resolve().then(cb)
var fsModule = new Blob([`
module.exports = {
readdirSync() {
return []
},
readFileSync(file) {
const xhr = new XMLHttpRequest()
@FireNeslo
FireNeslo / web-crypto-jwt.js
Last active March 24, 2024 04:27
JWT tokens using web crypto
const encoder = new TextEncoder()
const decoder = new TextDecoder()
const ALGORITHMS = {
HS: { name: 'HMAC' },
ES: { name: 'ECDSA', namedCurve: 'P-256' },
RS: { name: 'RSASSA-PKCS1-v1_5', modulusLength: 2048, publicExponent: new Uint8Array([0x01, 0x00, 0x01]) },
PS: { name: 'RSA-PSS', saltLength: 128, modulusLength: 2048, publicExponent: new Uint8Array([0x01, 0x00, 0x01]) },
}
var structure = (function () {
"use strict";
function BaseStruct(values) {
for(var i= values.length-1; i>= 0; i--) {
this[i] = values[i]
}
}
BaseStruct.prototype.toJSON = function toJSON() {
var array = new Array(this.length)
for(var i = array.length-1; i >= 0; i--) {
@FireNeslo
FireNeslo / immap.js
Last active May 14, 2017 17:52
Immutable thingy
var {ARRAY, NUMBER, STRING, BOOLEAN, OBJECT} = {
ARRAY: Symbol('array'),
OBJECT: Symbol('object'),
NUMBER: Symbol('number'),
STRING: Symbol('string'),
BOOLEAN: Symbol('boolean'),
}
function flatMap(list, callback) {
const result = []
@FireNeslo
FireNeslo / demo.es6
Last active January 2, 2018 01:47
Simple es6 heredoc thingy
var html = heredoc `
<section>
<h1> title</h1>
<p>content</p>
</section>
`
@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 / 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 / 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 / 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;