Skip to content

Instantly share code, notes, and snippets.

@imbyc
imbyc / index.html
Last active April 22, 2020 15:42
一个简单的维护页面,没有多余css,图片放在github,走jsdelivr加速,放心使用 // source https://jsbin.com/yenuyon
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="format-detection" content="telephone=no">
<title>系统维护</title>
<style>
body {
@imbyc
imbyc / 右移.php
Created May 2, 2020 14:32
[PHP实现JavaScript的位移运算符] https://zhile.io/2018/06/21/php-equivalent-javascript-bitwise-operators.html #无符号右移 #位运算
<?php
/**
* >> javascript operator in php x86_64
* @param int $v
* @param int $n
* @return int
*/
function rr($v, $n)
{
@imbyc
imbyc / getRemoteFileSize.php
Last active May 2, 2020 14:46
[获取远程文件大小] https://blog.cooldev.cn/3042595489.html #remote-filesize #PHP #远程文件大小
<?php
/**
* 获取远程文件大小
* @param $url
* @return int|null
*/
function getRemoteFileSize($url)
{
$size = null;
@imbyc
imbyc / getVersionFromFile.php
Last active October 16, 2020 07:11
[PHP 读取 exe\dll 文件版本号] 遇到大文件会有问题 #版本号 #exe #版本
<?php
/**
* PHP 读取 exe\dll 文件版本号
*
* @auth @腾讯电脑管家(https://zhidao.baidu.com/question/246143241010222924.html)
* @param $filename 目标文件
* @return string|string[]
*/
function getVersionFromFile($filename)
@imbyc
imbyc / bankCardAttribution.js
Created May 2, 2020 14:51
[通过银行卡号查询银行类型和银行卡类型] https://www.52pojie.cn/thread-1120776-1-1.html
//cardType:DC->储蓄卡,CC->信用卡
function bankCardAttribution(bankCard){
var cardTypeMap = {
DC: "储蓄卡",
CC: "信用卡",
SCC: "准贷记卡",
PC: "预付费卡"
};
function extend(target, source) {
@imbyc
imbyc / checkForm.js
Created May 21, 2020 08:47
[js验证,包含多种验证] 包含验证和判断,从别的网站找到的 https://appoint.yihu.com/appoint/js/checkForm.js?v=20181211 #js #验证
/**验证Email**/
function isEmail(str) {
if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
return true;
else
return false
}
/**数字检查**/
function isNum(str) {
return str.match(/\D/) == null
@imbyc
imbyc / type.js
Last active May 26, 2020 02:41
[js 比typeof运算符更准确的类型判断] 使用Object.prototype.toString判断 https://xugaoyi.com/pages/fd4a16d56b83c1bc/ #js
var type = function (o){
var s = Object.prototype.toString.call(o)
return s.match(/\[object (.*?)\]/)[1].toLowerCase()
}
type({}); // "object"
type([]); // "array"
type(5); // "number"
type(null); // "null"
type(); // "undefined"
type(/abcd/); // "regex"
function shuffle(arr) { // 随机打乱数组
let _arr = arr.slice() // 调用数组副本,不改变原数组
for (let i = 0; i < _arr.length; i++) {
let j = getRandomInt(0, i)
let t = _arr[i]
_arr[i] = _arr[j]
_arr[j] = t
}
return _arr
}
@imbyc
imbyc / pages.js
Created May 26, 2020 02:46
[js 将一维数组按指定长度转为二维数组] https://xugaoyi.com/pages/f1acb712033ac8da/
function pages(arr, len) {
const pages = []
arr.forEach((item, index) => {
const page = Math.floor(index / len)
if (!pages[page]) {
pages[page] = []
}
pages[page].push(item)
})
return pages
@imbyc
imbyc / hasNotch.js
Created June 3, 2020 08:18
[js 判断是否是刘海屏]
// 判断刘海屏
function hasNotch() {
var proceed = false
var div = document.createElement('div')
if (CSS.supports('padding-bottom: env(safe-area-inset-bottom)')) {
div.style.paddingBottom = 'env(safe-area-inset-bottom)'
proceed = true
} else if (CSS.supports('padding-bottom: constant(safe-area-inset-bottom)')) {
div.style.paddingBottom = 'constant(safe-area-inset-bottom)'
proceed = true