Skip to content

Instantly share code, notes, and snippets.

View jaymody's full-sized avatar
🙈
ignoring bugs

Jay Mody jaymody

🙈
ignoring bugs
View GitHub Profile
@jaymody
jaymody / Dockerfile
Created January 31, 2022 04:24
Docker image for a somewhat beefy ubuntu20.04 installation with my dotfiles repo
FROM ubuntu:20.04
# don't let tzdata prompt timezone selection, just use UTC
ENV DEBIAN_FRONTEND=noninteractive
# "essential" packages
RUN apt update -y && apt upgrade -y && apt install -y \
apt-transport-https \
build-essential \
ca-certificates \
@jaymody
jaymody / Dockerfile
Last active January 31, 2022 03:53
Dockerfile for a barebones ubuntu image with my dotfiles setup
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update -y && apt upgrade -y && apt install -y \
curl \
git \
vim \
zsh
@jaymody
jaymody / main.py
Created January 7, 2022 16:56
A very bad and slow way to find the shortest path between two wikipedia pages. If the degree of separation is more than one page, you may need to wait a couple years for the program to finish.
import requests
from bs4 import BeautifulSoup
base_url = "https://en.wikipedia.org/wiki/"
def page_to_url(page):
return base_url + page
@jaymody
jaymody / Collections.scala
Created November 23, 2021 21:33
Recursive, functional re-implementation of iterable functions (map, reduce, groupBy, etc ...) in Scala.
case class MyList[A](l: Seq[A]) {
def filter(f: A => Boolean): Seq[A] = l match {
case Nil => l
case x :: xs if !f(x) => xs.filter(f)
case x :: xs if f(x) => x +: xs.filter(f)
}
def map[B](f: A => B): Seq[B] = l match {
case Nil => Nil
case x :: xs => f(x) +: xs.map(f)
@jaymody
jaymody / Coin.scala
Created November 23, 2021 21:30
Simple CLI coin flip game in functional Scala.
import scala.io.StdIn.readLine
import scala.util.Random
import scala.annotation.tailrec
case class GameState(nFlips: Int, nCorrect: Int)
object Coin {
def prompt(): Unit = { print("(H) Heads, (T) Tails, (Q) End Game: ") }
def update(g: GameState): Unit = { println(s"nFlips = ${g.nFlips}, nCorrect = ${g.nCorrect}\n") }
@jaymody
jaymody / Main.scala
Created November 23, 2021 21:28
The many ways to write the signature of a function in Scala
object Main extends App {
// lambda function type are specified, type signature is inferred (works for both val and def)
val map1 = (f: (Int) => Int, l: Seq[Int]) => { for (x <- l) yield f(x) }
// lambda function types and result type are specified, type signature is inferred (works for both val and def)
val map2 = (f: (Int) => Int, l: Seq[Int]) => { for (x <- l) yield f(x) } : Seq[Int]
// type signature is specified, lambda function parameter types inferred (works for both val and def)
val map3: ((Int) => Int, Seq[Int]) => Seq[Int] = (f, l) => { for (x <- l) yield f(x) }
@jaymody
jaymody / main.rs
Created November 23, 2021 21:16
map, reduce, filter, forall, count, group_by in Rust
use std::collections::HashMap;
use std::hash::Hash;
fn map<A, B, F>(l: &Vec<A>, f: F) -> Vec<B>
where
F: Fn(&A) -> B,
{
let mut result = Vec::new();
for e in l.iter() {
result.push(f(e));
@jaymody
jaymody / efind.py
Created August 18, 2021 02:50
Email Finder
import json
import time
import requests
import pandas as pd
from tqdm import tqdm
def get_result(email):
return requests.get(f"https://api.trumail.io/v2/lookups/json?email={email}")
@jaymody
jaymody / main.py
Created August 18, 2021 02:49
A simulation for the TedEd frog riddle: https://www.youtube.com/watch?v=cpwSGsb-rTs
import random
N = 1000000 # number of frogs of each gender
assert N >= 2 # there must be at least 2 frogs of each gender
frogs = ["M"] * N + ["F"] * N
max_num_simulations = 2000000 # number of simulations to run
num_simulations = 0
num_clearing_successes = 0
@jaymody
jaymody / shopify-ds-intern-challenge.ipynb
Last active September 16, 2021 17:37
Shopify DS Intern Challenge
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.