Skip to content

Instantly share code, notes, and snippets.

@mkhan45
mkhan45 / sc.sh
Last active December 29, 2022 01:40
Screenshot
#!/bin/sh
# Usage: sc [DELAY] [OUTPUT]
# Image is copied to clipboard and saved to output
if [ -z "$2" ]
then
file="$(mktemp)"
else
file="/home/$USER/$2"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define PROGRESSLEN 25
// I'm not sure if I'm following best practices at all here but it works
int main(int argc, char *argv[]) {
@mkhan45
mkhan45 / assistivegame.ino
Last active March 11, 2020 19:08
game for AT club
enum Game {
BlinkGame
};
static Game game;
const int button1 = 3;
const int button2 = 4;
const int button3 = 5;
const int greenled = 6;
const int redled = 7;
@mkhan45
mkhan45 / example.py
Created April 18, 2020 18:43
yourgrad
import yourgrad as yg
a = yg.Tensor(list(range(15)))
b = yg.Tensor(list(range(15)))
f = a + b
f.backward()
print(a.grad)
@mkhan45
mkhan45 / solvenet.py
Created April 19, 2020 01:24
Solver for ai example questions
from typing import List, Dict, Tuple, Set
import math
g = lambda x: 1 / (1 + math.e**(-x))
def solve_net(node_vals: List[int], edges: Dict[Tuple[int, int], int], activated_nodes: Set[int]):
unsolved_nodes = [i for (i, v) in enumerate(node_vals) if v == None]
for node in unsolved_nodes:
val = sum(node_vals[i1 - 1] * w for ((i1, i2), w) in edges.items() if i2 == node + 1)
package main
import (
"bufio"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
@mkhan45
mkhan45 / main.go
Created January 4, 2021 04:08
A super simple server which redirects all http traffic to https
package main
import (
"net/http"
)
func httpRedirect(w http.ResponseWriter, req *http.Request) {
target := "https://" + req.Host + req.URL.Path
if len(req.URL.RawQuery) > 0 {
target += "?" + req.URL.RawQuery
}
@mkhan45
mkhan45 / linkedlist.hs
Last active March 11, 2021 18:38
Data.List is already a LinkedList
import Data.Semigroup
data Node a -- a Node containing type a is
= Val a (Node a) -- either a Value of type a and another Node
| End -- or the end of the list
-- Makes it possible for REPL to display a linked list
-- Val 5 (Val 3 (Val 9 End)) becomes 5->3->9->()
instance (Show a) => Show (Node a) where
show (Val a next) = (show a) <> "->" <> (show next)
@mkhan45
mkhan45 / demo.bytecode
Last active March 13, 2021 19:57
A super simple bytecode VM
Push 0
Push 0
-- accumulator is 0
-- index is 1
-- adds index to accumulator
Get 0
Get 1
Add
@mkhan45
mkhan45 / expr.cpp
Last active April 27, 2021 04:36
simple expr eval in cpp
#include <iostream>
#include <memory>
enum BinOp {
Add,
Sub,
Mul,
Div,
};