Skip to content

Instantly share code, notes, and snippets.

@babldev
babldev / README.md
Last active December 29, 2023 20:54
NextJS Background Task

NextJS Background Task Example

An example of how to add a background task (e.g. a queue consumer) to an existing NextJS project.

Setup

  • Add your background task file
  • Add a new worker-tsconfig.json, specifically specifying "module": "commonjs" and targeting only the worker source files.
  • Add convenience functions for building & running to package.json

Then to build once:

@nsjames
nsjames / EOSIO_API_Signing_Filter.js
Last active October 17, 2019 04:19
An example of how to protect your dapp and keys when assuming resource control for your users.
// SECURITY CONCERNS!
// Because your backend will be signing transactions, you will need to validate
// the transaction details before actually signing them.
// Using keys designated for specific actions is okay in some situations, but not all
// (like when your dapp wants to pay for eosio.token transfers, which exposes you to risk of losing your available tokens)
// The best flow for this is the following:
// VISUAL DIAGRAM: https://t.me/ScatterDevelopers/16787
// - Front-end which implements a multi-signer (scatter + api signer)
// - Scatter signs for the user
@cc32d9
cc32d9 / Fuzzys_ideas_on_new_BP_pay_model.md
Last active December 12, 2021 05:25
Fuzzy's ideas on a new BP pay model

@SirFuzzalot presented an idea for a new PB pay model for an EOSIO network in https://t.me/EOSPros

Fuzzy, [12.05.19 04:56]
Here is my thought on fixing dpos away from pageantry though. 
Let me find the discussion (should prob post it on whaleshares first but oh well)

Fuzzy, [12.05.19 05:03]
Ok ill just type it here since i am no longer in the group i posted it in initially.
@joepie91
joepie91 / random.md
Last active May 11, 2024 10:28
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

@assafshomer
assafshomer / op.js
Created March 10, 2016 11:57
bitcoinjs-lib op_return
wif='cNXxHLQwuzaLX7Z3apfSSEUDPPrQtUrwyzuaEZZakk2uWCcDS1Uo'
address='miq6AWvTYZJ63hJfh1W7zozHAf1URDv5pS'
unspent_txid = '067aabe97ff2e8051527d7f378266d046fd8e4c66e5b7dd671ec4e86b8a68cbb'
unspent_vout = 0
keyPair = bitcoin.ECPair.fromWIF(wif,network)
var txb = new bitcoin.TransactionBuilder(network)
var data = new Buffer('assafshomer')
var dataScript = bitcoin.script.nullDataOutput(data)
txb.addInput(unspent_txid, unspent_vout)
@Daniel-Hug
Daniel-Hug / arr-stat.js
Last active December 11, 2023 14:46
JavaScript statistical functions for arrays: max, min, range, midrange, sum, mean / average, median, modes, variance, standard deviation, mean absolute deviation, z scores
var arr = {
max: function(array) {
return Math.max.apply(null, array);
},
min: function(array) {
return Math.min.apply(null, array);
},
range: function(array) {