Skip to content

Instantly share code, notes, and snippets.

View somarlyonks's full-sized avatar
🎹
Easy

Yang somarlyonks

🎹
Easy
View GitHub Profile
SCSS 1 hr 24 mins ████████████████████▌ 98.2%
JavaScript 1 min ▎░░░░░░░░░░░░░░░░░░░░ 1.5%
CSS 0 secs ░░░░░░░░░░░░░░░░░░░░░ 0.3%
const debounce = (f, time) => {
let debounced
return function (...args) {
const actor = () => f.apply(this, args)
clearTimeout(debounced)
debounced = setTimeout(actor, time)
}
}
const throttle = (f, time) => {
@somarlyonks
somarlyonks / 123.js
Created June 11, 2019 07:00
123 -> 一二三 -> 壹贰叁
const decimalism = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']
const scalar = ['', '十', '百', '千']
const modular = 10000
const modualrScalar = ['', '万', '亿', '万']
function _123To壹贰叁 (num) {
if (isNaN(num)) return 'NaN'
if (num === 0) return '零'
if (num >= 1000000000000) return 'NaN' // 会计用兆而不是万亿,懒得转换了
# Show 20 biggest directories with 'K M G'
du | \
sort -r -n | \
awk '{split("K M G",v); s=1; while($1>1024){$1/=1024; s++} print int($1)" "v[s]"\t"$2}' | \
head -n 20
@somarlyonks
somarlyonks / DotDict.py
Last active March 22, 2019 02:22
A delicate proxy to json dicts to read/edit them by ".".
class DotDict(dict):
def __init__(self, value):
self.__dict__['__value'] = value
dict.__init__(self, value)
def __getattr__(self, key):
if key == '__value' or key == '_DotDict__value':
return self.__dict__['__value']
/*!
*
* ap/v1.13.0
* Wed Dec 12 2018 15:41:56 GMT+0800 (GMT+08:00)
*
*/
var global = self
, __appxStartTime = (global = self,
Date.now())
, AFAppX = function(e) {
@somarlyonks
somarlyonks / inject.js
Created December 19, 2018 03:59
A rough implemention of augularjs $inject.
var DI = function (dependency) {
this.dependency = dependency;
};
function readParams(func) {
const fs = func.toString()
const paramsMatch = fs.match(/^function.*\((.*?)\)/) || fs.match(/(.*?)\s*\=\>/)
if (!paramsMatch) throw ''
const paramsStr = paramsMatch[1].replace(/[\(\)]/g, '')
@somarlyonks
somarlyonks / github.css
Last active January 5, 2022 02:06
Github fixed logo with stylebot.
#partial-discussion-header > div.gh-header-shadow.box-shadow {
height: 45px;
}
#partial-discussion-header > div.js-sticky.js-sticky-offset-scroll.top-0.gh-header-sticky.is-stuck > div > div {
margin-top: 2px !important;
}
.gh-header .gh-header-sticky.is-stuck+.gh-header-shadow {
z-index: 18;
module Main
import System
readNumber : IO (Maybe Nat)
readNumber = do
input <- getLine
if all isDigit $ unpack input
then pure (Just $ cast input)