Skip to content

Instantly share code, notes, and snippets.

View SgLy's full-sized avatar
🙁
Busy.

SgLy SgLy

🙁
Busy.
View GitHub Profile
/**
* return a new asynchronous function which has same functionality as `func`,
* but can at most run `maxCount` instance concurrently, exceeded calls will
* be pend and run when old calls end.
* @param {number} maxCount
* @param {(...args: any[]) => Promise<any>} func
* @returns {(...args: any[]) => Promise<any>}
*/
function limit(maxCount, func) {
let currentCount = 0;
@SgLy
SgLy / card.wl
Last active April 1, 2020 18:57
f = 0 < x <= 6 && 0 < y <= 6 && 0 < a <= 3 && 0 < b && 20 <= x + y + z + a + b <= 30 && Element[x | y | z | a | b, Integers];
(* z = 4 *)
z4 = Maximize[
{
(
Binomial[y, 3] (a b + a x + b x) +
Binomial[y, 2] (
a b x +
Binomial[a, 2] (x + b) + Binomial[b, 2] (x + a) + Binomial[x, 2] (a + b)
const { bv2av, av2bv } = (() => {
const TABLE = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF';
const TABLE_REVERSED = {};
for (let i = 0; i < 58; ++i) TABLE_REVERSED[TABLE[i]] = i;
const S = [11, 10, 3, 8, 4, 6];
const XOR = 177451812;
const ADD = 8728348608;
/** @param {string} bv */
const bv2av = bv => {
let r = 0;
@SgLy
SgLy / all.js
Last active October 9, 2019 11:56
async forEach
Array.prototype.asyncAllForEach = async function(cb) {
await Promise.all(
this.map(async (...args) => {
await cb(...args)
})
)
}
@SgLy
SgLy / index.css
Created September 5, 2018 16:46
flex-based ruby tag
.container {
display: flex;
max-height: 80vh;
flex-direction: row;
writing-mode: vertical-rl;
flex-wrap: wrap;
justify-content: space-between;
}
.word {
display: inline-flex;
@SgLy
SgLy / promisify.js
Created August 22, 2018 05:40
promisify wx miniprogram api
const wx_p = (() => {
const _wx = {};
const ret = {};
Object.keys(wx).forEach(n => {
_wx[n] = wx[n];
ret[n] = (args = {}) => new Promise((resolve, reject) => {
args.success = (res) => { resolve(res); };
args.fail = (res) => { reject(res); };
_wx[n](args);
});
@SgLy
SgLy / md-box-shadow.css
Created July 18, 2018 08:40
Material Design Box-Shadow Cheatsheet
--shadow-transition_-_transition: box-shadow 0.28s cubic-bezier(0.4, 0, 0.2, 1);;
--shadow-none_-_box-shadow: none;;
--shadow-elevation-2dp_-_box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14),
0 1px 5px 0 rgba(0, 0, 0, 0.12),
0 3px 1px -2px rgba(0, 0, 0, 0.2);;
--shadow-elevation-3dp_-_box-shadow: 0 3px 4px 0 rgba(0, 0, 0, 0.14),
0 1px 8px 0 rgba(0, 0, 0, 0.12),
@SgLy
SgLy / binaryIndexTree.cpp
Created December 15, 2017 10:05
Simple data structures
const int MAXN = 131072;
int lowbit(int x)
{
return x & (-x);
}
class BIT {
int a[MAXN];
void add(int x, int t)
@SgLy
SgLy / judge.cpp
Created December 17, 2016 12:36
judge.cpp
#include <iostream>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <unistd.h>
#include <stdio.h>
#include <cmath>
using namespace std;