Skip to content

Instantly share code, notes, and snippets.

View soyart's full-sized avatar

Prem Phansuriyanon soyart

View GitHub Profile
@soyart
soyart / permute.go
Created October 1, 2024 18:37
All permutations
package main
import (
"fmt"
)
func main() {
r := permutation([]byte("abcdef"))
for i := range r {
pront(r[i])
@soyart
soyart / 1-10.c
Last active June 12, 2024 19:10
K&R C exercises
#include <stdio.h>
void unescape(void);
int main(void)
{
printf("knr 1-10\n");
printf("Unescape special characters\n");
unescape();
@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:
@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 / 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 / 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 / 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 / alert.go
Last active June 23, 2022 16:20
Code for practicing alerting
package main
import (
"crypto/rand"
"fmt"
"math/big"
"strings"
"time"
)
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
}
#![allow(dead_code)]
#![allow(unused)]
use std::fs::File;
use std::io::{prelude::*, ErrorKind, Read, BufReader};
use std::io;
fn main() {
let fname = ".gitignore";