Skip to content

Instantly share code, notes, and snippets.

View crisdosaygo's full-sized avatar
🏖️
Netscaping

Cris crisdosaygo

🏖️
Netscaping
View GitHub Profile

Keybase proof

I hereby claim:

  • I am dosaygo-coder-0 on github.
  • I am dosaygo (https://keybase.io/dosaygo) on keybase.
  • I have a public key whose fingerprint is 3167 FB69 514B 028F DCF4 63C8 A721 621D E695 FDA0

To claim this, I am signing this object:

@crisdosaygo
crisdosaygo / render.js
Created May 23, 2017 06:27
Easiest way to create HTML document fragments from text
"use strict";
{
function df( t ) {
return (new DOMParser).parseFromString(`<template>${t}</template>`,"text/html").head.firstChild.content;
}
function fc( t ) {
const article = document.createElement('article');
article.innerHTML = t;
return article.firstChild;
@crisdosaygo
crisdosaygo / tifumini.js
Last active June 17, 2017 18:20
tifuhash 32 bit in a mini package
// tifuhash 32-bit (c) dosyago & k stringfellow 2017 MIT LICENSE https://www.npmjs.com/package/tifuhash
let f = ( s = 0, m = '', ...n ) => {
s = parseFloat(s); m = Array.from(m).concat(n).map(x => isNaN(parseFloat(x)) ? x.charCodeAt(0) : parseFloat(x));
let a=new Float64Array(4);
a[0] = 1;
a[2] = s ? Math.pow(s+1/s, 1/2) : 3;
a[3] = s ? Math.pow(s+1/s, 1/5) : 7;
m.forEach((x,i) => {
a[1] = (x+i+1)/a[3];
@crisdosaygo
crisdosaygo / one.js
Last active September 15, 2017 19:21
5lines - useful utils in 5 lines or less
/* 5lines - function body must be not more than 5 SLOC */
// encrypt a string, also decrypt a string
function encrypt(key, str, s = 1) {
// clean
s = Number.isNaN(parseInt(s)) ? 1 : parseInt(s);
// turn key into numbers
key = new Uint16Array([...key].map( k => k.codePointAt(0) ));
// write generator to produce RNG
const rng = (function*(){while(true){yield(key.reduce((K,k,i)=>(key[(i+s)%key.length]+=k, k=(k<<1||k>>15),K+k),s),key[0])}}());
// more 5 line functions
function project( obj, ...slots ) {
slots = new Set(slots);
const pslots = Object.keys( obj ).filter( k => slots.has(k) );
return pslots.reduce( (p,k) => (k.includes('.') ? p[k] = resolve(obj,k) : p[k]=obj[k],p), {});
}
function resolve( obj, path ) {
// FIXME: if key == '.' this will break. :)
/**
Example of component api idea
**/
component1.api = {
add_sel()
del_sel()
generalize()
@crisdosaygo
crisdosaygo / index.html
Created September 23, 2017 18:15 — forked from anonymous/index.html
Bookmarklet // source https://jsbin.com/nosefuduju
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Bookmarklet</title>
</head>
<body style="max-width:700px; margin:0 auto;">
<p>Here is the bookmarklet:
<a href="javascript:(function()%7B(function()%20%7Bconst%20req%20%3D%20new%20XMLHttpRequest()%3Bconst%20key%20%3D%20'AIzaSyAUYMRSUW3BAZLhSTbB1poQuQ4xaqt2C4c'%3Breq.open('POST'%2C%20'https%3A%2F%2Fwww.googleapis.com%2Furlshortener%2Fv1%2Furl%3Fkey%3D'%2Bkey)%3Breq.setRequestHeader(%22Content-Type%22%2C%20%22application%2Fjson%22)%3Breq.responseType%3D%22json%22%3Breq.send(JSON.stringify(%7BlongUrl%3Alocation.href%7D))%3Bconst%20text%20%3D%20document.createElement('textarea')%3Blet%20result%3BsetTimeout(%20()%20%3D%3E%20(document.execCommand('copy')%2Ctext.remove())%2C%20700%20)%3Breq.onreadystatechange%20%3D%20()%20%3D%3E%20%7Bif%20(%20req.status%20%3D%3D%20200%20%26%26%20req.readyState%20%3D%3D%204%20)%20%7Bdocument.body.appendChild(text)%3Btext.value%20%3D%20req.response.id%3Btext.se
@crisdosaygo
crisdosaygo / neucomponents.js
Last active September 24, 2017 04:25
It all sucks. Time to make it better.
/**
So dosyhil gives good components on the server.
What about the client?
**/
// example
const components = {};
Object.assign( self, { components } );
def`
@crisdosaygo
crisdosaygo / wow.js
Created September 28, 2017 09:45
Micro Spread Sheet
// check this: http://jsfiddle.net/ondras/hYfN3/
@crisdosaygo
crisdosaygo / codegolf.md
Created September 28, 2017 09:48 — forked from xem/codegolf.md
JS code golfing

codegolf JS

Mini projects by Maxime Euzière (xem), subzey, Martin Kleppe (aemkei), Mathieu Henri (p01), Litterallylara, Tommy Hodgins (innovati), Veu(beke), Anders Kaare, Keith Clark, Addy Osmani, bburky, rlauck, cmoreau, maettig, thiemowmde, ilesinge, adlq, solinca, xen_the,...

(For more info and other projects, visit http://xem.github.io)

(Official Slack room: http://jsgolf.club / join us on http://register.jsgolf.club)