Skip to content

Instantly share code, notes, and snippets.

View arthurbacci's full-sized avatar

Arthur Bacci arthurbacci

  • Rio de Janeiro
  • 11:06 (UTC -03:00)
View GitHub Profile
import Control.Monad.State.Lazy
import Text.Printf
aprox :: Double -> State Double Double
aprox t = state (\y ->
let add = (t - x) * (1.0 - y) / (10.0 - x)
x = 10.0 ** y
in (t - x, y + add))
combine_x_times :: (Monad m) => Int -> m a -> m a
@arthurbacci
arthurbacci / async-input.rs
Created April 9, 2021 22:17
A example of async input using threads in Rust
use std::thread;
use std::sync::mpsc::{self, TryRecvError};
use std::io;
use std::time::Instant;
struct CircularIter<T> where T: Copy {
data: Vec<T>,
index: usize,
}
@arthurbacci
arthurbacci / main.rs
Last active April 7, 2021 22:32
S-expr parser in Rust
use std::io::{self, Write};
fn main() {
loop {
print!("repl>");
io::stdout().flush().expect("Could not flush stdout");
let mut line = String::new();
io::stdin().read_line(&mut line).expect("Could not read from stdin");
@arthurbacci
arthurbacci / replace-all.c
Created January 27, 2021 13:42
Replace all substrings in a string
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *replace_substring_in_string(char *str, char *from, char *to)
{
char *result;
unsigned int str_len, from_len, to_len;
str_len = strlen(str);
@arthurbacci
arthurbacci / replace.c
Created January 27, 2021 01:11
Replaces a substring from a string
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *replace_substring_in_string(char *str, char *from, char *to)
{
char *result;
unsigned int str_len, from_len, to_len;
str_len = strlen(str);