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 / 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)
@mingyang91
mingyang91 / template code.scala
Created March 19, 2018 13:02
尝试移除模板代码
// utils
class FromJsonQueryStringBindable[T] ()(implicit decoder: Decoder[T],
encoder: Encoder[T]) extends QueryStringBindable[T] {
implicit val binder: QueryStringBindable[Json] = JsonQueryStringBindable
override def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, T]] =
binder.bind(key, params).map(_.flatMap(_.as[T].left.map(_.message)))
override def unbind(key: String, value: T): String = s"$key=${value.asJson}"
}
λ curl -X POST \
http://chouun.nadileaf.com/api/open-candidates/ \
-H 'authorization: Bearer <TOKEN>' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: 1c12fc65-c157-49c7-d9d4-d2ad10832c53' \
-d '
{
"openid": "b39fe420-d67e-11e7-a5de-0250bbe96648",
"industry":"互联网",

Keybase proof

I hereby claim:

  • I am mingyang91 on github.
  • I am famer (https://keybase.io/famer) on keybase.
  • I have a public key ASAcRGRvhvMiRo4EgLphpfDpKuYzf6vEdGhR6TOw1igV6go

To claim this, I am signing this object:

@mingyang91
mingyang91 / deriv.rkt
Last active March 1, 2016 09:45
<SICP> 2.3
#lang racket
(define variable? symbol?)
(define (same-variable? v1 v2)
(and (variable? v1) (variable? v2) (eq? v1 v2)))
(define (=number? exp num)
(and (number? exp) (= exp num)))
@mingyang91
mingyang91 / 1.3.scm
Last active December 2, 2015 15:14
<SICP> 1.3
#lang scheme
(define (average . numbers)
(/ (apply + numbers) (length numbers)))
(define tolerance 0.000001)
(define (fixed-point f first-guess)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance))
(define (try guess)