Skip to content

Instantly share code, notes, and snippets.

View ming900518's full-sized avatar

Ming Chang ming900518

View GitHub Profile
@ming900518
ming900518 / main.rs
Created December 27, 2023 07:19
Rust SIMD mul operation test
#![feature(portable_simd)]
use rand::random;
use std::{array::from_fn, simd::Simd, time::Instant};
#[inline]
fn main() {
let test: [f32; 64] = from_fn(|_| random());
let random_magic: f32 = random();
let test_2: [f32; 64] = [random_magic; 64];
println!("Data for test: {test:?}");
@ming900518
ming900518 / main.rs
Created December 27, 2023 01:02
Rust Async Closure Test
#![feature(async_closure)]
use futures_util::future::join_all;
use std::{iter::zip, time::Duration};
use tokio::time::sleep;
#[tokio::main]
async fn main() {
let ids = [1, 2, 3, 4];
let durations = [200, 100, 300, 250];
@ming900518
ming900518 / mongo-transaction-with-ts-using.md
Last active September 8, 2023 08:05
MongoDB Transaction with TypeScript 5.2 `using` keyword
@ming900518
ming900518 / index.md
Created September 4, 2023 07:40
Express API with queue

Express API with queue

import express, { Application, Request, Response } from "express";

const app: Application = express();

const queue: Array<[number, string]> = new Array();
const result: Array<[number, string | null]> = new Array();

app.post("/:data", (req: Request, res: Response) => {
@ming900518
ming900518 / AoC22D6.md
Last active August 13, 2023 06:23
Advent of Code 2022 Day 6

Part 1 (Scala)

def part1(input: String) = {
  val index = input
    .toCharArray()
    .sliding(4)
    .zipWithIndex
    .map((chars, i) => (chars, i + 4))
 .find((chars, _) =&gt; chars.distinct.length == 4)
@ming900518
ming900518 / AoC22D5.md
Last active July 30, 2023 08:33
Advent of Code 2022 Day 5

Parsers (Scala)

def parseInput(input: String): List[ArrayBuffer[String]] = {
  val result = List(
    ArrayBuffer[String](),
    ArrayBuffer[String](),
    ArrayBuffer[String](),
    ArrayBuffer[String](),
    ArrayBuffer[String](),
@ming900518
ming900518 / AoC22D4.md
Created July 29, 2023 11:29
Advent of Code 2022 Day 4

Part 1 (Scala)

@main def main = {
    part1(input)
}

def part1(input: String) = {
  var count = 0;
  input.linesIterator.foreach((line) => {
@ming900518
ming900518 / AoC22D3.md
Created July 29, 2023 09:29
Advent of Code 2022 Day 3

Part 1 (Scala)

@main def main = {
    part1(input)
}

def part1(input: String) = {
  val result = input.linesIterator.map((line) => {
 val (first, second) = line.splitAt(line.length() / 2);
@ming900518
ming900518 / index.js
Last active July 17, 2023 06:26
Node.js 利用 Web Crypto API 產生 RSA 公私鑰範例
const { subtle } = require("node:crypto").webcrypto;
const { writeFileSync } = require("node:fs");
subtle
.generateKey(
{
name: "RSA-OAEP",
modulusLength: 2048,
publicExponent: new Uint8Array([1, 0, 1]),
hash: "SHA-256"
@ming900518
ming900518 / LeetCode 21 - Merge Two Sorted Lists.md
Created June 29, 2023 01:16
LeetCode 21 - Merge Two Sorted Lists

LeetCode 21 - Merge Two Sorted Lists

Rust Implementation

ListNode struct

#[derive(Debug)]
pub struct ListNode {
    pub val: i32,
    pub next: Option<Box<ListNode>>,