Skip to content

Instantly share code, notes, and snippets.

View Demonstrandum's full-sized avatar
🏫
Studying

S Knutsen Demonstrandum

🏫
Studying
  • University of Nottingham
  • Britanniarum Regnum
  • 00:53 (UTC +01:00)
View GitHub Profile
@Demonstrandum
Demonstrandum / 7.rb
Last active November 30, 2018 20:24
7 segment display
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 August 5, 2018 23:24
Perlin and Simplex noise -- by josephg
/*
* 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 July 8, 2018 15:10
Fully functioning Brainf*ck interpreter in Ruby
#!/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
#!/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) }
@Demonstrandum
Demonstrandum / index.html
Last active June 1, 2018 00:59
p5 Riemann sum
<!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>
@Demonstrandum
Demonstrandum / music.rb
Last active January 21, 2018 16:29
Generating sweet saw tooth wave synths in Ruby, duuuude.
def note frequency, volume, chord, octave
octaves = [ 'Qj}6jQ6%' '_u}6u_6%' ] # Some good sounding random octaves
octave_index = 0
octave_index = (frequency % 4 >> 16) % octaves.size
volume += 1
return 0 if volume.zero?
choose = frequency * (octaves[octave_index][chord % 8].ord + 51)
choose = (choose >> octave) % 4
choose % volume << 4
@Demonstrandum
Demonstrandum / progress_bar.rb
Last active November 5, 2017 23:39
Different style progress bars in Ruby
require 'net/http'
require 'uri'
uri = URI.parse 'http://www.mirrorservice.org/sites/ftp.archlinux.org/iso/2017.11.01/archlinux-2017.11.01-x86_64.iso'
uri = URI.parse 'http://ipv4.download.thinkbroadband.com/10MB.zip'
download = File.basename uri.path
#spin_states = %w{ - \\ | / Done! } # Traditional line spinner
#spin_states = %w{ /^v^\\ \\^v^/ \\ovo/ } # Happy bats
@Demonstrandum
Demonstrandum / frost_sieve.c
Last active October 25, 2017 19:50
Prime Sieve, Frost.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define u64 unsigned long long
typedef unsigned short int bool;
#define false (unsigned short)0
#define true (unsigned short)1
alias kill='kill -KILL'
alias lookup='ps aux | grep'
alias goodnight='sudo systemctl suspend'
alias ls='ls --color=auto'
alias clean='sudo pacman -Qdtq | xargs sudo pacman --noconfirm -Rsn'
alias pacman='sudo pacman'
alias root='su root'
alias s='sudo'
alias please='sudo !-1'
alias starwars='telnet towel.blinkenlights.nl'
<ul class="website-list ui-sortable">
<li class="website-list-item ui-state-default sorting-initialize ui-sortable-handle">
<span class="website-name">Github</span>
<i class="fa fa-times remove-website"></i>
<a target="_blank" class="website-link" href="https://github.com">https://github.com/</a>
</li><li class="website-list-item ui-state-default sorting-initialize ui-sortable-handle">
<span class="website-name">Gist it</span>
<i class="fa fa-times remove-website"></i>
<a target="_blank" class="website-link" href="https://gist.github.com/">https://gist.github.com/</a>