Skip to content

Instantly share code, notes, and snippets.

Yufan Lou louy2

Block or report user

Report or block louy2

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View longestValidParenthesis.hs
{-# 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 Feb 24, 2019
Reader Monad practice
View reader.hs
{-# 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 Feb 21, 2019
問題「砂漠の公園」 | エンジニアが死滅シタ世界 〜アンドロイドとふたりぼっちで生きろ〜
View desert_park.hs
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 Feb 21, 2019
問題「隔離された街のゲート」 | エンジニアが死滅シタ世界 〜アンドロイドとふたりぼっちで生きろ〜
View gate.hs
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 Feb 13, 2019
Simple one-line hash (don't use for anything serious)
View hash.js
let hash = k => Array.from(k).map(s => s.charCodeAt(0)).reduce((a, c) => a + c, 0) % 111 + 1
@louy2
louy2 / dumb.txt
Created Feb 3, 2019
Dumb errors programming in C
View dumb.txt
> 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 Jan 31, 2019
Dismiss all course updates in My Blackboard
View browser.js
/* 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
@louy2
louy2 / vagrant.log
Created Jun 10, 2017
Vagrant Alpine Linux Debug Log
View vagrant.log
INFO global: Vagrant version: 1.9.5
INFO global: Ruby version: 2.2.5
INFO global: RubyGems version: 2.4.5.1
INFO global: VAGRANT_EXECUTABLE="D:\\Installed\\HashiCorp\\Vagrant\\embedded\\gems\\gems\\vagrant-1.9.5\\bin\\vagrant"
INFO global: VAGRANT_INSTALLER_EMBEDDED_DIR="D:\\Installed\\HashiCorp\\Vagrant\\embedded"
INFO global: VAGRANT_INSTALLER_ENV="1"
INFO global: VAGRANT_INSTALLER_VERSION="2"
INFO global: VAGRANT_LOG="debug"
INFO global: VAGRANT_OLD_ENV_="ExitCode=00000000"
INFO global: VAGRANT_OLD_ENV_aliases="D:\\Installed\\cmder_mini\\config\\user-aliases.cmd"
View notes-on-mac-internet-sharing.md

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:

View E.java
/*
* 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; }
You can’t perform that action at this time.