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
If every problem in Computer Science can be solved by either | |
adding or removing a layer of abstraction, there's only one | |
reasonable conclusion to come to: | |
You're using the wrong abstraction. |
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
trait Volume {} | |
struct RawChunk; impl Volume for RawChunk {} | |
struct RleChunk; impl Volume for RleChunk {} | |
struct FileChunk; impl Volume for FileChunk {} | |
struct Container { | |
raw: Option<RawChunk>, | |
rle: Option<RleChunk>, | |
file: Option<FileChunk>, |
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
// Server-side | |
impl Server { | |
fn start(&self) { | |
let listener = TcpListener::bind("0.0.0.0:59003").unwrap(); | |
// Listen for new clients connecting | |
for stream in listener.incoming() { | |
// When a client connects, generate a UID for them... | |
let client_uid = self.generate_uid(); | |
// ...spawn a new job to handle all of their communication... |
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::cell::RefCell; | |
use std::rc::Rc; | |
trait Widget { | |
fn add(&self, w: Rc<Widget>) -> Rc<Widget> { w } | |
fn children(&self) -> Vec<Rc<Widget>> { vec!() } | |
fn type_name(&self) -> &'static str; | |
fn print_tree(&self, depth: i32) { | |
for _ in 0..depth { print!(" "); } |
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 start_networking (remote: &str) { | |
let mut threadpool = ThreadPool::new(10); | |
let mut postoffice = PostOffice::new(remote); | |
while let Ok(req) = postoffice.await_new() { | |
threadpool.exec(move || { | |
match req { | |
Req::Chunk(postbox) => handle_chunk_req(postbox), | |
Req::Entity(postbox) => handle_entity_req(postbox), | |
Req::Inventory(postbox) => handle_inventory_req(postbox), |
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::mpsc; | |
use std::sync::{Arc, Mutex}; | |
use std::sync::atomic::{AtomicUsize, Ordering}; | |
use std::collections::HashMap; | |
use std::thread; | |
trait Serialize {} | |
trait Deserialize {} | |
impl Serialize for String {} | |
impl Deserialize for String {} |
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 Client { | |
jobs: Jobs, | |
depot: PostDepot, | |
} | |
impl Client { | |
fn new() -> Client { | |
Client { jobs: Jobs::new(), depot: PostDepot::new() } | |
} | |
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
/// | |
/// This code is procedurally generated using the 4th-order Markov chain generator | |
/// | |
/// Original training material: https://github.com/vurtun/nuklear/blob/master/nuklear.h | |
/// | |
const struct nk_image s; | |
* a = (nk_byte) tmp[3]; | |
} | |
NK_API void |
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
import random | |
by_word = True | |
text = open("test.txt").read().replace(" ", " ") | |
if by_word: | |
text = text.split(" ") | |
freq = {} |
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
// Run like: ./bf <myfile.bf> | |
#include<stdio.h> | |
main(int u,int**v){char t[1<<12]={0,},c[1<<16];int m=fread(c,1,1<<16,fopen(*++v,"r")); | |
char*p=t,n=0,x=0,*i=c;for(;i-c<m;){ | |
*i==62?p++:*i==60?p--:*i==43?++*p:*i==45?--*p:*i==46?write(1,p,1):*i==44?read(0,p,1):0; | |
if((*i==91&&!*p)||(*i==93&&*p)){*p?n--:n++;for(;n;)*(*p?--i:++i)==91?n++:*i==93?n--:0;*p?0:i--;}i++;}} |