Skip to content

Instantly share code, notes, and snippets.

View tuananh's full-sized avatar
☁️
Head of Tech Platform @ VPBank. AWS Community Builder

Tuan Anh Tran tuananh

☁️
Head of Tech Platform @ VPBank. AWS Community Builder
View GitHub Profile
if (!process.browser) var sodium = require('sodium-native')
var blake2b = require('blake2b')
var blake2bw = require('blake2b-wasm')
var BLAKE2s = require('blake2s-js')
var crypto = require('crypto')
var DATA_64KB = Buffer.alloc(65536)
var DATA_4KB = Buffer.alloc(4096)
var DATA_128B = Buffer.alloc(128)
# Let's add a few entries in our stream "mystream". Every entry in a stream is like
# an hash, composed of fields and values, but every entry can have different fields.
# XADD appends a new entry in a stream, and returns an unique ID which is guaranteed
# be incrementing.
# The first part of the ID is the millisecond unixtime during the
# addition (or the time of the last entry in the stream, if greater than the current time).
# The second part of an entry is a 64 bit counter for entries added in the same ms.
127.0.0.1:6379> XADD mystream name pamela nicknake kill-9
@danielhavir
danielhavir / die_javascript.sh
Last active July 30, 2018 15:49
JavaScript Must Die!
### Removes Node and NPM from mac OS ###
# Uninstall using NPM
npm uninstall npm -g || echo "NPM uninstall didn't work"
# Try if Node's installed with Brew
(brew uninstall node&&brew prune)||echo "Node was not installed with Brew"
# Remove all files and folders including Node or NPM
rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node opt/local/include/node /opt/local/lib/node_modules
rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*
rm -rf /usr/local/include/node*
const Page = require('puppeteer/lib/Page');
// the following 2 methods are originally from: https://github.com/GoogleChrome/puppeteer/issues/85#issuecomment-341743259, with some modification to fit puppeteerv1.0.0
async function newPageWithNewContext(browser) {
const { browserContextId } = await browser._connection.send('Target.createBrowserContext');
const { targetId } = await browser._connection.send('Target.createTarget', { url: 'about:blank', browserContextId });
const target = await browser._targets.get(targetId);
const client = await browser._connection.createSession(targetId);
const page = await Page.create(client, target, browser._ignoreHTTPSErrors, browser._appMode, browser._screenshotTaskQueue);
page.browserContextId = browserContextId;
@balupton
balupton / README.md
Last active June 5, 2019 10:26
Summary of the Node.js Board controversy from what I can gather
@fenos
fenos / Example.js
Last active June 26, 2019 10:15
Dataloader and GraphQL passing arguments
// GraphQL query that i'm trying to resolve with Dataloader but i can't find a way to pass argument to the
// loader function.
// The following GraphQL query should invoke the following DB round trips
// 1 - Posts *
// 2 - Tags limit 10 where post_id = ?
// 3 - Tags limit 20 where post_id = ?
query limitTagsOfThePost {
posts {
name
# These filters are based on email that Tim Hockin sent to kubernetes-dev a
# while ago on how to bring some sanity to github notifications with Kubernetes.
#
# https://groups.google.com/forum/#!msg/kubernetes-dev/5qU8irU7_tE/aZov0LpCBwAJ
#
# This file can be processed with https://github.com/mesozoic/gmail-yaml-filters
# Mark all k8s email
- match:
any:
@kanaka
kanaka / addTwo.wast
Last active June 17, 2021 21:39
Run wast (WebAssembly) in node
(module
(func $addTwo (param i32 i32) (result i32)
(i32.add
(get_local 0)
(get_local 1)))
(export "addTwo" (func $addTwo)))

Creating a redis Module in 15 lines of code!

A quick guide to write a very very simple "ECHO" style module to redis and load it. It's not really useful of course, but the idea is to illustrate how little boilerplate it takes.

Step 1: open your favorite editor and write/paste the following code in a file called module.c

#include "redismodule.h"
/* ECHO <string> - Echo back a string sent from the client */
int EchoCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {

Redis 4.2 roadmap

  1. Redis Cluster
  • Speed up key -> hashslot association. Now makes RBB loading 4x slower when there are many small keys.
  • Better multi data center story
  • redis-trib C coded and moved into redis-cli
  • Backup / Restore of Cluster
  • Non blocking MIGRATE (also consider not using 2X memory)
  • Faster resharding
  • Bug fixing and stress testing to bring it to next level of maturity