Skip to content

Instantly share code, notes, and snippets.

View soyart's full-sized avatar

Prem Phansuriyanon soyart

View GitHub Profile
#![allow(dead_code)]
use customers; // brings module customers to scope, from file ./customers.rs
use rand::Rng;
pub fn waiter_jobs() {
// crate::front::serving::take_order(); // crate points to this crate root
front::serving::take_order();
front::serving::deliver_to_kitchen();
crate::front::serving::bring_order();
use std::collections::HashMap;
fn main() {
// Arrays - fixed size known at compile time
let rust_array = [1, 2, 3];
// Simple iteration with for-in
for item in rust_array {
println!("{}", item);
}
// Iterate like Go's for-range with enumerate()
#![allow(dead_code)]
#![allow(unused)]
use std::fs::File;
use std::io::{prelude::*, ErrorKind, Read, BufReader};
use std::io;
fn main() {
let fname = ".gitignore";
fn get_largest<T: PartialOrd + Copy>(v: Vec<T>) -> T {
let mut largest = v[0];
for item in v {
if largest > item {
largest = item
};
};
largest
}
@soyart
soyart / alert.go
Last active June 23, 2022 16:20
Code for practicing alerting
package main
import (
"crypto/rand"
"fmt"
"math/big"
"strings"
"time"
)
@soyart
soyart / simple_alert.go
Last active June 27, 2022 05:46
Practice code for alerting with varying intervals for different severity levels
package main
import (
"crypto/rand"
"fmt"
"math/big"
"strings"
"time"
)
@soyart
soyart / flatten.rs
Created January 24, 2023 20:18
Basic Rust `Iterator` and `DoubleEndedIterator` implementation on nested flattener.
#![allow(dead_code)]
// Basic Rust `Iterator` and `DoubleEndedIterator` implementation on nested flattener.
struct Flattener<O>
where
O: Iterator,
O::Item: IntoIterator,
{
outter: O,
@soyart
soyart / draw_down.rs
Last active March 10, 2023 17:08
Draw down, i.e. financial securiry performance indicator
// Generic draw down
fn draw_down<T, U>(points: &[T]) -> U
where
T: Clone + Into<U>,
U: Copy + Default + PartialOrd + std::ops::Sub<Output = U>,
{
if points.len() <= 1 {
return U::default();
}
@soyart
soyart / dewhite.c
Created October 1, 2023 15:42
K&R exercise 1-18
#include <stdio.h>
#define MAXLEN 1000
/* Avoid confilic with stdio.h */
int _getline(char line[], int limit);
int main(void) {
char line[MAXLEN];
int i, j, c, len;
@soyart
soyart / rama9sort.c
Last active October 3, 2023 11:56
Rama IX sort (`rama9sort`) - a Thai sorting algorithm in homage to the late Thai God-King
/*
Rama 9 Sort (rama9sort)
rama9sort is a highly efficient (and sufficient) sorting algorithm that runs in constant time and space (O(1)).
rama9sort got its inspiration from Stalin Sort (another highly efficient algorithm).
rama9sort borrows ideas from Stalin Sort - unwanted/unordered elements are discarded right away from the input,
although rama9sort has some other _unorthodox_ checks to make it more suitable for deployment in Thailand.
The differences from Stalin Sort are: