This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from copy import deepcopy | |
import json | |
from confluent_kafka.schema_registry import SchemaRegistryClient | |
from confluent_kafka.schema_registry.avro import AvroSerializer, AvroDeserializer | |
from confluent_kafka.serialization import StringSerializer, SerializationContext, MessageField | |
KAFKA_HOST = 'localhost' | |
schema_registry_conf = {'url': f'http://{KAFKA_HOST}:8081'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging, sys | |
from pyflink.common import WatermarkStrategy, Row | |
from pyflink.common.serialization import Encoder | |
from pyflink.common.typeinfo import Types | |
from pyflink.datastream import StreamExecutionEnvironment | |
from pyflink.datastream.connectors import FileSink, OutputFileConfig, NumberSequenceSource | |
from pyflink.datastream.execution_mode import RuntimeExecutionMode | |
from pyflink.datastream.functions import KeyedProcessFunction, RuntimeContext, MapFunction, CoMapFunction, CoFlatMapFunction | |
from pyflink.datastream.state import MapStateDescriptor, ValueStateDescriptor | |
from pyflink.common import JsonRowDeserializationSchema, JsonRowSerializationSchema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flowchart LR | |
core[(Core)] | |
cart[(Cart)] | |
other[(Others)] | |
bq[(BigQuery)] | |
rt[[Realtime events including CDC]] | |
pg[(Postgres)] | |
api[Shoplytics] | |
user(((User))) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("fast-check test", () => { | |
before(async () => { | |
// generate 10 random records | |
}); | |
it("#1", async () => { | |
const result = await getMoney(100); | |
expect(result.length).to.be.equal(10); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const events = require('events'); | |
const emitter = new events.EventEmitter(); | |
emitter.on('purchased', function(user, total) { | |
if (total >= 1000) { | |
giveCoupon(cart.user, total); | |
} | |
}); | |
emitter.on('purchased', function(user, total) { | |
if (ok && total >= 5000) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const expect = require("chai").expect; | |
const table = [10, 10, 15, 15, 30, 30, 100]; | |
const boxTable = [0, 1, 0, 0, 1, 0, 1]; | |
const dateDiff = (sD1, sD2) => { | |
const d1 = new Date(sD1); | |
const d2 = new Date(sD2); | |
d1.setHours(0, 0, 0, 0); | |
d2.setHours(0, 0, 0, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const os = require('os'); | |
// Take the first CPU, considering every CPUs have the same specs | |
// and every NodeJS process only uses one at a time. | |
const cpus = os.cpus(); | |
const cpu = cpus[0]; | |
// Accumulate every CPU times values | |
const total = Object.values(cpu.times).reduce( | |
(acc, tv) => acc + tv, 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let lastid = "0-0"; | |
let checkBacklog = true | |
while (true) { | |
const myid = checkBacklog ? lastid : ">"; | |
const items = await redis.xreadgroup('GROUP',GroupName,ConsumerName,'BLOCK','2000','COUNT','10','STREAMS',StreamName,myid); | |
if (!items) continue; | |
checkBacklog = !(items[0][1].length == 0); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Scan(list *sql.Rows) (rows []map[string]interface{}) { | |
fields, _ := list.Columns() | |
for list.Next() { | |
scans := make([]interface{}, len(fields)) | |
row := make(map[string]interface{}) | |
for i := range scans { | |
scans[i] = &scans[i] | |
} | |
list.Scan(scans...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type DiningPhilosophers struct { | |
wg *sync.WaitGroup | |
n int | |
forks [5]sync.Mutex | |
ate [5]int | |
} | |
func (obj *DiningPhilosophers) checkAll() bool { | |
end := true | |
for i := 0 ; i < len(obj.ate) ; i++ { |
NewerOlder