Skip to content

Instantly share code, notes, and snippets.

View press.one
https://press.one/p/address/v?s=0d80826215b9101cfb46e551202cb9db44c6ae6c608020ad301cd46d3f8eb0dde15718edd6f46e768dec4617dad23bc203f0d791a3369e08fa6b4fc0ef2244371&h=973c23a77c5d9bf694f718f3afd579fa5e97a411cd71e4d6dadf8299133a7b6f&a=ee8917ea16dc93624aa7d604e7a328db246c787d&f=P1&v=2
@mcfog
mcfog / paging.js
Created Mar 13, 2017
answer for promise paging exercise
View paging.js
//ref https://www.v2ex.com/t/346533#r_4122841
const api = (num) => {
const allNum = 3 + parseInt(7 * Math.random());//你不知到总页数的
const quality = 0.15;//接口质量指数
return new Promise((resolve, reject) => {
setTimeout(_=>{//超时逻辑
reject({
code: 'CODE_TIMEOUT',
msg: 'timeout'
View gitabbr.fish
abbr g git
abbr ga 'git add'
abbr gaa 'git add --all'
abbr gb 'git branch'
abbr gbda git\ branch\ --merged\ \|\ command\ grep\ -vE\ \"\^\(\\\*\|\\s\*master\\s\*\\\$\)\"\ \|\ command\ xargs\ -n\ 1\ git\ branch\ -d
abbr gbnm 'git branch --no-merged'
abbr gbr 'git branch --remote'
abbr gc 'git commit -v'
abbr gc! 'git commit -v --amend'
abbr gca 'git commit -v -a'
View color.awk
#!/usr/bin/env awk -f
/success/ { print "\033[92m" $0 "\033[0m"; next; }
/error/ { print "\033[91m" $0 "\033[0m"; next; }
/./ { print $0 }
View elevator_2.js
{
init: function(elevators, floors) {
elevators.forEach(initElevator);
floors.forEach(initFloor);
var topFloor = floors.length - 1;
function initElevator(elevator) {
elevator.on("idle", function() {
});
View defer.js
function defer() {
var resolve, reject;
var promise = new Promise(function(realResolve, realReject) {
resolve = realResolve;
reject = realReject;
});
return {
resolve: resolve,
reject: reject,
View Paginator.php
<?php
class Paginator implements \IteratorAggregate
{
const TPL_WRAPPER = 'wrapper';
const TPL_NUM = 'num';
const TPL_NUM_CURRENT = 'currentNum';
const TPL_TAG = 'tag';
const TPL_NEXT = 'next';
const TPL_PREV = 'prev';
@mcfog
mcfog / mixins.less
Created Nov 3, 2014
less垂直居中
View mixins.less
.vertical-align-middle(@child: ~".content") {
&:before {
display: inline-block;
content: '';
height: 100%;
vertical-align: middle;
margin-right: -0.25em;
}
@{child} {
display: inline-block;
@mcfog
mcfog / NotSimpleXMLElement.php
Created Aug 18, 2014
带array正反转换的XMLElement
View NotSimpleXMLElement.php
<?php
class NotSimpleXMLElement extends SimpleXMLElement
{
const ATTR = 'attr';
const NAME = 'name';
const CHILDREN = 'children';