Skip to content

Instantly share code, notes, and snippets.

View jfacoustic's full-sized avatar

Josh Mathews jfacoustic

View GitHub Profile
@jfacoustic
jfacoustic / website_blocker.py
Created March 10, 2024 16:43
Python UI Website Blocker
#!/usr/bin/env python3
from PySide6.QtWidgets import (
QApplication,
QMessageBox,
QWidget,
QLabel,
QPushButton,
QVBoxLayout,
QPlainTextEdit
@jfacoustic
jfacoustic / cont-frac.scm
Last active October 17, 2020 15:37
1.37, 1.38, 1.39 SICP
(define (cont-frac n d k)
(define (loop i k)
(if (= k i)
(/ (n i) (d i))
(/ (n i) (+ (d i) (loop (+ i 1) k)))))
(loop 1 k))
; 1.37
(define golden-ratio 1.61803398875)
@jfacoustic
jfacoustic / fixed-point.scm
Created October 16, 2020 12:58
1.35, 1.36 sicp
(define tolerance 0.00001)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance))
(define (fixed-point f first-guess)
(define (try guess)
(let ((next (f guess)))
(if (close-enough? guess next)
next
@jfacoustic
jfacoustic / filtered-acc.scm
Created October 14, 2020 12:19
1.33 SICP (iterative solution)
(define (filtered-acc filter combiner null-value term a next b)
(define (iter a result)
(if (> a b)
result
(if (filter a)
(iter (next a) (combiner (term a) result))
(iter (next a) result))))
(iter a null-value))
(define (prime? n)
(define (product term a next b)
(define (iter a result)
(if (= a b)
result
(iter (next a) (* result (term a)))))
(iter a 1))
(define (inc x) (+ x 1))
(define (identity x) x)
@jfacoustic
jfacoustic / product.scm
Last active October 13, 2020 12:22
1.31 SICP (recursive)
(define (product term a next b)
(if (> a b)
1
(* (term a)
(product term (next a) next b))))
(define (inc x) (+ x 1))
(define (identity x) x)
(define (factorial n)
(define (sum term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (+ result (term a)))))
(iter a 0))
@jfacoustic
jfacoustic / simpsons.scm
Created October 11, 2020 15:21
1.29 SICP
(define (sum term a next b)
(if (> a b)
0
(+ (term a)
(sum term (next a) next b))))
(define (simpson-integral f a b n)
(let ((h (/ (- b a ) n)))
(define (term n)
(define y (f (+ a (* h n))))
@jfacoustic
jfacoustic / split-string.lisp
Created September 4, 2020 17:20
Splits string by delimiter; default delimiter is \#space. (split-string "1 2 3 4") evaluates to ("1" "2" "3" "4").
(defun split-string (str &key (delimiter #\space))
(defun split-string-rec (str str-list delimiter-pos)
(if delimiter-pos
(let ((current (subseq str 0 delimiter-pos))
(remaining (subseq str (+ delimiter-pos 1) (length str))))
(split-string-rec remaining
(push current str-list)
(position delimiter remaining)))
(reverse (push str str-list))))
(split-string-rec str nil (position delimiter str)))
const cities = ['Tokyo', 'London', 'Rome', 'Donlon', 'Kyoto', 'Paris'].map(city => city.toLowerCase());
const matches = cities.reduce((acc, curr) => {
const double = curr + curr;
const match = [];
cities.forEach(city => {
if(double.includes(city)) {
match.push(city);
}
});