Skip to content

Instantly share code, notes, and snippets.

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

Renkai Ge Renkai

🤓
提升姿势水平中
View GitHub Profile
@Renkai
Renkai / Main2.scala
Last active November 14, 2016 12:35
/**
* Created by renkai on 16/9/7.
*/
object Main2 {
def isSingleton[A](a: A)(implicit ev: A <:< Singleton = null) = {
Option(ev).isDefined
}
@Renkai
Renkai / sbt_repositories
Created January 5, 2017 09:23
put it to ~/.sbt/repositories
[repositories]
local
maven-local
aliyun: http://maven.aliyun.com/nexus/content/groups/public
maven-central
sbt-maven-releases: https://repo.scala-sbt.org/scalasbt/maven-releases/, bootOnly
sbt-maven-snapshots: https://repo.scala-sbt.org/scalasbt/maven-snapshots/, bootOnly
typesafe-ivy-releases: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
sbt-ivy-snapshots: https://repo.scala-sbt.org/scalasbt/ivy-snapshots/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly
import sys
import getpass
import os
import pexpect
hosts = ['']
user = raw_input("type in the username:")
password = getpass.getpass('type in the password:')
expect_list = ['(yes/no)', 'password:']
@Renkai
Renkai / build.gradle.kts
Created August 22, 2018 08:17
create fat jar with gradle kotlin dsl
tasks.create<Jar>("fatJar") {
appendix = "fat"
setDuplicatesStrategy(DuplicatesStrategy.FAIL)
manifest {
attributes(mapOf("Main-Class" to "Main")) // replace it with your own
}
val sourceMain = java.sourceSets["main"]
from(sourceMain.output)
configurations.runtimeClasspath.filter {
@Renkai
Renkai / resetkafka.scala
Created September 12, 2018 06:20
reset kafka offset to specific timestamp
import java.time.{Instant, ZoneId, ZonedDateTime}
import java.util.Properties
import org.apache.kafka.clients.consumer.KafkaConsumer
import org.apache.kafka.common.TopicPartition
import org.apache.kafka.common.serialization.StringDeserializer
import scala.collection.JavaConverters._
object KafkaResetSample {
@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
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 / 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()
@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,
};
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);