This file contains 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 java.util.Random; | |
public class FireSim { | |
public static final int EMPTY = 0; | |
public static final int BURNING_STATE_1 = 1; | |
public static final int BURNING_STATE_2 = 2; | |
public static final int TREE = 3; | |
public static final int SAPLING = 4; | |
public static final int LIGHTNING = 5; | |
public static final int INFLAMMABLE = 6; // small large | |
public static final int SMOKE_STATE_1 = 7; |
This file contains 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
# A playing card. | |
class Card | |
# All possible suits a card can have | |
SUITS = %w(Clubs Diamonds Hearts Spades).freeze | |
# All possible ranks a card can have | |
RANKS = %w(2 3 4 5 6 7 8 9 10 Jack Queen King Ace).freeze | |
# Allows us to do `some_card.rank` and `some_card.suit` | |
attr_reader :rank, :suit |
This file contains 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
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | |
pub struct Person {{ | |
age: u32, | |
name: String | |
}} | |
impl Person { | |
fn new(age: u32, name: String) => Self { | |
Self {{ age: age, name: name }} | |
} |
This file contains 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
require 'inquire' | |
# An example of my command-line parsing inquire gem | |
Inquire.new do | |
version '2.0a', switch: '-V' | |
app_name 'cURL2' | |
author 'Sam' | |
switch '-v', '--[no-]verbose', 'Enables (or disables) verbose mode', default: false | |
This file contains 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
module FP | |
class MultiMethod | |
NoMethodMatchesError = Class.new StandardError | |
def initialize = @methods = [] | |
def add(callable, conditions) = @methods.push([callable, conditions]) | |
def call(...) | |
@methods.each do |callable, conditions| |
This file contains 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
grammar Syntax { | |
rule TOP { <expr> .* } | |
rule expr { <.ws> [<literal> | <function>] } | |
token ws { [ <[(){}[\]:\s\n]> | '#' \N* \n? ]* } | |
proto token literal {*} | |
token literal:sym<identifier> { <[a..z_]> <[a..z0..9_]>* } | |
token literal:sym<number> { \d+ } |
This file contains 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
#include <stdlib.h> | |
#include <string.h> | |
#include <stddef.h> | |
#include <assert.h> | |
static inline void LIST_NOFREE(void *t) {} | |
#define LIST_DEFINE(kind, list_name, free_fn) \ | |
typedef struct list_name { \ | |
size_t len, cap; \ | |
kind *eles; \ |
This file contains 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
#!ruby -W0anF(?=) -rstringio | |
# Prompt: Create a program that can check to see if an input | |
# (given any way you want) contains all the letters in the | |
# alphabet, case-insensitive. Note that the input string will | |
# only be ascii, but it may contain non-alphabetic letters. | |
# Make it cursed. | |
END{p$====032} | |
BEGIN{$_=$0.tr *%w*A-Z a-z*; sub $&,% while/\W|\d|_/; $stdin=StringIO.new$_} |
This file contains 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
class Literal { | |
constructor(value) { this.value = value; } | |
run(env) { return this; } | |
toInteger() { return parseInt(this.value); } | |
toString() { return "" + this.value; } | |
toBoolean() { return !!this.value; } | |
} | |
class Variable { | |
constructor(name) { this.name = name; } |
This file contains 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
class ParseError < RuntimeError; end | |
class Token | |
attr_reader :value, :kind, :location | |
def initialize(value, kind, location) | |
@value = value | |
@kind = kind | |
@location = location | |
end |
OlderNewer