Skip to content

Instantly share code, notes, and snippets.

View ElectricCoffee's full-sized avatar

Niko Lepka ElectricCoffee

View GitHub Profile
const quips = [
"NaN days since last JS incident!",
"function funCallFun() { funCallFun(); }",
"Will code for food!",
"In a love/hate relationship with JS since 2012!",
"If you see this, the JS didn't load!",
"Natural 20!"
];
function randQuip() {
# An implementation of Haskell's arrow library in Python, done as an exercise
from __future__ import annotations
from typing import Callable
class Arrow:
def __init__(self, func):
self.func = func
def __call__(self, *args):
;;;; Haskell's arrow library implemented in common lisp as an exercise
;;; date: 2019-09-17
;;; author: Niko L.
(defstruct arrow func)
(defmacro arr (args &body body)
`(make-arrow :func (lambda ,args ,@body)))
(defun run (arrow arg)
#! python
import os, sys, mimetypes, pprint
from typing import Optional, Dict
# Lists the file types and their associated line endings in a file tree
types: Dict[str, list] = {}
def guess_filetype(path: str) -> Optional[str]:
"""Returns just the type returned by mimetypes.guess_type, not its encoding"""
@ElectricCoffee
ElectricCoffee / fix-line-endings.py
Created July 31, 2019 08:47
DO NOT RUN, it has some weird tendency to include binaries, despite being asked to skip them
#! python
import os, sys, mimetypes
from typing import Optional
# Attempts to fix the line endings in all files in a given folder and its subfolders.
ALLOWED_FILETYPES = [
'text/plain', 'application/json', 'text/html', 'application/xml', 'text/xml',
'application/xhtml+xml', 'application/vnd.ms-excel', 'text/css', 'application/javascript'
]
use specs::prelude::*;
use specs_derive::*;
#[derive(Component)]
#[storage(VecStorage)]
struct Position {
x: i32,
y: i32,
}
@ElectricCoffee
ElectricCoffee / specs-test.rs
Created May 12, 2019 22:53
Dependencies include specs and specs-derive
use specs::prelude::*;
use specs_derive::*;
#[derive(Component)]
#[storage(VecStorage)]
struct Position {
x: i32,
y: i32,
}
@ElectricCoffee
ElectricCoffee / razzle_dazzle.rb
Last active April 20, 2019 23:56
Inspired by the Razzle Dazzle ScamNation video on YouTube: https://www.youtube.com/watch?v=527F51qTcTg This models the dice version of the game.
# Inspired by the Razzle Dazzle scam on YouTube: https://www.youtube.com/watch?v=527F51qTcTg
# Note that this always assumes fair play
##
# Keeps track of the outcome of any given dice roll
# +points+ is how many points a given field is worth
# +prize+ is how many prizes are being added to your current pool of prizes
# +cost_mult+ is the cost multiplier of a given spot
class Outcome
attr_reader :points, :prize, :cost_mult
@ElectricCoffee
ElectricCoffee / cleanup.rb
Last active April 16, 2019 14:34
ruby implementation of my old cleanup.bash file.
#! /usr/bin/ruby
require './prompt'
# Exit early if a file name hasn't been provided
if ARGV.length < 1 then
puts "Please provide an identifier"
exit
end
# Gets all the strings that include the provided identifier
@ElectricCoffee
ElectricCoffee / mkcpp.rb
Last active April 16, 2019 12:46
tool for generating cpp and hpp files
#! /usr/bin/ruby
# Somewhat counter-intuitively, Ruby's ARGV doesn't include the file name,
# so the vector is 1 shorter than normal.
# Typically writing ./mkcpp.rb foo would give a vector like ARGV = ["mkcpp.rb", "foo"], but not here.
if ARGV.length < 1 then
puts "Please provide a sufficient number of arguments"
exit
end