Skip to content

Instantly share code, notes, and snippets.

#!/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 .
{-# LANGUAGE LambdaCase #-}
-- Solution to https://leetcode.com/problems/longest-valid-parentheses/
-- Same recursive algorithm with
-- 1. function
-- 2. foldl
-- 3. Reader
-- 4. ReaderT
-- 5. StateT
-- 6. foldr
@louy2
louy2 / reader.hs
Last active February 24, 2019 13:43
Reader Monad practice
{-# LANGUAGE InstanceSigs #-}
newtype Reader e a = Reader (e -> a)
runReader :: Reader e a -> e -> a
runReader (Reader f) = f
instance Functor (Reader e) where
fmap :: (a -> b) -> Reader e a -> Reader e b
fmap a2b (Reader e2a) = Reader (a2b . e2a)
@louy2
louy2 / desert_park.hs
Last active February 21, 2019 11:34
問題「砂漠の公園」 | エンジニアが死滅シタ世界 〜アンドロイドとふたりぼっちで生きろ〜
import Data.List (elemIndex)
import Data.Maybe (fromJust, isJust)
p :: [String] -> [[Maybe Int]]
p = fmap (fmap d)
where
d 'W' = Just 2
d 'D' = Just 1
d 'L' = Just 0
d _ = Nothing
@louy2
louy2 / gate.hs
Created February 21, 2019 07:07
問題「隔離された街のゲート」 | エンジニアが死滅シタ世界 〜アンドロイドとふたりぼっちで生きろ〜
decode :: String -> [Int]
decode "U" = [ 0, 1]
decode "D" = [ 0, -1]
decode "L" = [-1, 0]
decode "R" = [ 1, 0]
decode _ = [ 0, 0]
(.+) :: Num a => [a] -> [a] -> [a]
(.+) = zipWith (+)
@louy2
louy2 / hash.js
Last active February 13, 2019 09:54
Simple one-line hash (don't use for anything serious)
let hash = k => Array.from(k).map(s => s.charCodeAt(0)).reduce((a, c) => a + c, 0) % 111 + 1
@louy2
louy2 / dumb.txt
Created February 3, 2019 07:38
Dumb errors programming in C
> error: unknown type name 'size_t'
Always put your own header files after system header files, otherwise they will not pick up system types.
Or include necessary system headers in the header file.
@louy2
louy2 / browser.js
Last active January 31, 2019 16:17
Dismiss all course updates in My Blackboard
/* Dismiss all course updates in My Blackboard
*
* To use this, copy the following script into the developer console while on the Updates page
*/
// iframeRef takes an iframe element and returns the document inside it
// Ref: https://stackoverflow.com/questions/1452871/how-can-i-access-iframe-elements-with-javascript
const iframeRef = fr => fr.contentWindow ? fr.contentWindow.document : fr.contentDocument;
// get the Blackboard main UI iframe document
const bb = iframeRef(document.querySelector('#mybbCanvas'));
// click every dismiss button

A preset locally administered MAC address is used as the BSSID of the AP. Changing the MAC address of the Wifi interface doesn't affect this.

The Internet Sharing in System Preferences invokes configd, which then communicates with wifid via IPC to change the mode of the Wifi interface.

Problem: Internet Sharing only works when Security is set to None in Wi-Fi Options. Version: macOS 10.12.4 Model: MacBook Air (13-inch, Mid 2011) Wi-Fi:

@louy2
louy2 / E.java
Created April 24, 2017 04:39
Solving A Java Inheritance Puzzler from https://llogiq.github.io/2015/07/14/inheritance.html
/*
* Solving A Java Inheritance Puzzler from
* https://llogiq.github.io/2015/07/14/inheritance.html
*/
class A {
int x = 3;
int a() { x++; return x + c(); }
int b() { return a(); }
int c() { return x; }