This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Thu Aug 11 15:55:44 2016 | |
@author: Cat | |
""" | |
#!/usr/bin/python | |
# -*- coding: UTF-8 -*- | |
import requests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: UTF-8 -*- | |
import requests | |
#import urlextractor | |
import re | |
import string | |
# utils.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::sync::{Arc, RwLock}; | |
use std::collections::HashMap; | |
use std::hash::Hash; | |
use std::cmp::Eq; | |
trait SessionStore<K, V> { | |
fn remove(&self, key: &K) -> bool; | |
} | |
type Store<K, V> = RwLock<HashMap<K, RwLock<V>>>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fmt::{Debug}; | |
use std::ops::Add; | |
use std::num::{Zero, One}; | |
trait Numeric : 'static + Debug + Clone + Zero + One { } | |
} | |
impl<T> Numeric for T where T : 'static + Debug + Clone + Zero + One { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// incoming packet handler and reconnection thread | |
thread::spawn(move || { | |
// get underlying tcpstream clone from connection object | |
let mut _stream_pkt_hndlr_thrd = { | |
let ref connection = *_client_pkt_hndlr_thrd.connection.lock().unwrap(); | |
let stream = match connection.stream { | |
Some(ref s) => s, | |
None => panic!("No stream found in the connectino"), | |
}; | |
stream.try_clone().unwrap() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define a structure named `List` containing a `Vec`. | |
use std::fmt; | |
use std::ops::Deref; | |
struct List(Vec<i32>); | |
impl Deref for List { | |
type Target = Vec<i32>; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://rosettacode.org/wiki/Define_a_primitive_data_type | |
/// Implements a custom type named CustomInt. | |
/// One problem that I'm not sure how to solve is bounds checking on variable assignments. | |
/// This type only implements a subset of all traits within std::ops. | |
use std::ops; | |
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Copy, Clone)] | |
pub struct CustomInt { | |
value: u8, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Book { | |
name: String | |
} | |
impl Book { | |
fn show_book_name(&self) { | |
println!("Name is : {}", self.name); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn get_c() -> Box<FnMut(i32)> { | |
Box::new(|val: i32| { | |
println!("value --> {}", val); | |
}) | |
} | |
pub fn set_c<F>(mut callback: F) | |
where F: FnMut(i32) | |
{ | |
callback(100); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::sync::Arc; | |
use std::rc::Rc; | |
use std::fmt::Debug; | |
use std::cell::RefCell; | |
#[derive(Debug, PartialEq, Clone, Copy)] | |
enum NodeType{ | |
Node, | |
Leaf | |
} |