Skip to content

Instantly share code, notes, and snippets.

View Tomotoes's full-sized avatar
🍅
PRESS START

Simon Ma Tomotoes

🍅
PRESS START
View GitHub Profile
@Tomotoes
Tomotoes / isElementInViewport.js
Created November 7, 2020 07:22
isElementInViewport
function isElementInViewport(el) {
http://stackoverflow.com/questions/325933/determine-whether-two-date-ranges-overlap
{ /* The source of the following code. */ }
const rect = el.getBoundingClientRect()
const windowHeight = (window.innerHeight || document.documentElement.clientHeight)
const windowWidth = (window.innerWidth || document.documentElement.clientWidth)
const vertInView = (rect.top <= windowHeight) && ((rect.top + rect.height) >= 0)
const horInView = (rect.left <= windowWidth) && ((rect.left + rect.width) >= 0)
@Tomotoes
Tomotoes / QuickSort.js
Created October 10, 2020 05:12
QuickSort.js
const quickSort = a => {
if (!a.length) { return [] }
return [
...quickSort(a.filter(e => e < a[0])),
...a.filter(e => e === a[0]),
...quickSort(a.filter(e => e > a[0]))]
}
@Tomotoes
Tomotoes / permutate.js
Created September 25, 2020 13:36
permutation
const permutate = (n, choices = ['A', 'B', 'C', 'D']) => {
const result = []
const recursion = path => {
if (path.length === n) {
result.push(path.join(''))
return
}
choices.forEach(c => { recursion([...path, c]) })
}
@Tomotoes
Tomotoes / main.js
Created September 25, 2020 10:30
leastWorkTime
const patchTasksByTimeout = (task, tasks, timeout) => {
return tasks.reduce((a, t) => {
if (t.value === task.value) {
t.timeout = timeout
} else {
t.timeout = Math.max(0, t.timeout - 1)
}
return [...a, t]
}, [])
}
@Tomotoes
Tomotoes / counter.js
Created July 5, 2020 05:05
Redux-Counter
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import ReactDOM from 'react-dom'
import { createStore } from 'redux'
import { Provider, connect } from 'react-redux'
// React component
class Counter extends Component {
render() {
const { value, onIncreaseClick } = this.props
@Tomotoes
Tomotoes / Generator.go
Created March 7, 2020 07:36
Generator.go
package main
import "fmt"
func Iter(start, end int) chan int {
ch := make(chan int)
go func(ch chan int) {
for i := start; i <= end; i++ {
ch <- i
}
@Tomotoes
Tomotoes / PromiseSimple.js
Created February 26, 2020 04:00
PromiseSimple
class PromiseSimple {
constructor(executionFunction) {
this.promiseChain = [];
this.handleError = () => {};
this.onResolve = this.onResolve.bind(this);
this.onReject = this.onReject.bind(this);
executionFunction(this.onResolve, this.onReject);
}
@Tomotoes
Tomotoes / recent-activity.txt
Last active October 29, 2020 14:15
⚡️ Recent activity
❗️ Opened issue #103 in Tomotoes/weibo
❗️ Opened issue #102 in Tomotoes/weibo
❗️ Closed issue #99 in Tomotoes/weibo
❗️ Closed issue #82 in Tomotoes/weibo
🗣 Commented on #75 in Tomotoes/scrcpy-gui
@Tomotoes
Tomotoes / Weibo.md
Last active November 11, 2023 12:38
✨ Latest Weibo

Newsletter 是一类去平台化的信息源,能让自己重新掌握消费的主动权,通过筛选的优质信息,可创造出能使自己思考的环境。

Newsletter 作为我重要的输入源,已使用多年,不知不觉已积累了一些自认为的高质信息源,这些信息粗分为 技术主题 与 科技人文主题,信息源与其订阅方式已梳理到 https://tomotoes.com/newsletter/,希望能对你有所帮助。

如果你也有推荐的 newsletter,欢迎补充到 issue 中,同时也可以看看 我的 newsletter - 思考的价值 是不是你想要的菜~

微博地址: https://tomotoes.com/blog/weibo

@Tomotoes
Tomotoes / Once.go
Created August 18, 2019 09:34
Officially provided Context package
package sync
import (
"sync"
"sync/atomic"
)
type Once struct {
m sync.Mutex
done uint32