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
  • 05:59 (UTC +01:00)
View GitHub Profile
@Demonstrandum
Demonstrandum / lambda_fizzbuzz.py
Last active June 3, 2017 13:49
Lambda for FizzBuzz in Python
fizzbuzz = (
lambda n: 'fizzbuzz' if n % 15 == 0 else ('fizz' if n % 3 == 0 else ('buzz' if n % 5 == 0 else str(n) ))
)
# Interactivity
if __name__ == '__main__':
import sys
if len(sys.argv) == 1:
print('Give command line arguments of number to fizzbuzz.')
exit(1)
@Demonstrandum
Demonstrandum / payload.php
Last active June 3, 2017 13:51
GitHub's webhooks for repositories, in PHP and sh.
<?php
header("Content-type: text/plain");
if ( $_POST['payload'] ) {
shell_exec("./pull");
}
?>
@Demonstrandum
Demonstrandum / sphere.rb
Last active June 9, 2017 22:05
Sphere, sort of...
require 'matrix'
class Sphere
def initialize(shine, shineFocus, mood, r)
@shades = ['.', ':', '|', '*' 'o', 'e', '&', '%', '#', '@']
@shine = shine.normalize
@shineFocus = shineFocus
@mood = mood
@r = r
@Demonstrandum
Demonstrandum / cross.cpp
Last active June 20, 2017 21:06
Prints a cross of stars (`*`)
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
void starCross(int n) {
float half = (float)n * 0.5;
@Demonstrandum
Demonstrandum / fib.cr
Last active June 22, 2017 11:41
Fibonacci calculator, ARGV[0] is the nth Fibonacci number.
require "./matrix.cr" # from https://github.com/Exilor/matrix.git the src.matrix.cr file -> https://github.com/Exilor/matrix/blob/master/src/matrix.cr
require "big_int"
require "benchmark"
def fib(n : BigInt)
return 0 if n == 0
return 1 if n <= 2
number = Matrix.rows([[BigInt.new(1), BigInt.new(1)], [BigInt.new(1), BigInt.new(0)]])
@Demonstrandum
Demonstrandum / spectrum.cr
Last active June 23, 2017 18:22
StumpyCore/PNG form_hsl function example:
require "stumpy_png"
include StumpyPNG
width = 361
height = 101
spectrum = Canvas.new(width, height)
(0..width - 1).each do |x|
(0..height - 1).each do |y|
# RGBA.from_hsla_n(hue, saturation, lightness, alpha) is an internal helper method
color = RGBA.from_hsl([x, 64, y]) # Here from_hsl(x, 100, y) would work exactly the same
@Demonstrandum
Demonstrandum / ascii_mandelbrot.rb
Last active August 7, 2017 22:19
Mandelbrot Fractal in ASCII
#!/usr/bin/env ruby
height = %x{ tput lines }.to_i - 3 # -3 for PS1
width = %x{ tput cols }.to_i
scale = 0.6 * width.to_f / height.to_f
definition = 40
def calculate a, b, c_arr
ca, cb = c_arr
@Demonstrandum
Demonstrandum / prime-speed-comparison.cr
Last active August 7, 2017 22:51
Sieve of Eratosthene
require "time"
require "big_int"
def primesArray(n : UInt64)
primedex = [false, false] of Bool
primedex += [true] * (n - 1)
(2_u64..n).each do |i|
(2_u64..n).each do |j|
begin
@Demonstrandum
Demonstrandum / .bashrc
Last active August 18, 2017 20:11
Default bashrc
. /etc/bashrc
prompt() {
extra=2
PS1=$(printf "\n%*s\r%s\n>>> " "$(expr $(tput cols) - ${#PWD} + $(if [[ $PWD/ = "$HOME"/* ]]; then echo ${#HOME} - 1; else echo 0; fi) + $extra )" '[ \w ]' '\u@\h')
}
PROMPT_COMMAND=prompt
. ~/.functions
. ~/.aliases
@Demonstrandum
Demonstrandum / .vimrc
Created August 18, 2017 21:51
Basic vimrc with vundle
set nocompatible
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required