Skip to content

Instantly share code, notes, and snippets.

View Shuumatsu's full-sized avatar

为世人降下祝福 Shuumatsu

View GitHub Profile
import { curry } from 'ramda'
import React from 'react'
import { withStateHandlers } from 'recompose'
import styled, { css } from 'styled-components'
const initialState = { retryCount: 1 }
const stateHandlers = {
reload: ({ retryCount }) => _ => ({ retryCount: retryCount + 1 })
}
import { STATUSES } from '@/constants'
import withUserInformation from '@/hocs/withUserInformation'
import { identity } from 'ramda'
import { branch, compose, renderComponent } from 'recompose'
import LoginPage from '../routes/login'
const privateComponent = branch(
({ loginStatus }) => loginStatus === STATUSES.SUCCESSED,
identity,
renderComponent(LoginPage)
#include <iostream>
using namespace std;
// 罗马数字共有 7 个,即 I(1)、V(5)、X(10)、L(50)、C(100)、D(500)和
// M(1000)
string transform(string accu, int n) {
if (n == 0)
return accu;
int ms = n / 1000;
@Shuumatsu
Shuumatsu / tokenizer.mll
Created April 10, 2019 12:43 — forked from lindig/tokenizer.mll
Some Scanning Recipes for OCamlLex
{
(* short names for important modules *)
module L = Lexing
module B = Buffer
type token =
| STR of string
| INT of int
| ID of string
| PLUSEQ
module PrioQueue = struct
type priority = int
type 'a queue = Empty | Node of priority * 'a * 'a queue * 'a queue
let empty = Empty
let is_empty = function Empty -> true | _ -> false
let rec insert queue prio elt =
open Base
module Make (Comparable : Comparable.S) = struct
let sort_into_piles list =
let piles = Array.create ~len:(List.length list) [] in
let bsearch len elem =
let rec aux lo hi =
if lo > hi then lo
else
let mid = (lo + hi) / 2 in
open Base
module Make (Eq : sig
type t
val equal : t -> t -> bool
end) =
struct
type operation = Delete of int | Insert of int [@@deriving show]
@Shuumatsu
Shuumatsu / StateMonad.hs
Created June 5, 2019 03:59
State monad as composition of (a ->) & (, s)
newtype State s a = State { runState :: s -> (a, s) }
instance Functor (State s) where
-- fmap f st = State
-- $ \s -> let (a, s') = runState st s
-- in (f a, s')
-- fmap f st = State $ fmap (fmap f) (runState st)
fmap f st = State $ (.) (\(a, s) -> (f a, s)) (runState st)
fmap f st = State $ (\g x -> (\(a, s) -> (f a, s)) $ g x) (runState st)
fmap f st = State $ (\x -> (\(a, s) -> (f a, s)) $ (runState st) x)
{-# LANGUAGE TupleSections #-}
module Exe where
class Fluffy f where
furry :: (a -> b) -> f a -> f b
-- Exercise 1
-- Relative Difficulty: 1
instance Fluffy [] where
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
module Step where
import qualified Data.Map.Strict as Map
import Control.Monad.State.Strict (StateT(..))
import Control.Applicative