Skip to content

Instantly share code, notes, and snippets.

View wirelessr's full-sized avatar

ChunTing Wu wirelessr

  • Taiwan
View GitHub Profile
"""
Install the Google AI Python SDK
$ pip install google-generativeai
See the getting started guide for more information:
https://ai.google.dev/gemini-api/docs/get-started/python
"""
import os
@wirelessr
wirelessr / changepoints_detection.py
Last active June 20, 2024 04:32
PELT Changepoints Detection
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from ruptures import Pelt
from scipy.stats import ttest_ind
# Generate synthetic data with clear changepoints
np.random.seed(42)
timestamps = pd.date_range('2023-10-26', periods=60, freq='D')
latency = np.concatenate([
@wirelessr
wirelessr / schema-registry-test.py
Created March 29, 2023 07:36
Real Experiment of AVRO and Schema Registry
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'}
@wirelessr
wirelessr / pyflink_connect_example.py
Last active October 19, 2022 02:59
PyFlink Connect Example
@wirelessr
wirelessr / trd1
Last active September 23, 2022 03:04
flowchart LR
core[(Core)]
cart[(Cart)]
other[(Others)]
bq[(BigQuery)]
rt[[Realtime events including CDC]]
pg[(Postgres)]
api[Shoplytics]
user(((User)))
@wirelessr
wirelessr / fast-check.example.js
Created May 10, 2022 08:30
fast-check examples
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);
});
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) {
@wirelessr
wirelessr / design_in_clean_architecture_way.js
Last active January 25, 2022 06:02
How to Design in Clean Architecture Way, Part 2
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);
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
@wirelessr
wirelessr / redis_stream_worker.js
Created November 18, 2021 13:21
A doable worker in Redis Stream
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);