Skip to content

Instantly share code, notes, and snippets.

View korzio's full-sized avatar

Alex Korzhikov korzio

View GitHub Profile

Microservices with GRPC/Go by Andrew

  • Overview

    • Use case - notify slack with time management
  • Project idea

    • Time management with no extra costs
    • On-premise project
  • Alternatives

@korzio
korzio / async generators.js
Last active April 21, 2021 19:05
Based on impressions of Kyle Simpson's "JavaScript: The Recent Parts" workshop - https://frontendmasters.com/courses/js-recent-parts/ . The task is to demonstrate the ability of iterating async requests with asap strategy, where both all the requests are done, and the results are returned as soon as possible
async function get(n) {
return new Promise(r => setTimeout(() => r(n), n * 100))
}
async function* asyncGenerator(arr) {
let anyResolve
arr.map(get).forEach(async request => {
const anyResult = await request
anyResolve(anyResult)
@korzio
korzio / nud.go
Last active March 17, 2021 20:40
func nud(acc interface{}, next token.Token) iterator {
// Node{Token: token.Token{Type: token.PLUS, Literal: "+"}, Left: &Node{Token: token.Token{Type: token.INT, Literal: "2"}}}
node := ast.Node{Token: &next}
it := iterator{nud: &node}
accIt, isIt := acc.(iterator)
if isIt {
// { , {... }
node.Left = accIt.nud
// save current stack
it.stack = accIt.stack
@korzio
korzio / tree.go
Last active March 17, 2021 20:38
tree := p.lexer.Tokens().
Scan(func(_ context.Context, acc interface{}, elem interface{}) (interface{}, error) {
it, isIterator := acc.(iterator)
next := elem.(token.Token)
if !isIterator || it.left == nil {
// null denotation
return nud(acc, next), nil
}
if it.operator != nil {
var prevIt *iterator
@korzio
korzio / node.go
Last active March 17, 2021 20:34
type Node struct {
Token *token.Token
Left *Node
Right *Node
}
// string representation
// 1 * 2 + 3 -> {+,{*,{1},{2}},{3}}
func (n *Node) ToString() string {
res := "{" + n.Token.Literal
if n.Left != nil {
// iota enumerator gives an effective way in go language
// to use constants in enum-like constructs
const (
none = iota
plus
mul
)
// enum-like map of operator token keys and iota values defined above
var precendences = map[string]int{
token.PLUS: plus,
func led(left ast.Node, operator token.Token, right ast.Node) *ast.Node {
return &ast.Node{Left: &left, Token: &operator, Right: &right}
}
@korzio
korzio / main.go
Last active February 6, 2021 18:12
package main
import (
"fmt"
"os"
"os/user"
"pizzascript/repl"
)
func main() {
@korzio
korzio / repl.go
Last active February 6, 2021 18:12
package repl
import (
"bufio"
"fmt"
"io"
"pizzascript/eval"
"pizzascript/lexer"
"pizzascript/parser"
)
@korzio
korzio / token.go
Last active February 6, 2021 18:11
package token
type TokenType string
type Token struct {
Type TokenType
Literal string
}
const (
// Literals