Skip to content

Instantly share code, notes, and snippets.

View zesterer's full-sized avatar

Joshua Barretto zesterer

View GitHub Profile
@zesterer
zesterer / hanoifuck.c
Created March 9, 2019 23:41
Hanoifuck is a Turing-complete programming language inspired by Towers of Hanoi and Brainfuck
unsigned char SA[1024], SB[1024], SC[1024];
unsigned char *sa = SA, *sb = SB, *sc = SC, *tmp;
int cp = 0;
int main(int argc, char **argv) {
char* code = "$+$+$+[$-!$+$+$+$+!!]![$-!!$+$+$+$+$+$+!]!!.$-$-$-.$$$$$$$+++++++..$$$+++.[$-]$+$+[$-!$+$+$+$+$+!!]!.";
while (*code != '\0') {
switch (*code) {
@zesterer
zesterer / cargo-web-netlify.sh
Last active February 25, 2019 10:58
curl <URL> -sSLf | bash
#!/usr/bin/env bash
set -e
cweb_version=0.6.23
cweb=https://github.com/koute/cargo-web/releases/download/$cweb_version/cargo-web-x86_64-unknown-linux-gnu.gz
curl -Lo cargo-web.gz $cweb
gunzip cargo-web.gz
chmod u+x cargo-web
@zesterer
zesterer / forge.rs
Last active February 21, 2019 14:57
Forge Language Initial Tests
use std::rc::Rc;
use std::collections::HashMap;
#[derive(Debug)]
pub enum ForgeError<'a> {
UnexpectedChar(char, CodePos),
Expected(&'static str, CodePos, Option<Lexeme<'a>>),
NoSuchItem(&'a str),
InvalidOp(String),
WrongArgNum(String),
// Library
use vek::*;
use quicksilver::{
Result,
geom::{Line, Circle, Transform, Vector},
graphics::{Background::Col, Color},
lifecycle::{Settings, State, Window, run},
};
struct Point {
@zesterer
zesterer / rpn.rs
Created January 25, 2019 16:08
RPN Interpreter
#[derive(Debug)]
enum Error {
InvalidToken(String),
InvalidProgram,
}
#[derive(Debug)]
enum Token {
Add,
Sub,
// Standard
use std::{
sync::RwLock,
collections::HashMap,
hash::Hash,
};
pub struct Tub<K: Copy + Eq + Hash, T> {
map: RwLock<HashMap<K, RwLock<T>>>,
}
@zesterer
zesterer / typed_noise.rs
Last active August 26, 2018 01:04
Typed noise implementation
use std::ops::{Add, Mul};
use std::marker::PhantomData;
// Generic NoiseFn type
trait NoiseFn: Copy + Clone {
type Inp: Copy + Clone;
type Out: Copy + Clone;
fn get(&self, i: Self::Inp) -> Self::Out;
@zesterer
zesterer / manager_pattern.rs
Created August 22, 2018 10:14
A pattern for correctly managing worker threads associated with an instance in Rust
struct Server;
impl Server {
fn new() -> Server {
Server
}
}
struct ServerMgr {
server: Arc<Server>,
#![feature(integer_atomics)]
use std::sync::{mpsc, Arc, Mutex, atomic::{AtomicU64, Ordering}};
use std::collections::HashMap;
use std::thread;
use std::marker::PhantomData;
// Msg
trait Msg: Send + Sync + 'static {}
@zesterer
zesterer / veloren-principles.md
Last active August 15, 2018 15:37
Some useful development principles

Principles Of Development

Below are a series of principles you should try to keep to when developing code for Veloren

Criticism is how you learn: get used to it!

Don't get attached to your code. Expect that everything you write will be poked, prodded, rewritten, refactored, deleted or used in a context you don't envisage. Don't take criticism of your code personally, and realise that all programmers are worthy of criticism at times.

Code is written once and read 100 times!