Skip to content

Instantly share code, notes, and snippets.

View greister's full-sized avatar
🎯
Focusing

greister

🎯
Focusing
View GitHub Profile
@greister
greister / gist:72c9c0bf3c78d7745bce146f8de2a0a7
Created August 11, 2016 10:31
Use regex extracting urls from text file.
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 11 15:55:44 2016
@author: Cat
"""
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import requests
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import requests
#import urlextractor
import re
import string
# utils.py
@greister
greister / You cannot unwrap an Arc that you don't own
Last active May 11, 2016 00:22 — forked from anonymous/playground.rs
You cannot unwrap an Arc that you don't own
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>>>;
@greister
greister / trait aliases
Last active May 8, 2016 03:49 — forked from anonymous/playground.rs
Shared via Rust Playground
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 { }
// 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()
@greister
greister / List.len by using "Deref".rs
Last active April 30, 2016 09:04 — forked from anonymous/playground.rs
Shared via Rust Playground
// 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>;
@greister
greister / aatch change impl panic funtion
Last active April 26, 2016 14:53 — forked from anonymous/playground.rs
Shared via Rust Playground
// 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,
}
@greister
greister / playground.rs
Created April 25, 2016 14:30 — forked from anonymous/playground.rs
Shared via Rust Playground
struct Book {
name: String
}
impl Book {
fn show_book_name(&self) {
println!("Name is : {}", self.name);
}
}
@greister
greister / playground.rs
Created April 23, 2016 17:49 — forked from anonymous/playground.rs
Shared via Rust Playground
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);
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
}