Skip to content

Instantly share code, notes, and snippets.

@shau-lok
shau-lok / pagination.js
Last active August 24, 2023 00:36
后端返回所有数据, 前端做分页
// 前端做数据分页
function pagination(pageNo, pageSize, array) {
var offset = (pageNo - 1) * pageSize;
return (offset + pageSize >= array.length) ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize);
}
// 后端django做分页
from django.core.paginator import Paginator
@shau-lok
shau-lok / add local aar file.md
Last active January 20, 2022 08:23
Android Studio add local .aar reference

Add local .aar file

  1. basic build.gradle directory using flatDir
repositories {
    mavenCentral()
    flatDir {
 dirs 'libs'
@shau-lok
shau-lok / aes_python3.py
Created December 26, 2016 14:52
AES/ECB/PKCS#7加密 (python实现)
import base64
import json
from Crypto import Random
from Crypto.Cipher import AES
from star_site import settings
class AESCrypt:
@shau-lok
shau-lok / check-string.py
Created November 1, 2017 02:40
Check if a Python list item contains a string inside another string
# Check if a Python list item contains a string inside another string
# If you only want to check for the presence of abc in any string in the list, you could try
some_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456']
if any("abc" in s for s in some_list):
# whatever
# If you really want to get all the items containing abc, use
matching = [s for s in some_list if "abc" in s]
@shau-lok
shau-lok / aes.py
Created June 11, 2020 05:29
aes加密
import os
import sys
import base64
import json
from Crypto import Random
from Crypto.Cipher import AES
class AESCrypt:
@shau-lok
shau-lok / terminal-proxy.md
Created October 23, 2017 02:52
terminal set proxy

add to ~/.zshrc

alias setproxy="export ALL_PROXY=socks5://127.0.0.1:1080"
alias unsetproxy="unset ALL_PROXY"
alias ip="curl -i http://httpbin.org/ip"

then restart termainl

@shau-lok
shau-lok / terminal-du,df.sh
Last active January 17, 2019 23:33
terminal-du,df
# get current dir size!
$ du -sh
>>> 224M .
# get specific file (logs) size!
$ du -sh logs
>>> 2.7M logs
# get disk useage
$ df -h
@shau-lok
shau-lok / docker-mongo.sh
Last active January 17, 2019 23:33
docker-mongo
$ docker pull mongo:3.0.15-wheezy
$ docker run --name mongo -itd -p 27017:27017 mongo:3.0.15-wheezy --auth
# 增加admin管理账号
$ docker exec -it mongo mongo admin
> use admin
switched to db admin
@shau-lok
shau-lok / mysql-command.sql
Last active July 7, 2018 14:00
mysql-command
-- get now
select DATE(NOW());
-- date between
WHERE CONVERT(start_date, DATE) => DATE(NOW()) AND CONVERT(end_date, DATE) => DATE(NOW();
-- 7天前 2017-10-25
select convert(NOW(), DATE) - interval 7 day;
-- 今天
@shau-lok
shau-lok / nginx.conf
Created June 27, 2018 05:25
【nginx 错误】Upstream prematurely closed connection while reading upstream
Had a similar problem with my reverse proxy.
This is the configuration that finally did it for me:
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto http;