Skip to content

Instantly share code, notes, and snippets.

View Noxivs's full-sized avatar

Noxivs Noxivs

  • Toulouse, France
View GitHub Profile
@Noxivs
Noxivs / CompilableTree.cs
Created October 22, 2013 16:57
Compiled tree written in C#.Net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace Trees
{
public class CompilableTree<TKey, TValue>
{
protected readonly CompilableTree<TKey, TValue> _parent;
@Noxivs
Noxivs / main.rs
Last active August 29, 2015 13:59
simple tcp server
use std::io::net::ip::{Ipv4Addr, SocketAddr};
use std::io::net::tcp::{TcpListener, TcpStream};
use std::io::{Acceptor, Listener, IoResult};
struct Client {
stream: TcpStream
}
extern crate time;
use std::io::{Listener, Acceptor};
use std::io::net::tcp::{TcpListener};
use std::io::net::ip::{SocketAddr, Ipv4Addr};
use std::io::timer;
static TICK_TIME: i32 = 60; //ms
fn tick(last_tick: &mut i32) {
@Noxivs
Noxivs / tree.rs
Last active August 29, 2015 14:03
/// # Example
///
/// ```rust
/// fn main() {
/// let mut tree = Tree::<char,String>::new();
/// tree.insert_recursively(&vec!('H', 'C'), "HandleHelloConnectMessage".into_string());
/// tree.insert_recursively(&vec!('H', 'G'), "HandleHelloGameMessage".into_string());
///
/// println!("{}", tree.find_recursively(&vec!('H', 'G')).unwrap());
/// println!("{}", tree.find_recursively(&vec!('H', 'C')).unwrap());
use std::io::{MemReader, MemWriter,IoResult, IoError, InvalidInput};
trait StringReader {
fn read_le_string(&mut self) -> IoResult<String>;
}
impl StringReader for MemReader {
fn read_le_string(&mut self) -> IoResult<String> {
let str_b_len = self.read_le_u16();
match str_b_len {
#![feature(quote)]
extern crate syntax;
extern crate rustc;
use std::collections::HashMap;
use std::hash::Hash;
use std::gc::{Gc, GC};
use std::ascii::{AsciiCast, AsciiStr};
use std::comm::TryRecvError;
use std::io::net::tcp::TcpStream;
static NEW_LINE_CHAR: u8 = 0x0a;
static END_LINE_CHAR: u8 = 0x00;
static MAX_BUFFER_LENGHT: uint = 8192;
#[handler="3"]
pub fn handle_hello_connect(client: Client, cx: Context, msg: ClientMessage) {
/* ... */
}
#[deriving(Clone)]
pub type Handler = fn(client: Client, cx: Context, msg: ClientMessage) -> ();
pub struct HelloConnectMessage {
salt: String,
key: Vec<u8>
}
impl HelloConnectMessage {
pub fn salt<'a>(&self) -> &'a String {
&self.salt
}
#![feature(macro_rules)]
macro_rules! grammar(
($name:expr,$x:expr) => ( /* parser + generate function */)
)
grammar!("url", "
rule TOP {
<protocol>'://'<address>
}