Skip to content

Instantly share code, notes, and snippets.

@jan-osch
jan-osch / esnextbin.md
Created November 4, 2019 13:27
esnextbin sketch
// Micro-app Code
io.press(() => {
print('sending alert');
cloud.enqueue('alert', {});
sync.now();
});
function turnOnLED(){
io.led(true);
timers.single(3000, () => {
#!/usr/bin/env node
/* eslint-disable no-console */
const superagent = require('superagent');
const stream = require('stream');
// Tests if the server is not vulnerable for this issue
// https://github.com/expressjs/body-parser/blob/master/README.md#request-aborted
const main = async () => {
const request = superagent.post('http://localhost:8001/v1/rexio')
.set('Content-Type', 'application/octet-stream');
@jan-osch
jan-osch / sync_pending.js
Created July 23, 2018 13:53
Sync pending settings bookmarklet
javascript:(() => { const identifierRegex = /(\/beacons|v3\/devices)\/(\w{16,32})(\/settings)?/; const match = identifierRegex.exec(window.location); if (!match) { return; } const isProd = /cloud\.estimote\.com/.exec(window.location); if (isProd && !window.confirm('This is production, are you sure?')) { return; } const identifier = match[2]; fetch(`/v3/devices/${identifier}`, { credentials: 'same-origin' }) .then(response => response.json()) .then(body => { if (body.data.pending_settings) { return fetch(`/v2/devices/${identifier}`, { body: JSON.stringify({ identifier: identifier, settings: body.data.pending_settings, }), method: 'POST', headers: { 'content-type': 'application/json', }, credentials: 'same-origin', }).then(response => response.json()) .then((body) => { if (window.confirm('Reload?\n\n' + JSON.stringify(body, null, 2))) { location.reload(); } }); } alert('No pending settings'); }); })();
var board = [
['-', '-', '-', '-', '-', '-', '-'],
['-', '-', '-', '-', '-', '-', '-'],
['-', '-', '-', 'R', 'R', 'R', 'R'],
['-', '-', '-', 'Y', 'Y', 'R', 'Y'],
['-', '-', '-', 'Y', 'R', 'Y', 'Y'],
['-', '-', 'Y', 'Y', 'R', 'R', 'R']];
function* getTraverses(matrix) {
const horizontalSize = matrix[0].length;
const { cloneDeep } = require('lodash');
class Solver {
constructor() {
this.fields = {};
this.avaliableValues = {};
this.queue = [];
this.result = 0;
}
const powerSet = (array) => {
const results = [];
const maximum = 1 << array.length;
let reference = 0;
while (reference < maximum) {
results.push(array.filter((element, index) => reference & 1 << index));
reference++;
}
#!/usr/bin/env node
const url = require('url');
const parse = (connectionString) => {
if (!connectionString) {
return 'Connection string is needed';
}
const parsed = url.parse(connectionString);
function * dawejPadding(str, len, ch=' '){
let current = str.length;
while(current < len){
yield ch;
current++;
}
yield str;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.box {
height: 20px;
width: 20px;