Skip to content

Instantly share code, notes, and snippets.

View stavalfi's full-sized avatar

Stav Alfi stavalfi

  • CVI @ CVI
  • Israel
View GitHub Profile
@stavalfi
stavalfi / Cpp lvalue rvalue and between By Stav Alfi.md
Last active November 27, 2021 20:33
C++ lvalue, rvalue and between By Stav Alfi
@stavalfi
stavalfi / functional-programming-practice.md
Last active September 5, 2018 14:29
Functional Programming Practice

Functional Programming Practice

All the methods and the documentation are taken from lodash docs


Goal

Manipulating collections using functional and declerative code.

Introduction

The following exercises are for experimenting and learning Redux. Do not use any external library except rxjs (it's optional and recommended).

Documentations:

Ex1

Write your allocator. Allocate a big block of bytes and manage its allocations and deallocations by your self. For example, allocate an array of 20,000 bytes and divide it into 10 cells such that each cell contains 2,000 bytes. The user can allocate and free cells of 2,000 bytes whenever he wants.

import WebSocket from 'ws'
function throttle<T>(callback: (message: T) => Promise<void>, interval = 1000): (message: T) => Promise<void> {
return (message: T) => Promise.resolve()
}
interface Message {
type: string
content: string
}
@stavalfi
stavalfi / setup-redis-cluster
Last active August 7, 2021 20:33
setup a cluster of redis masters on your local machine. support single instance or cluster (3+).
// must have: redis-cli, redis-server executables
// need npm modules: @stavalfi/create-folder-structure, execa, lodash
// tested on node 14.
// RUN single instance: `ts-node <file-name>.ts 1`
// RUN cluster of masters only: `ts-node <file-name>.ts 3` // can be 3+
// close with ctrl+c. make sure ports are closed after that as well.
///////////////////
@stavalfi
stavalfi / slowlog-evaluator.ts
Created August 7, 2021 21:59
Evaluate Redis Slowlogs output in nodejs
// this is just part of the code:
// based on iordis client in NodeJS
const [[error, result]] = await client.multi([['slowlog', 'get', '-1']]).exec()
if (error) {
throw error
}
const slowLogs = result as [id: number, ts: number, executionTime: number, command: string[]][]
const descOrder = slowLogs.sort((a, b) => b[2] - a[2])
for (const slowLog of descOrder) {
if status is-interactive
# Commands to run in interactive sessions can go here
end
fnm env | source
secrethub completion fish | source
set PATH $HOME/.cargo/bin /Users/stavalfi/.fnm/node-versions/v14.18.1/installation/bin $PATH
alias config.fish "code ~/.config/fish/config.fish"
alias config.vimrc "code ~/.vimrc"
alias crw "cargo watch -qcx 'run -q'"