Skip to content

Instantly share code, notes, and snippets.

@louy2
louy2 / Main.java
Created Oct 12, 2020
Find the nearest number @ JetBrain Academy
View Main.java
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 Jul 3, 2020
Experiment with tagless final in Rust
View not_tagless_final.rs
// 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
Wrote another truth table generator in Firefox console
View truth_table_in_console.js
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 Apr 28, 2020
Zotero script for fixing url of video of chaos computer club
View fix_ccc_url.js
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 Mar 21, 2020
Lullaby first phrase chord by Sonic Pi | Brahms, Johannes: Wiegenlied (Lullaby) op. 49/4 https://youtu.be/t894eGoymio | https://www.musipedia.org
View lullaby.rb
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 Mar 19, 2020
Rust solution to Paiza Online Hackathon Lite 4 ending
View pohlite4_enkoi_ending.hs
-- 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 Feb 21, 2020
Merge sort demo with Racket because DrRacket debug mode shows the stack nicely
View merge-sort-demo.rkt
#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 Jan 12, 2020
Learning Monadic Functional Programming with Paiza.jp
View diff_str.hs
-- 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 Oct 17, 2019
My first non-trivial proof in Lean Prover! ㊗️🎉
View lim_inf_cons_mul_eq.0.lean
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∥ < ε
View git-cleanup-ignore.sh
#!/usr/env sh
# remove all files from the index
# while leaving them in working dir
git rm -r --cached .
# add everything back
# with gitignore
git add .
You can’t perform that action at this time.