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 / AoC22D1.md
Last active September 9, 2023 07:46
Advent of Code 2022 Day 1

Part 1 (Rust)

fn main() {
    let mut result = 0;
    let mut buffer = 0;
    DATA.lines().for_each(|line| {
        if line.is_empty() {
            if buffer > result {
                result = buffer;
@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 / AoC22D2.md
Last active July 28, 2023 05:43
Advent of Code 2022 Day 2