This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:20.04 | |
ENV DEBIAN_FRONTEND=noninteractive | |
RUN apt update -y && apt upgrade -y && apt install -y \ | |
curl \ | |
git \ | |
vim \ | |
zsh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
base_url = "https://en.wikipedia.org/wiki/" | |
def page_to_url(page): | |
return base_url + page | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.