Skip to content

Instantly share code, notes, and snippets.

View palemoky's full-sized avatar
🤔
Make thinking a habit

Palemoky palemoky

🤔
Make thinking a habit
View GitHub Profile
@palemoky
palemoky / snake_and_camel_convert.php
Last active February 18, 2021 05:03
蛇形变量名与驼峰变量名的相互转换
<?php
// 驼峰命名法转蛇形命名法
function camel2snake ($camel) {
if (false !== strpos($camel, '_')) {
return $camel;
}
$capitalLetters = range('A', 'Z');
for ($i=1; $i < strlen($camel) - 1; $i++) {
if (in_array($camel[$i], $capitalLetters)) {
@palemoky
palemoky / synology_login_background.php
Created July 9, 2020 15:12
Synology login page automatically replaces bing wallpaper
<?php
// 获取图片信息
$img_info = file_get_contents('https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&pid=hp&FORM=BEHPTB&video=1');
// 请求失败时,使用「Server 酱」将错误信息推送至绑定的微信
if (false === $img_info) {
file_get_contents('https://sc.ftqq.com/xxx.send?text=' . urlencode('Get bing wallpaper error!'));
}
$img_obj = json_decode($img_info)->images[0];
@palemoky
palemoky / synology_login_background.sh
Last active July 9, 2020 15:13
Synology login page automatically replaces bing wallpaper
#!/bin/bash
# Author: Palemoky
# Fetch image
img=$(curl -s 'https://bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&pid=hp&FORM=BEHPTB&video=1')
img_path=$(jq .images[0].url <<< $img)
img_name=$(jq .images[0].urlbase <<< $img)
img_name=${img_name#*=}
@palemoky
palemoky / bing_wallpaper.sh
Created July 8, 2020 05:05
Get bing wallpaper via proxy
#!/bin/bash
# Author: Palemoky
# Change directory to work path
cd /path/to/work
pages=$(curl -sG --data-urlencode "country=美国" 'https://ip.jiangxianli.com/api/proxy_ips' | jq .data.last_page)
for page in $(eval echo {1..${pages}}); do
@palemoky
palemoky / cloudflare_ddns.sh
Last active July 8, 2020 05:08
Cloudflare DDNS
#!/bin/bash
# Author: Palemoky
email=
domain=
api_token=
dns_identifier=
zone_identifier=
@palemoky
palemoky / uploadFile.function.php
Created September 13, 2016 01:40
单文件上传函数
<?php
function uploadFile($fileInfo,$uploadPath = 'uploads',$maxSize = (2<<20),$allowExt = array('jpg','png','jpeg','gif','bmp'),$checkImg=true){
$filename = $fileInfo['name'];
$type = $fileInfo['type'];
$tmp_name = $fileInfo['tmp_name'];
$size = $fileInfo['size'];
$error = $fileInfo['error'];
// $maxSize = (2<<20);//限制上传文件的大小为2M,以字节为单位
// $allowExt = array('jpg','png','jpeg','gif','bmp');
@palemoky
palemoky / unitConvert.php
Created August 27, 2016 01:13
实现文件单位的快速转换,这是我的第一个函数
<?php
/**
* Created by PhpStorm
* User: Xinyu
* Date: 16/8/25
* Time: 下午10:09
*/
function unitConvert($scale){
if($scale >= (1<<30)){
$scale /= (1<<30);