This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import styled, { keyframes } from 'styled-components' | |
const Svg = styled.svg.attrs({ | |
version: '1.1', | |
xmlns: 'http://www.w3.org/2000/svg', | |
xmlnsXlink: 'http://www.w3.org/1999/xlink', | |
'xmlns:sketch': 'http://www.bohemiancoding.com/sketch/ns' | |
})` | |
position: relative; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const sync = syncFn => (data, cb) => data |> syncFn |> cb; | |
export const compose = (taskList, cb) => | |
reduceRight((next, task) => data => task(data, next), cb, taskList); | |
export const withErrorHandler = handler => | |
map(task => (data, next) => | |
data instanceof Error ? handler(data) : task(data, next) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cache = new Map() | |
export default src => | |
new Promise((resolve, reject) => { | |
if (cache.has(src)) resolve(cache.get(src)) | |
const audio = document.createElement('audio') | |
audio.addEventListener('loadedmetadata', () => { | |
const duration = audio.duration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://www.ics.uci.edu/~eppstein/161/960109.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cache = new WeakMap() | |
export default src => new Promise((resolve, reject) => { | |
if (cache.has(src)) | |
resolve(cache.get(src)) | |
const audio = document.createElement('audio') | |
audio.addEventListener('loadedmetadata', e => { | |
const duration = audio.duration | |
cache.set(src, duration) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cache = new WeakMap() | |
export default async fileblob => new Promise((resolve, reject) => { | |
if (cache.has(fileblob)) | |
resolve(cache.get(fileblob)) | |
const reader = new FileReader() | |
reader.addEventListener('load', e => { | |
const src = e.target.result | |
cache.set(fileblob, src) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 常规的递归方法 | |
const flatten1 = arr => { | |
const result = [] | |
for (const v of arr) { | |
Array.isArray(v) ? | |
result.push(...flatten(v)) : | |
result.push(v) | |
} | |
return result |