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
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
inline static void | |
incref(int32_t *refp) { | |
asm volatile("addl $1, (%0)" : : "r" (refp) : "memory"); | |
} | |
inline static 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
// Copyright © 2018 Bart Massey | |
// This program is licensed under the "MIT License". | |
// Please see the file LICENSE in this distribution | |
// for license terms. | |
// Advent of Code Day 11. | |
"use strict"; | |
function power_level(x, y, gsn) { |
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
// https://www.reddit.com/r/rust/comments/a0g730/new_to_rust_discouraged_by_slowrunning_code/ | |
fn nth_prime_bad(initial: u64) -> u64 { | |
let mut prime_count = 0; | |
let mut curr = 2; | |
let mut prime = None; | |
while prime_count < initial { | |
let mut denom = 2; | |
while denom < curr { | |
if curr % denom == 0 { |
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
Inductive nzbin : Type := | |
| O | |
| A (b: nzbin) | |
| B (b: nzbin). | |
Fixpoint nzincr (b : nzbin) : nzbin := | |
match b with | |
| O => A O | |
| A c => B c | |
| B c => A (nzincr c) |
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
-- Modified from https://www.snoyman.com/blog/2018/10/raii-better-than-bracket-pattern | |
import Control.Exception (bracket) | |
import Text.Printf (printf) | |
data MyResource = MyResource { handle :: Int } | |
newMyResource :: IO MyResource | |
newMyResource = do | |
putStrLn "Creating a new MyResource" |
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
# Copyright (c) 2018 Bart Massey | |
# GC demo. | |
# Create a circular structure. The reference | |
# count of x and y would be 2: one for the | |
# variable and 1 for the internal reference. | |
x = [1] | |
y = [2] | |
y[0] = x |
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
{ | |
"consumes": [ | |
"application/json" | |
], | |
"swagger": "2.0", | |
"basePath": "/", | |
"schemes": [ | |
"https" | |
], | |
"produces": [ |
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
// Copyright © 2018 Bart Massey | |
// Simple deck of cards using enum_derive. | |
#[macro_use] extern crate custom_derive; | |
#[macro_use] extern crate enum_derive; | |
custom_derive! { | |
#[derive(Debug, Clone, Copy, PartialEq, Eq, IterVariants(Suits))] |
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
-- Copyright © 2017 Bart Massey | |
-- | Illustrate the FTP problem in a realistic way. | |
import Data.List | |
import Data.Maybe | |
-- | Given a list of values `xs`, return a list of tuples | |
-- consisting of a list of `n` copies of a given value and a | |
-- count of its occurrences, ordered by value. Setting `n` |
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
// http://willcrichton.net/notes/rust-memory-safety/ | |
// Modified by Bart Massey 2018-02-03 | |
#![feature(alloc, allocator_api)] | |
extern crate alloc; | |
use std::slice; | |
use std::heap::{Heap, Alloc}; | |
use alloc::allocator::Layout; |