Skip to content

Instantly share code, notes, and snippets.

@louy2
louy2 / cargo_install_all.sh
Created January 5, 2021 14:27
cargo install all global binaries again, which effectively upgrades them all to latest version.
cargo install --list | grep : | awk '{print $1}' | xargs cargo install
@louy2
louy2 / Main.java
Created October 12, 2020 07:46
Find the nearest number @ JetBrain Academy
import java.util.*;
import java.util.stream.Collectors;
class DistNum {
public Integer distance;
public Integer num;
public DistNum(Integer distance, Integer num) {
this.distance = distance;
this.num = num;
@louy2
louy2 / not_tagless_final.rs
Last active July 3, 2020 08:43
Experiment with tagless final in Rust
// http://okmij.org/ftp/tagless-final/JFP.pdf
// Self is not HKT so cannot enforce term types
trait Symantics {
fn int(v: i64) -> Self;
fn bool(v: bool) -> Self;
// Cannot enforce that add takes int
fn add(x: Self, y: Self) -> Self;
// Cannot enforce that leq takes int and returns bool
@louy2
louy2 / truth_table_in_console.js
Created May 2, 2020 04:41
Wrote another truth table generator in Firefox console
let and2 = (x, y) => {
if (Boolean(x)) {
return Boolean(y)
} else {
return false
}
}
let or2 = (x, y) => {
if (Boolean(x)) {
@louy2
louy2 / fix_ccc_url.js
Created April 28, 2020 12:21
Zotero script for fixing url of video of chaos computer club
var items = Zotero.getActiveZoteroPane().getSelectedItems();
for (let item of items) {
//return item
let d = item.getField("libraryCatalog").trim()
let p = item.getField("url").trim()
//return { d, p }
//return p.startsWith("https")
if (!p.startsWith("https")) {
let u = "https://" + d + p
//return u
@louy2
louy2 / lullaby.rb
Last active November 18, 2021 22:58
Lullaby first phrase chord by Sonic Pi | Brahms, Johannes: Wiegenlied (Lullaby) op. 49/4 https://youtu.be/t894eGoymio | https://www.musipedia.org
play_chord [60, 64, 68]
sleep 0.5
play_chord [60, 64, 68]
sleep 0.5
play_chord [64, 68, 71]
sleep 1.5
play_chord [60, 64, 68]
sleep 0.5
play_chord [60, 64, 68]
sleep 1
@louy2
louy2 / pohlite4_enkoi_ending.hs
Last active March 19, 2020 09:43
Rust solution to Paiza Online Hackathon Lite 4 ending
-- https://paiza.jp/poh/enkoi-ending/ed57428d
-- しゃくとり法
import Data.List
main = do
t:_ <- map read . words <$> getLine
interact $ show . solve t . map read . lines
solve :: Int -> [Int] -> Int
solve t xs = maximum $ solve' t xs
@louy2
louy2 / merge-sort-demo.rkt
Created February 21, 2020 03:52
Merge sort demo with Racket because DrRacket debug mode shows the stack nicely
#lang racket
(define (merge-sort l)
(cond
[(null? (cdr l)) l]
[else (let-values
([(l1 l2) (split-in-half l)])
(merge (merge-sort l1) (merge-sort l2)))]))
(define (split-in-half l)
@louy2
louy2 / diff_str.hs
Last active January 12, 2020 08:58
Learning Monadic Functional Programming with Paiza.jp
-- https://paiza.jp/works/mondai/skillcheck_sample/diff_str?language_uid=haskell
{-# LANGUAGE OverloadedStrings #-}
import Prelude hiding (getLine, putStrLn)
import Data.Text (Text, pack, unpack)
import Data.Text.IO (getLine, putStrLn)
import Control.Applicative (liftA2)
diffStr :: Text -> Text -> Text
@louy2
louy2 / lim_inf_cons_mul_eq.0.lean
Last active October 17, 2019 18:02
My first non-trivial proof in Lean Prover! ㊗️🎉
import tactic.norm_num
import data.real.basic
import analysis.normed_space.basic
open normed_field
def lim_inf (f : ℝ → ℝ) (L : ℝ) :=
∀ ε > 0, ∃ N > (0 : ℝ),
∀ x, x > N → ∥f x - L∥ < ε