Skip to content

Instantly share code, notes, and snippets.

@fero23
fero23 / async_poc.rs
Last active June 26, 2016 21:21
Proof of concept design for an async library
use std::marker::PhantomData;
use std::sync::{Arc, Mutex};
use std::thread;
//use std::alloc::arc::Weak;
#[derive(Debug)]
enum Promise<O> {
Awaiting,
ResultValue(Arc<Mutex<O>>)
}
@fero23
fero23 / RssCompilatorFrontEnd.elm
Last active June 17, 2016 19:51
Reactive front-end for an RSS compilator using Elm.
import Html exposing (..)
import Html.App as Html
import Html.Attributes exposing (href, style, target)
import WebSocket
import Json.Decode exposing (..)
import Time exposing (Time)
import Date exposing (..)
import List exposing (append, sortBy, reverse)
import String exposing (pad)
@fero23
fero23 / bytevec_bincode_comparison.rs
Created May 31, 2016 03:19
Comparison of bytevec and bincode
extern crate bincode;
extern crate rustc_serialize;
#[macro_use]
extern crate bytevec;
use bincode::SizeLimit;
use bincode::rustc_serialize::{encode, decode};
use bytevec::{ByteDecodable, ByteEncodable};
bytevec_impls! {
@fero23
fero23 / unsafe_copy.rs
Created May 25, 2016 17:18
Unsafe copy using a byte buffer with Rust
#[derive(PartialEq, Eq)]
struct Person {
id: u32,
name: String,
last_name: String
}
fn main() {
let p1 = Person {
id: 1,
use std::collections::HashMap;
trait Resolver {
type Input;
fn resolve<'a, T: FromInput<Self::Input>>(&self, name: &'a str) -> T;
}
trait FromInput<T> {
fn from(s: T) -> Self;
}
@fero23
fero23 / multisort.rs
Last active May 15, 2016 01:55
Multiple sorting algorithms implemented using Rust
fn main() {
let vec = vec![23,6,2,7,8,43,3,7,9,2];
println!("Shellsort: {:?}", vec.clone().shellsort());
println!("Quicksort: {:?}", vec.clone().quicksort());
println!("Heapsort : {:?}", vec.clone().heapsort());
}
trait MultiSort {
fn shellsort(&mut self) -> &mut Self;
fn quicksort(&mut self) -> &mut Self;
@fero23
fero23 / maximum_flow.rs
Created April 29, 2016 21:03
A maximum flow algorithm solution
const START: usize = 1;
const END: usize = 5;
fn main() {
/*let mut edges = [
(1, 3, 6, 6),
(1, 2, 5, 5),
(1, 4, 5, 5),
(2, 5, 3, 3),
@fero23
fero23 / list_parser.rs
Created April 28, 2016 06:00
A rust parser example that parses a list of processes into html tables
#[macro_use]
extern crate rspc;
extern crate chrono;
use rspc::parsers::{Parser, ParserOps, number, string, ws, letter, not_of, character};
use rspc::parsers::combinators::many1;
use rspc::context::StringSource;
use std::fs::File;
use std::io::Read;
@fero23
fero23 / s_expr.rs
Last active April 23, 2016 18:50
S-Expr proof of concept test on my rspc library
#[macro_use]
extern crate rspc;
use std::fmt::{Display, Formatter};
use rspc::parsers::{Parser, ParserOps, ws, character, alphanumeric};
use rspc::parsers::combinators::many1;
use rspc::context::StringSource;
#[derive(PartialEq, Debug)]
enum Tree<T> {
@fero23
fero23 / nqueen.rs
Last active April 13, 2016 15:31
A Rust implementation of the solution of the N-Queen puzzle
use std::collections::LinkedList;
use std::iter::IntoIterator;
fn main() {
for (n, s) in NQueens::new(8).enumerate() {
println!("Solution #{}:\n{}\n", n + 1, s.to_string());
}
}
fn permutations<'a, T, I>(collection: I) -> Box<Iterator<Item=LinkedList<T>> + 'a>