Skip to content

Instantly share code, notes, and snippets.

View BookOwl's full-sized avatar

Matthew BookOwl

  • USA
View GitHub Profile
def reimann_l(f, a, b, n):
dx = (b - a)/n
area = dx * sum(f(a + i*dx) for i in range(n))
return area
def reimann_r(f, a, b, n):
dx = (b - a)/n
area = dx * sum(f(a + i*dx) for i in range(1, n+1))
return area

Keybase proof

I hereby claim: * I am bookowl on github. * I am cdslice (https://keybase.io/cdslice) on keybase. * I have a public key ASBkUqvThpHQy4Gds4jo13s39j6jrXzTH4bhEK7Eoe65lgo To claim this, I am signing this object:

{   "body": {     "key": {       "eldest_kid": "01206452abd38691d0cb819db388e8d77b37f63ea3ad7cd31f86e110aec4a1eeb9960a",       "host": "keybase.io",       "kid": "01206452abd38691d0cb819db388e8d77b37f63ea3ad7cd31f86e110aec4a1eeb9960a",       "uid": "d731df86ea4233fc3006f99b7842bb19",       "username": "cdslice"     },     "merkle_root": {       "ctime": 1576083420,       "hash": "ad12109541099e881bac42ad08aff4627101bc9946b041c6074bf6f6a51a1d70537454b20a326d23e1a4fed26f8296cf6180714da7e4aa3804ea69027919de0c",       "hash_meta": "3b739e953c36354de47cff91bf0a616474996d808d94361c5d74320a90c6537e",       "seqno": 13379831     },     "service": {       "entropy": "EgEmvwi9tQ2ymrow2RXV/1Zr",       "name": "github",       "username": "bookowl"     },     "type": "web_service_b
use std::cmp::{PartialOrd, Ord, Ordering};
use std::collections::HashSet;
// Calculates the highest common factor with Euclid's algorithm
// Probably the hottest code. Is there a faster way to calculate the HCF?
fn hcf(mut a: i64, mut b: i64) -> i64 {
while b != 0 {
let temp = (b, a - b*(a/b));
a = temp.0;
b = temp.1;
@BookOwl
BookOwl / sequence.rs
Last active June 29, 2017 13:35 — forked from anonymous/playground.rs
A hacky sequence macro for emulating C-style for loops
macro_rules! sequence {
($x:ident : $t:ty = $init:expr ; $cond:expr ; $change:expr) => {{
struct Sequence {
val: $t,
}
impl Iterator for Sequence {
type Item = $t;
#[inline]
<blocks app="Snap! 4.0, http://snap.berkeley.edu" version="1"><block-definition s="SUCESS %&apos;val&apos;" type="reporter" category="other"><header></header><code></code><inputs><input type="%s"></input></inputs><script><block s="doReport"><block s="reportNewList"><list><l>SUCESS</l><block var="val"/></list></block></block></script></block-definition><block-definition s="ERROR %&apos;msg&apos;" type="reporter" category="other"><header></header><code></code><inputs><input type="%s"></input></inputs><script><block s="doReport"><block s="reportNewList"><list><l>ERROR</l><block var="msg"/></list></block></block></script></block-definition><block-definition s="match %&apos;x&apos; with Sucess %&apos;val&apos; %&apos;block1&apos; Error %&apos;msg&apos; %&apos;block2&apos;" type="command" category="control"><header></header><code></code><inputs><input type="%l"></input><input type="%upvar"></input><input type="%cs"></input><input type="%upvar"></input><input type="%cs"></input></inputs><script><block s="doIfElse"><
@BookOwl
BookOwl / index.html
Last active February 3, 2017 15:09
The HTML file that we are embedding Rust into.
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<title>Hello from Rust</title>
</head>
<body>
<script src="rust-to-web.js"></script>
</body>
</html>
@BookOwl
BookOwl / main.rs
Created February 1, 2017 17:52
The contents of main.rs. Used for my blog post "Rust to Web"
fn main() {
println!("Hello, JS World!");
}
@BookOwl
BookOwl / rust-to-web.sh
Created February 1, 2017 15:46
A bash script to get Rust ready to compile to the web
# First we get Rust ready.
echo "Getting Rust ready..."
rustup default nightly
rustup target add asmjs-unknown-emscripten
rustup target add wasm32-unknown-emscripten
# Now we get emscripten
echo "Rust is ready. Installing Emscripten..."
curl -O https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz
tar -xzf emsdk-portable.tar.gz
source emsdk_portable/emsdk_env.sh
(function(ext) {
// Cleanup function when the extension is unloaded
ext._shutdown = function() {};
// Status reporting code
// Use this to report missing hardware, plugin or unsupported browser
ext._getStatus = function() {
return {status: 2, msg: 'Ready'};
};
@BookOwl
BookOwl / cloudcoder.py
Created April 3, 2016 01:41
cloudcoder.py - Python module to go along with https://scratch.mit.edu/projects/103348115/
"""cloudcoder.py - Utilities for encoding and decoding strings for Scratch cloud data
Use the encode and decode functions to prepare strings to be stored in cloud variables
and to get strings out of them.
Examples:
>>> encode("I <3 the cloud")
'0x2F49203c332074686520636c6f7564'
>>> decode('0x2F49203c332074686520636c6f7564')
'I <3 the cloud'