Skip to content

Instantly share code, notes, and snippets.

@weberliu
weberliu / format-date.js
Last active September 5, 2023 22:26
JS 片段
const today = new Date().toJSON().slice(0, 10).replace(/-/g, '')
// 对象数组除重
arr.filter((item, index) => arr.findIndex((i) => item.id === i.id) === index)
const combine = (arr) => {
let result = []
let go = (currentArr) => {
if (currentArr.length === arr.length) {
result.push(currentArr)
@weberliu
weberliu / hosts
Created August 16, 2023 02:04 — forked from consti/hosts
/etc/hosts to block shock sites etc.
# This hosts file is brought to you by Dan Pollock and can be found at
# http://someonewhocares.org/hosts/
# You are free to copy and distribute this file for non-commercial uses,
# as long the original URL and attribution is included.
#<localhost>
127.0.0.1 localhost
127.0.0.1 localhost.localdomain
255.255.255.255 broadcasthost
::1 localhost
/**
* 返回数组数组的标准偏差。
*
* 使用 Array.reduce() 来计算均值,方差已经值的方差之和,方差的值,然后确定标准偏差。
* 您可以省略第二个参数来获取样本标准偏差,或将其设置为 true 以获得总体标准偏差。
*/
const standardDeviation = (arr, usePopulation = false) => {
const mean = arr.reduce((acc, val) => acc + val, 0) / arr.length;
return Math.sqrt(
arr.reduce((acc, val) => acc.concat((val - mean) ** 2), []).reduce((acc, val) => acc + val, 0) /
#!/usr/bin/python
# coding=utf-8
# TF-IDF提取文本关键词
# http://scikit-learn.org/stable/modules/feature_extraction.html#tfidf-term-weighting
import sys
import os
from config_ch import *
import chardet
import numpy as np
#!/bin/bash
# curl "https://gist.github.com/weberliu/c3e12e4c09f27c9ef3363314f2401859/centos-ss" | /bin/sh
####################################
install_home="/etc/shadowsocks/" # 安装目录
port=30443; # 端口
password="ladders" # 密码
encrypt="chacha20-ietf-poly1305" # 加密方式
####################################
@weberliu
weberliu / nunjucks.js
Created March 25, 2018 03:02
Nunjucks for koa2
/*
USAGE:
import njk from './nunjucks';
// Templating - Must be used before any router
app.use(njk(path.join(__dirname, 'views'), {
extname: '.njk',
noCache: process.env.NODE_ENV !== 'production',
throwOnUndefined: true,
filters: {
json: function (str) {
@weberliu
weberliu / dialog.js
Created March 16, 2018 02:51
wxapp dialog
import Component from '../component'
export default {
/**
* 默认参数
*/
setDefaults () {
return {
title: undefined,
content: undefined,
@weberliu
weberliu / arraydiff.js
Created March 10, 2018 04:06
Find the difference of two arrays.
function arrDiff (a1, a2) {
var a = []
var diff = []
for (var i = 0; i < a1.length; i++) {
a[a1[i]] = true
}
for (var i = 0; i < a2.length; i++) {
if (a[a2[i]]) {
@weberliu
weberliu / drawimage.js
Created March 7, 2018 08:27
It's a bit more complicated to get a cover functionality, though here here is one solution for this:
/**
* https://stackoverflow.com/questions/21961839/simulation-background-size-cover-in-canvas/21961894#21961894
*
* By Ken Fyrstenberg Nilsen
*
* drawImageProp(context, image [, x, y, width, height [,offsetX, offsetY]])
*
* If image and context are only arguments rectangle will equal canvas
*/
function drawImageProp (ctx, img, x, y, w, h, offsetX, offsetY) {
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>