Skip to content

Instantly share code, notes, and snippets.

@hathix
hathix / immutablemap.ts
Last active October 25, 2021 14:06
TypeScript immutable map
class ImmutableMap<T> {
// This is immutable, can't be changed in place
private innerMap: Map<string,T>;
public constructor(nativeMap = new Map<string,T>()) {
this.innerMap = nativeMap;
}
public keys() : string[] {
@hathix
hathix / calendar-days-ago.js
Created June 14, 2021 05:12
Calendar days ago
/**
* Strips the time part away from a date so that it's a pure date (no time).
*/
function toPureDate(d: Date) : Date {
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0);
}
function hoursAgo(h: number) : Date {
const now: Date = new Date();
now.setTime(now.getTime() - h * 60 * 60 * 1000);
@hathix
hathix / proof-of-work.js
Created February 1, 2020 23:16
Bitcoin mining simulation
// Simulating Bitcoin's Proof-of-Work mining algorithm
// The challenge: choose a nonce that, when appended to "hello",
// yields an MD5 hash with at least 4 leading zeroes
for (let i = 0; i < 1000000; i++) {
out = md5("hello" + i);
if (out.startsWith("0000")) {
console.log(i, out)
}
}
@hathix
hathix / list-of-harvard-libraries.txt
Created February 26, 2018 16:27
List of Harvard Libraries
Andover-Harvard Theological Library
Arnold Arboretum Horticultural Library
Arthur and Elizabeth Schlesinger Library on the History of Women in America
Baker Library
Baker Library Special Collections
Birkhoff Mathematical Library
Botany Libraries
Cabot Science Library
Chemistry and Chemical Biology Library
Countway Library of Medicine
@hathix
hathix / list-of-harvard-museums.txt
Created February 26, 2018 16:27
List of Harvard Museums
Fogg Museum
Busch-Reisinger Museum
Arthur M. Sackler Museum
Carpenter Center
Peabody Museum
Graduate School of Design
Harvard Semitic Museum
Arnold Arboretum
Collection of Historical Scientific Instruments
Harvard Museum of Natural History
@hathix
hathix / email-regex.txt
Created October 3, 2017 04:17
RegEx to find emails
/\b[\w\d._%+-]+@[\w\d.-]+\.[\w]{2,}\b/g