Skip to content

Instantly share code, notes, and snippets.

View mkhan45's full-sized avatar
🍪

Mikail Khan mkhan45

🍪
View GitHub Profile
@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
}
package main
import (
"bufio"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
@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)
@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 / 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;
#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 / 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"