Skip to content

Instantly share code, notes, and snippets.

View quadrupleslap's full-sized avatar

Ram quadrupleslap

  • Sydney, Australia
View GitHub Profile
@quadrupleslap
quadrupleslap / choose.py
Last active February 16, 2017 07:12
Simple function to choose from a range of options.
alphabet = "abcdefghijklmnopqrstuvwxyz"
def choose(question, options):
assert 1 < len(options) <= len(alphabet)
while True:
print(question)
for i, opt in enumerate(options):
print("{}) {}".format(alphabet[i], opt))
inp = input("(a-{})> ".format(alphabet[i]))
if len(inp) == 1:
@quadrupleslap
quadrupleslap / make-ten.rs
Last active October 29, 2019 10:33
Making ten from four digits.
use std::fmt;
enum Op<'a> {
Base(f64),
Add(&'a Op<'a>, &'a Op<'a>),
Sub(&'a Op<'a>, &'a Op<'a>),
Mul(&'a Op<'a>, &'a Op<'a>),
Div(&'a Op<'a>, &'a Op<'a>),
Sbi(&'a Op<'a>, &'a Op<'a>),
Dvi(&'a Op<'a>, &'a Op<'a>),
@quadrupleslap
quadrupleslap / decimal-spiral.c
Created March 20, 2018 06:55
This (probably) sucks.
#include <stdio.h>
// Should run in O(1) space (ignoring output) and O(n^3) time, assuming TCO.
int solve(int n, int x, int y) {
int k = (n - 1) * (n + 3) / 2;
if (y == 0) {
// First Row
return k - x;
@quadrupleslap
quadrupleslap / naive-scrap-bench.rs
Last active April 7, 2018 12:58
A naive screen capture benchmark.
// cargo-deps: scrap, x11cap
// Use cargo-script to run this benchmark!
extern crate scrap;
extern crate x11cap;
use std::time::{Duration, Instant};
fn x11cap() {
@quadrupleslap
quadrupleslap / math.pest
Created April 24, 2018 15:17
Questionable math expression grammar.
defn =_{ soi ~ variable ~ "=" ~ expr ~ eoi }
main =_{ soi ~ expr ~ eoi }
add = { "+" }
sub = { "-" }
mul = { "*" }
div = { "/" }
rem = { "%" }
exp = { "^" }
@quadrupleslap
quadrupleslap / heap.c
Last active May 20, 2018 05:17
A binary heap that hopefully works.
#include <assert.h>
#include <stdlib.h>
#define T int
typedef struct heap {
T* data;
size_t cap, len;
} Heap;
@quadrupleslap
quadrupleslap / noughts.py
Last active June 25, 2018 14:53
Command-line noughts and crosses.
import random
BLANK = 0
P1 = 1
P2 = 2
TRANSLATE = { BLANK: '.', P1: 'O', P2: 'X' }
def main():
'''Play noughts and crosses!'''
@quadrupleslap
quadrupleslap / bench-sorts.html
Last active August 2, 2018 04:33
Dumb Insertion Sort (w/ Linked List) vs. GNU Coreutils
<!doctype html>
<html>
<head>
<title>Results</title>
<meta charset="utf-8">
<style>
body {
margin: 0;
font-family: sans-serif;
@quadrupleslap
quadrupleslap / youtube-sucks.sh
Created November 19, 2018 21:42
I'm feeling lucky but with Youtube music and CLI.
#!/bin/sh
mpv "ytdl://ytsearch:$*" --no-video --loop
@quadrupleslap
quadrupleslap / macros.rs
Created January 8, 2019 09:05
Horrific linear algebra macros for when you want to hate something.
use num::traits::{Inv, One, Zero};
use std::ops::*;
use super::F;
macro_rules! vector {($T:ident, $F:ident, $n:tt, [$($i:expr),*]) => {
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct $T(pub [$F; $n]);
impl Deref for $T { type Target = [$F; $n]; fn deref(&self) -> &Self::Target { &self.0 } }