Skip to content

Instantly share code, notes, and snippets.

View justan's full-sized avatar

justan

  • Shenzhen, China
  • 07:18 (UTC +08:00)
View GitHub Profile
@justan
justan / run-scripts-by-path.mjs
Last active October 10, 2023 03:53
run turbo/yarn workspace command by path
import { execSync } from 'child_process';
import pt from 'path';
import os from 'os';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const rawCommand = process.argv[2];
const argv = process.argv.slice(3);
@justan
justan / thirdparty_upload_cloudfunction.js
Last active August 16, 2019 11:39
第三方平台授权账号上传云函数
// 仅限第三方平台授权的账号调用
const crypto = require('crypto')
const fs = require('fs')
const fsPromises = fs.promises
const pt = require('path')
const fetch = require('node-fetch')
/**
@justan
justan / index.js
Created July 31, 2018 02:48
获取小程序码实例 wxacode
// 云函数入口函数
const request = require('request')
const appId = 'xxxxxx'
const appSecret = 'xxxxxxxx'
exports.main = ({userInfo}, context) => {
return new Promise((resolve, reject) => {
request({
url: `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appId}&secret=${appSecret}`
@justan
justan / duplicate_promise_combine.js
Last active March 1, 2017 13:09
combine duplicate promise
//通用 promise 合并
var duplicatePromiseCombine = function () {
var pendings = { }
/**
* @param {Function} promiseFn 原始的 promise 方法
* @param {Function} keyGenFn 相同的 promise 通过该方法应该返回相同的 key
* @return {Function} 可合并相同 key promise 的方法
*/
return function (promiseFn, keyGenFn) {
@justan
justan / my_favorite_item.user.js
Last active December 11, 2015 22:58
Add a google reader item to favorite when star it.
// ==UserScript==
// @name favorite item
// @namespace http://gmscrobber.whosemind.net
// @include https://www.google.com/reader/view/*
// @version 0.0.1
// ==/UserScript==
document.body.addEventListener('click', function(e) {
var target = e.target
, container
@justan
justan / rgbatohex.js
Created October 31, 2012 13:25
给定一个背景颜色, 将 rgba 转换成 hex
//give a background color, convert rgba to hex
var rgbaToHex = function(rgba, bgRgb){
var a = rgba[3] / 255
, r = Math.round((1 - a) * bgRgb[0] + a * rgba[0]).toString(16)
, g = Math.round((1 - a) * bgRgb[1] + a * rgba[1]).toString(16)
, b = Math.round((1 - a) * bgRgb[2] + a * rgba[2]).toString(16)
;
return '#' +
(r.length === 1 ? ('0' + r) : r) +
@justan
justan / remove_selection.js
Created August 29, 2012 02:09
取消选中区域
//做滚动条的时候可能用得上
window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
server {
listen 80;
server_name img.whosemind.net;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://dl.dropbox.com/u/6877098/;
proxy_redirect off;
}
@justan
justan / qrcode.js
Created June 21, 2012 09:01
a qrcode bookmarklet(二维码小书签)
//a qrcode bookmarklet(二维码小书签)
//javascript:(function(d){var b=d.createElement("textarea"),c,f=!!d.all,a,e="http://qrcode.kaywa.com/img.php?s=5&d=%s";(c=d.getElementById("_qrcode__"))?(b=c,a=b.style,a.display=""):(a=b.style,b.id="_qrcode__",d.body[f?"attachEvent":"addEventListener"]((f?"on":"")+"click",function(){a.display="none"},!0),a.zIndex=9999,a.position="fixed",a.top=0,a.left=0,a.width="100%",a.height="100%",d.body.appendChild(b));c=function(){var a,b=d.selection,c=d.activeElement,e=top.getSelection,f=c&&c.selectionEnd;f?a=c.value.substring(c.selectionStart, f):e&&(a=e()+"");b&&(a=b.createRange().text);return a=a||location.href}();b.title=c;e=e.replace("%s",encodeURIComponent(c));a.color='#fff';a.background="rgba(0, 0, 0, 0.3) url("+e+") no-repeat center";b.select()})(document);
//original code
(function(doc){
var qrcode = doc.createElement('textarea'), tmp,
ie = !!doc.all, style, txt,
qrimage = 'http://qrcode.kaywa.com/img.php?s=5&d=%s',
id = '_qrcode__';
@justan
justan / ed2k search.js
Created June 19, 2012 13:44
a bookmarklet for emule search selected text
//bookmarklet
//javascript:(function(a){var b,c=a.selection,a=a.activeElement,d=top.getSelection,e=a&&a.selectionEnd;e?b=a.value.substring(a.selectionStart,e):d&&(b=d()+"");c&&(b=c.createRange().text);b&&(location="ed2k://|search|%s|/".replace(/%s/,b))})(document);
//origin code
(function(doc){
var text,
IEselection = doc.selection,
activeEle = doc.activeElement,
getSelection = top.getSelection,
selectionEnd = activeEle && activeEle.selectionEnd;