Skip to content

Instantly share code, notes, and snippets.

@nwrox
nwrox / convert-dec-bin.js
Last active July 6, 2017 13:14
Desafio decimal para binário
const getLog2 = (n) => Math.round(Math.log2(n))
const reverseSeq = (n) => Array.from(Array(n + 1).keys()).reverse()
const getPow = (b, n) => Math.pow(b, n)
const decToBin = (n) => {
reverseSeq(getLog2(n)).reduce(
(acc, curr) => (getPow(2, curr) <= n) ? ( n -= getPow(2, curr), acc + '1' ) : acc + '0', ''
)
const createScript = (path, version) => {
const scriptTag = document.createElement('script')
scriptTag.src = path + '?v=' + version
scriptTag.type = 'text/javascript'
document.head.appendChild(scriptTag)
}
const createStyle = (path, version) => {
const assert = require('assert')
, crypto = require('crypto')
class HKDFBufferGenerator {
constructor(alg, ikm, info, salt, size) {
this._alg = alg
this._ikm = ikm
this._info = info
this._salt = salt
this._size = size
// entrada
[
{
"nome_ponto": "ponto A",
"nome_parametro": "parametro X"
},
{
"nome_ponto": "ponto B",
"nome_parametro": "parametro Y"
},
const asn1 = require('asn1.js')
, BN = require('bn.js')
, crypto = require('crypto')
const privKey = '{' +
'"version": "0",' +
'"modulus": "259154769957187194386805172792520197599479908823949686364408864499' +
'94962945058195024520647063684248740786360017811823364689336100960942063494732020' +
'91812725346950176505638890859938367164068105119839615900697880416966060139081266' +
'35977887948210779573734140292700996701877639405960971827664641117294919785640103' +
// capKey vem de uma iteração em um objeto
$('#div' + capKey).find('input')
.keydown(e => {
const key = e.key
, arrKeys = [
'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp','Backspace',
'Control', 'Delete', 'End', 'Home', 'Tab'
]
, input = $(e.currentTarget)
@nwrox
nwrox / mediaQuery.css
Created August 24, 2017 17:25 — forked from Woodsphreaker/mediaQuery.css
Responsive Media Query Defaults
/* Smartphones (portrait and landscape) ----------- */
@media only screen and (min-device-width: 320px) and (max-device-width: 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen and (min-width: 321px) {
/* Styles */
}
const arrStr = 'a.b.c.d'.split('.')
const res = arrStr.reduce((acc, curr, i, j) => {
acc.push({ [`${curr}`]: {} })
return acc
}, []).reduce((acc, curr, i, arr) => {
acc = arr[0]
if(i < arr.length) {
const arr = [{ price: 10, qtd: 2}, { price: 20, qtd: 1}]
, res = arr.reduce((acc, curr) => { acc.price = (acc.price || 0) + curr.price * curr.qtd; acc.qtd = (acc.qtd || 0) + curr.qtd; return acc }, {})
console.log(res)
@nwrox
nwrox / groupBy.js
Created February 13, 2018 13:31 — forked from suissa/groupBy.js
Group by bem facinho
const groupBy = (xs, key) => xs.reduce((rv, x) => {
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});