Skip to content

Instantly share code, notes, and snippets.

View mingyang91's full-sized avatar
🎯
Go for broke

Ming Yang mingyang91

🎯
Go for broke
View GitHub Profile
@mingyang91
mingyang91 / bullet.rs
Last active February 28, 2024 14:44
Object Pool for Godot
impl ReuseObject for Bullet {
fn init(&mut self) {
}
fn prepare(&mut self) {
if self.state != State::Init {
self.state = State::Init;
self.base_mut().set_process(true);
@mingyang91
mingyang91 / compare_concurrency_control.kt
Last active December 22, 2023 08:01
Compare concurrency control in Coroutine VS Reactive VS VirtualThread(a.k.a Loom)
package org.example
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
import org.openjdk.jmh.annotations.*
import java.util.concurrent.TimeUnit
@mingyang91
mingyang91 / chat.md
Created September 13, 2023 09:21
Chat with GPT(New Bing)

Me:

this is my dockerfile, could you please tell me why the OS cannot find libpython so?

# Build stage
FROM rust:bookworm as builder

# Install python3.11 and build dependencies
RUN apt-get update
RUN apt-get install -y software-properties-common
#RUN add-apt-repository ppa:deadsnakes/ppa
package lsbf.fm;
import java.util.Optional;
public class Tree {
public static void main(String[] args) {
Node<Integer> root = new Node<>(5);
root = new Node<>(5, Optional.of(new Node<>(1)), Optional.of(new Node<>(10)));
System.out.println(root.getLeft().get().getValue());
System.out.println(root.getRight().get().getValue());
@mingyang91
mingyang91 / ICRP phatom voxel to fluka.ipynb
Last active January 23, 2023 13:30
P110 & P143, translate from fortran version
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mingyang91
mingyang91 / immutable-avl.rs
Last active September 21, 2023 10:09
Immutable AVL tree
#![feature(let_else)]
use std::cmp::Ordering;
use std::fmt::{Display, Formatter};
use std::sync::Arc;
pub enum Root<K, V> {
Empty,
More(Arc<Node<K, V>>)
}
@mingyang91
mingyang91 / leetcode-138.scala
Created August 8, 2022 08:53
138. Copy List with Random Pointer
/**
* Definition for a Node.
* class Node(var _value: Int) {
* var value: Int = _value
* var next: Node = null
* var random: Node = null
* }
*/
import scala.collection.mutable._
class V2EX_stream {
public List<String> getForeignKeyTable(List<String> tableNames,
DataSourceEntity info,
List<ForeignKeyInfo> foreignKeyInfos) {
var childTables = tableNames.stream()
.map(tableName -> findAllTable(info.getDataBaseName(), tableName))
.filter(column -> !DB_KEYWORD_SET.contains(column.getColumnName().toUpperCase()))
.flatMap(columnInfo -> foreignKeyInfos.stream()
.filter(it -> it.getSourceTableName().equals(columnInfo.getTableName()) &&
@mingyang91
mingyang91 / vson.scala
Created July 26, 2022 03:47
This code is totally electronic trash for solving an issue at V2EX, please don't use it in your production environment.
//
object Vson extends RegexParsers:
val string: Parser[String] = """[^,:}]+""".r ^^ { str => str.trim }
val int: Parser[Int] = """-?\d+""".r ^^ (_.toInt)
val double: Parser[Double] = """-?\d+\.\d+""".r ^^ (_.toDouble)
val bool: Parser[Boolean] = "true" ^^^ true | "false" ^^^ false
def pair: Parser[(String, Json)] = (string <~ ":") ~ value ^^ { case k ~ v => (k, v) }
def obj: Parser[Json] = "{" ~> repsep(options | pair, ",") <~ "}" ^^ Json.fromFields
def tuple: Parser[(Int, String, String)] = ((int <~ ":") ~ string <~ ":") ~ string ^^ { case k ~ v1 ~ v2 => (k, v1, v2) }
def array: Parser[List[(Int, String, String)]] = repsep(tuple, ",")
@mingyang91
mingyang91 / SumTwoCaseClass.scala
Last active July 19, 2022 14:34
Sum two case class in scala3
@experimental
object Test extends App :
val a = CCA("a", 2, 3.0)
val b = CCB(4.5, 128.toByte)
val res = sum[CCA, CCB, CCC](a, b)
println(res)
@experimental
def sum[A <: Product, B <: Product, C <: Product](a: A, b: B)