Skip to content

Instantly share code, notes, and snippets.

@C-F-K
C-F-K / guid.js
Last active December 19, 2019 16:30
RFC4122-compliant v4 UUID using crypto-strong randomness, code so functional Haskell B. Curry would fucking WEEP
const [Bx,Hx,Qx] = [()=>crypto.getRandomValues(new Uint8Array(1))[0],x=>[...Array(x)].map(Bx),m=>n=>x=>y=>y<=n&&y>=m?y:Qx(m)(n)(x)(x())];
export const guid = ()=>[Hx(4),Hx(2),[Qx(0b01000000)(0b01001111)(Bx)(Bx()),Bx()],[Qx(0b10000000)(0b10111111)(Bx)(Bx()),Bx()],Hx(6)].map(a=>a.map(a=>a.toString(16).padStart(2,'0')).reduce((a,b)=>a.concat(b),'')).join('-');
# CODE PARSES .CSV FILES:
# @csvrows = (@$row1, @$row2, @$row3...)
# @row1 = ("field","other field","bla bla bla"...)
# ie. an array of references to other arrays containing the values of the fields in each row
# CODE NEEDS TO RETURN:
# @$arrayref = (%$hash_of_row1, %$hash_of_row2...)
# %hash_of_row1 = {FIELDS => @$row1}
# %hash_of_row2 = {FIELDS => @$row2}...
# @row1 = (%$hash_of_field1, %$hash_of_field2...)
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/firebase-element/firebase-element.html">
<polymer-element name="db-retrieve">
<template>
<firebase-element id="db"
location="http://cth-storage.firebaseio.com/"
data="{{data}}"
keys="{{keys}}"
childEvents
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/firebase-element/firebase-element.html">
<polymer-element name="db-save">
<template>
<firebase-element id="db"
location="http://cth-storage.firebaseio.com/"
data="{{data}}"
keys="{{keys}}"
childEvents
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/core-firebase/core-firebase.html">
<polymer-element name="discount-room">
<template>
<core-firebase location="https://discount-app.firebaseio.com/"
list="{{discount}}"
on-items-added={{update}}>
<input id="uchar" type="text"></input>
<button id="submit" on-click={{sendChar}}>Submit</button>
How exactly does the Firebase JS client interact with Polymer?
Specifically, what can and can't I do in terms of defining new Firebase references and getting/setting values from within nested elements?
model of component:
+-------
|discount-room
|+------
||discount-input