Skip to content

Instantly share code, notes, and snippets.

Avatar
🍣
Studying, low activity.

Samuel Demonstrandum

🍣
Studying, low activity.
View GitHub Profile
@Demonstrandum
Demonstrandum / tacit.py
Created Jun 3, 2020
Tacit programming with Currying and Composition in Python.
View tacit.py
# # Exaple:
# ```py
# from tacit import *
#
# @fn
# def f(x, y):
# return 2 * (x + y)
#
# @fn
# def g(x): return x + 3
@Demonstrandum
Demonstrandum / simp-deps.svg
Created Mar 21, 2020
Simp'O'Matic Dependencies
View simp-deps.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View basic_ruby.rb
def f x; x**2 + 2*x + 1; end
def integrate sym, a, b
dx = 0.001
fn = method sym
dx * (a..b - dx).step(dx).map(&fn).sum
end
puts integrate :f, 2, 4
@Demonstrandum
Demonstrandum / 7.rb
Last active Nov 30, 2018
7 segment display
View 7.rb
REDACT = %w{ k m v w x z }
longest = Array.new
def valid? word
(REDACT & (word.split '')).empty?
end
words = (File.read 'words.txt').split /\s/
words.each { |word| longest = word unless word.size <= longest.size || !(valid? word) }
@Demonstrandum
Demonstrandum / perlin.js
Created Aug 5, 2018
Perlin and Simplex noise -- by josephg
View perlin.js
/*
* By: josephg - https://github.com/josephg
* From: https://github.com/josephg/noisejs/blob/master/perlin.js
* Only slight modification from me, so it works as a module.
*/
/*
* A speed-improved perlin and simplex noise algorithms for 2D.
*
* Based on example code by Stefan Gustavson (stegu@itn.liu.se).
@Demonstrandum
Demonstrandum / brainfrog
Last active Jul 8, 2018
Fully functioning Brainf*ck interpreter in Ruby
View brainfrog
#!/usr/bin/env ruby
$DEBUG = false
EOF = "\0"
String.class_eval { define_method(:arg?) { ARGV.include? self } }
ALLOC = '--alloc'.arg? ? ARGV[(ARGV.index '--alloc') + 1].to_i : 100
PROGRAM = (File.read ARGV.select { |arg| File.file? arg }.first) + EOF
View pronouns.rb
#!/usr/bin/env ruby
require 'rmagick'
include Magick
PRONOUN_DIR = File.expand_path './pronoun_images/'
def parse_pronouns file
raw = File.read File.expand_path file
raw.split("\n").map{ |line| line.split(/--|\//).map(&:strip) }
View index.html
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.11/addons/p5.dom.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />
</head>
<body>
<script src="sketch.js"></script>