Skip to content

Instantly share code, notes, and snippets.

View greister's full-sized avatar
🎯
Focusing

greister

🎯
Focusing
View GitHub Profile
@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 / 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 / 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>;
// 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 / 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 { }
@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>>>;
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import requests
#import urlextractor
import re
import string
# utils.py
@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
@greister
greister / article.md
Created August 29, 2016 13:27 — forked from punmechanic/article.md
static-vs-dynamic-dispatch.md

Static vs Dynamic dispatch

AKA: Why is consuming an Iterator from glutin so damn hard?


In Rust, like many other languages, there are two different ways to call a function: static and dynamic dispatch. They're used in different scenarios and each have their own pros and cons, which are summarised thusly:

  1. Static calls tend to be faster because they do not require the use of a lookup table, which incurs overhead as the compiler has to 'find' the function it is calling at runtime.
  2. Dynamic calls tend to be more conservative of space as they can be re-used. This isn't so much an issue with functions like strcpy, but with functions that have multiple types of arguments (generics, for example), the code for the function must be duplicated.
@greister
greister / ffap-nodejs-module.el
Created December 2, 2016 12:45 — forked from davazp/ffap-nodejs-module.el
Find node module at point
;;; Try to find the string at point as a NodeJS module
(require 'ffap)
(defun ffap-nodejs-module (name)
(unless (or (string-prefix-p "/" name)
(string-prefix-p "./" name)
(string-prefix-p "../" name))
(let ((base (locate-dominating-file
default-directory