Skip to content

Instantly share code, notes, and snippets.

View Renkai's full-sized avatar
🤓
提升姿势水平中

Renkai Ge Renkai

🤓
提升姿势水平中
View GitHub Profile
@Renkai
Renkai / bilibili_cache_converter.py
Last active April 29, 2023 09:15
Convert your bilibili local cache to mp4
import subprocess
import shlex
import json
import sys
from pathlib import Path
from numpy import fromfile, uint8 # pip install numpy
ROOT = Path(sys.argv[0]).resolve().parent
for dir in ROOT.iterdir():
if not dir.name.startswith("22"):
@Renkai
Renkai / method_from_name.py
Created April 24, 2022 08:39
python run method from name
import base64
import json
import sys
demo_obj = {
'module_name': "spock_spore_engine.tasks.demo_task",
'class_name': "DemoTask",
'class_args': [],
'class_kwargs': {
@Renkai
Renkai / timed_flow.scala
Created April 6, 2021 13:25
Demo to measure time consumption of a flow
object TimedFlow {
def apply[In, Out](innerFlow: Flow[In, Out, NotUsed], func: (Long, Long) => Any): Flow[In, Out, NotUsed] = {
val flowWithLong = Flow.fromGraph(GraphDSL.create() {
implicit builder =>
import akka.stream.scaladsl.GraphDSL.Implicits._
val unzip = builder.add(Unzip[In, Long]())
val zip = builder.add(Zip[Out, Long]())
unzip.out0 ~> innerFlow ~> zip.in0
unzip.out1 ~> zip.in1
@Renkai
Renkai / rm_outdated_m2.sh
Created December 3, 2020 01:48
remove outdated m2 cache
find ~/.m2/repository/ -atime +1 -iname '*.pom' -print0 | while read -d '' -r pom; do echo rm -rf "$(dirname $pom)"; done
@Renkai
Renkai / pip.md
Last active November 30, 2020 02:37
PIP: Configurable data source priority for offloaded messages

Motivation

Currently, if the data in pulsar was offloaded to the second storage layer, data can still exists in bookkeeper for a period of time, but the client will directly read data from the second layer.

This may lead to several problems:

  • Read from second layer have different performance characteristics, which may lead wrong estimate from users if they didn't know which layer they are reading.
  • The second layer may be managed by another team rather than Pulsar management team(for example, a independent HDFS management team), they may have independent quota or authority policy to users.
  • The second layer storage can be infinite in theory, if user set cursor to an error time in accident, it will cause a lot of resource waste.
fn encode_spans(rx : CollectorRx) -> impl Iterator<Item = spanpb::Span> {
let finished_spans = rx.collect();
let spans = finished_spans.into_iter().map(|span| {
let mut s = spanpb::Span::default();
s.set_id(span.id.into());
s.set_start(span.elapsed_start);
s.set_end(span.elapsed_end);
s.set_event_id(span.tag);
@Renkai
Renkai / fetch_by_offset.rs
Created February 7, 2020 07:50
fetch reference by offset
struct Foo {
x: u32,
y: f64,
}
fn main() {
let foo = Foo {
x: 1,
y: 1.024,
};
@Renkai
Renkai / executionpool.scala
Last active August 21, 2019 06:20
give a execution fixed thread execution context
val pool = Executors.newFixedThreadPool(16)
implicit val ec = ExecutionContext.fromExecutor(pool)
pool.shutdown()
def compress(input: Array[Byte]): Array[Byte] = {
val bos = new ByteArrayOutputStream(input.length)
val gzip = new GZIPOutputStream(bos)
gzip.write(input)
gzip.close()
val compressed = bos.toByteArray
bos.close()
compressed
}
@Renkai
Renkai / build.gradle.kts
Created July 24, 2019 07:46
java and scala call each other, and create fatjar for gradle 5.5 kotlin dsl
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* User Manual available at https://docs.gradle.org/5.5.1/userguide/tutorial_java_projects.html
*/
plugins {
// Apply the java plugin to add support for Java