Skip to content

Instantly share code, notes, and snippets.

@Ginhing
Ginhing / slot_machine.html
Created August 17, 2018 06:36
learn the APIs of Web Component
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
@Ginhing
Ginhing / cloudSettings
Last active January 17, 2019 10:23
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-01-17T10:23:30.548Z","extensionVersion":"v3.2.4"}
@Ginhing
Ginhing / customIf.jsx
Created June 24, 2016 03:22
jsx condition
const _call = (result) => typeof result === 'function' ? result() : result;
const IF = (condition) => (result, otherResult = null) => _call(condition ? result : otherResult);
const FooComponent = () => (
<div>
{IF(true)(
<span>here is true and evaluated before the condition</span>,
_ => <p>here is false and will not be evaluated</p>
)}
</div>
/**
* @typedef {{delay: number, concurrent: number, holdOn: boolean, onHoldMax: (number|boolean)}} Option
*/
/**
* 用于应对大量的输入,有如下方式:
* - 对所有入队的数据按一定的时间间隔,逐个处理
* - 当固定的时间间隔内没有新输入,或到达一定时间,对当前整个队列处理
* @param handler
* @param {Option} options
* @returns {Object}
@Ginhing
Ginhing / scroll-at.js
Last active May 3, 2016 07:41
a vue-directive to fire when scroll at top or bottom
'scroll-at': {
/**
* @example: <div v-scroll-at.bottom="loadMore"></div>
*/
_bind() {
this.el.addEventListener('scroll', this.scrollHandler)
},
_unbind() {
this.el.removeEventListener('scroll', this.scrollHandler)
@Ginhing
Ginhing / call_lunchs_at_meituan.js
Last active February 3, 2016 02:26
用脚(本)订美团外卖
// 从国内某知名企业 IM 的讨论界面开始运行以下语句
var userAndlunch = e => e.querySelector('.message') && [e.querySelector('.user-name').textContent, e.querySelector('.message pre').textContent.trim().split('\n')[0]]
var lunchs = [].map.call($('.msg-box'), userAndlunch).filter(a => a && ~a[1].search(/^\$[^\$]*/)).map(a => a.join(':'))
JSON.stringify(lunchs, null, 2)
// 将上面输出的字符串复制,到美团商铺页面粘贴并赋值给全局变量 lunchs,再还行剩余所有语句
var lunchNames = lunchs.map(str => str.replace(/^.*\:\$/, ''))
function addCart(foods, lunchNames) {
[].slice.call(foods).filter(e=> ~lunchNames.indexOf($(e).find('[title]').text().trim()))
.map(e => e.querySelector('.j-addcart'))
@Ginhing
Ginhing / install_peer_dep.sh
Created January 26, 2016 14:19
install all unmet peer dependency
#!/bin/sh
## Tested in ArchLinux
npm ls 2>/dev/null | grep "UNMET PEER DEPENDENCY" | awk '{print $NF}' | xargs npm install
from itertools import product
def expand(segment):
if '-' in segment:
start, end = map(int, segment.split('-'))
return map(str, range(start, end + 1))
else:
return [segment]
def parse_ip(ip):
@Ginhing
Ginhing / NumberBaseConverter.py
Last active August 29, 2015 14:26
10进制 to 2-36进制
class NumberBaseConverter(object):
def __init__(self, base=10):
if not (2 <= base <= 36):
raise
self.base = base
def _remainder_map(self, remainder):
if remainder < 10:
return str(remainder)
@Ginhing
Ginhing / redit.py
Created April 16, 2015 07:00
Edit remote file and save it back
#!/usr/bin/env python
from subprocess import call
from time import time
from argparse import ArgumentParser
def pull(path, fname):
if call(['scp', path, fname]) != 0:
raise Exception(path + ' :File path or host seems wrong')
call(['cp', fname, fname + '.bak'])