乱码三千 – 分享实用IT技术

乱码三千 – 码出一个新世界


  • 首页

  • 归档

  • 搜索

关于移动设备唯一标识的获取

发表于 2022-07-13

起因

我们在做移动端开发时, 不可避免地会遇到需要获取设备唯一标识的问题

如果仅仅只需要给设备去重, 通常情况下我们可以考虑直接使用推送SDK生成的设备Token, 比如极光推送, 或者腾讯TPNS, App重装后这个token可能会变, 但重复的概率极低 只是并不具备唯一性

想要唯一性 以安卓设备为例, 其实有很多设备码可用, 比如IMEI, MAC地址等等, 但是为什么我们在实际应用中无法将它们用作唯一标识呢

我们挨个来分析一下

IMEI

Android中也叫DEVICE_ID, 是移动电话的唯一设备码, 相当于手机的身份证, 具备唯一性

但是:

  • 有通话功能的设备才有该码, 不是所有移动设备都具备拨号功能
  • 双卡双待会有两个IMEI值
  • 模拟器可以修改IMEI
  • Android10以上无法获取IMEI

网卡 Mac地址

其中包含硬件MAC地址和WLAN MAC地址(BSSID), 硬件MAC地址和硬件绑定, 具备唯一性 , 但是WLAN MAC地址通常是随机的 主要是为了避免隐私泄露, 每个热点在连接时会使用随机的地址

可即便是硬件Mac也存在不足之处:

  • 有网卡的设备才有Mac地址, 不是所有设备都具备联网功能
  • Mac地址可以通过软件欺骗性修改

蓝牙Mac地址

和WLAN Mac一样具备唯一性

但是:

  • 没有蓝牙的设备获取不到该值
  • 蓝牙需要保持开启状态才有值

ANDROID_ID

官方推荐使用的设备码, 具备唯一性

但是:

  • 设备恢复出厂设置 或者ROOT后 该值会改变
  • 国内定制系统的设备可能返回null
  • Android8以下无法获取Android_ID

PsuedoID

该方式是通过拼接硬件信息获取到的,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//获得独一无二的Psuedo ID
public static String getUniquePsuedoID() {
String serial = null;

String m_szDevIDShort = "35" +
Build.BOARD.length()%10+ Build.BRAND.length()%10 +

Build.CPU_ABI.length()%10 + Build.DEVICE.length()%10 +

Build.DISPLAY.length()%10 + Build.HOST.length()%10 +

Build.ID.length()%10 + Build.MANUFACTURER.length()%10 +

Build.MODEL.length()%10 + Build.PRODUCT.length()%10 +

Build.TAGS.length()%10 + Build.TYPE.length()%10 +

Build.USER.length()%10 ; //13 位

try {
serial = android.os.Build.class.getField("SERIAL").get(null).toString();
//API>=9 使用serial号
return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
} catch (Exception exception) {
//serial需要一个初始化
serial = "serial"; // 随便一个初始化
}
//使用硬件信息拼凑出来的15位号码
return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();

最终会得到类似于这样的一串ID:00000000-088ee-388eb-ffff-ffffe93ee2

这种方案只能做到小范围内唯一

因为:

  • 系统升级后 该值可能会变化
  • 同一批次出厂的设备可能出现值重复

总体来说 该方案可行性相对较高一些 重复的概率极低, 而且不需要获取用户权限

但是依然不够唯一

总结

以上所有的方案似乎都只是理论唯一, 真要用到实际产品中还是差了点, 如果非要准确一些可以考虑以下方案:

第一种
  • Android 8.0以下 使用 PsuedoID + DeviceId 来判断设备唯一性
  • Android 8.0及以上 使用PsuedoID + ANDROID_ID来判断设备唯一性
第二种

如果忽略大部分不能联网的设备, 可以使用Mac地址作为唯一标识, 由于Android6.0以上的版本无法获取Mac地址, 我们可以考虑从底层文件获取, Mac地址文件路径为:

1
/sys/class/net/wlan0/address

具体代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fun getMacAddr(): String {
return try {
loadFileAsString("/sys/class/net/wlan0/address")
.toUpperCase().substring(0, 17)
} catch (e: IOException) {
e.printStackTrace()
""
}
}

@Throws(IOException::class)
private fun loadFileAsString(filePath: String): String {
val fileData = StringBuffer(1000)
val reader = BufferedReader(FileReader(filePath))
val buf = CharArray(1024)
var numRead = 0
while (reader.read(buf).also { numRead = it } != -1) {
val readData = String(buf, 0, numRead)
fileData.append(readData)
}
reader.close()
return fileData.toString()
}
第三种

使用第三方设备唯一标识提供商, 比如数字联盟, 对于Android和IOS设备均适用

本文为作者原创转载时请注明出处 谢谢

乱码三千 – 点滴积累 ,欢迎来到乱码三千技术博客站

Android TV 电视盒子开发之远程网络调试

发表于 2022-07-12

硬件环境准备

一般电视盒子是不具备 USB 线调试功能 , 多数只能使用adb远程调试 , 国内的电视盒子提供一个 USB 的接口可以插 U 盘 ;

USB线调试 : 有些厂商提供了通过该接口进行 adb 调试的功能 , 如 小米 , 但是必须使用一根公对公的 USB 线 ;
( 国内的电视盒子一般要使用 USB 公对公接口 , 两头都是 USB 接口 , 有些电视没有该功能 )

远程调试 : 开发者电脑 与 Android TV , 必须在同一个局域网中 , 才能进行远程调试 ; ( 远程调试的速度一般要低于 )

开启开发者模式

先到 关于本机 界面 , 启用开发者模式 , 选择 关于本机 / 产品信息 / 软件版本 点击多次 , 即可启用开发者模式 ;

在这里插入图片描述

在这里插入图片描述

在 账户安全 界面的 ADB模式 选择 开启 即可进行远程调试 ;

在这里插入图片描述

查询 Android 电视局域网 IP 地址

进入设置界面 , 选择网络连接界面进入 ;

在这里插入图片描述

进入 网络设置 后 , 选择当前连接的 WIFI选项 , 进入 ;

在这里插入图片描述

此时就可以看到Android TV 的局域网 IP 地址 ;

在这里插入图片描述

开启远程连接

在上面得到安卓电视的 IP 地址是 192.168.1.104 , 先ping 一下 , 查看是否能ping 通 ;

在这里插入图片描述

如果 ping 不通 , 说明 电脑 与 电视 , 网络连接不通 , 无法进行 adb 调试 , 此时需要排查问题 , 电脑是否网络通常 , 电视网络是否通常 , 电脑和电视是否在同一个局域网中 ;

如果能ping 通 , 则使用 adb connect 命令 , 连接该远程设备 ;

1
adb connect 192.168.1.104:5555   #5555可以省略

执行上述命令 , 即可通过网络连接 adb 调试 ;

使用adb devices命令 , 可以查看当前使用 adb 调试的设备 ;

在这里插入图片描述

在Android Studio 中也可以看到该电视盒子 , 并且打印电视盒子的相关日志 , 向电视盒子中部署程序 , 跟使用 USB 调试手机一样 ;

在这里插入图片描述

以上远程调试方法不仅针对AndroidTV, 对于Android手机也是一样的流程

附加

  1. 如果出现连接不上的情况 可能是设备tcpip模式未开启, 可以执行以下指令开启:

    1
    adb -s 设备名 tcpip 5555
  2. 如果依然无法连接, 那么有可能是安卓设备没有开启adb远程调试或者端口未开放

    我们可以通过shell查看安卓设备5555端口是否开启, 指令如下:

    1
    adb -s 设备名 shell netstat -ntlp | grep 55

    img

  3. 如果端口没有开启, 则运行以下指令开启:

    1
    adb -s 设备名 shell setprop service.adb.tcp.port 5555
  4. 另外 如果要通过shell查看设备ip, 可以运行以下指令:

    1
    adb -s 设备名 shell ifconfig
或者

1
adb -s 设备名 shell netcfg
  1. 最后 断开设备连接

    1
    adb disconnect 192.168.1.104:5555

本文转载自: https://blog.csdn.net/shulianghan/article/details/118241238

乱码三千 – 点滴积累 ,欢迎来到乱码三千技术博客站

1
2


Mac快速开启http本地服务共享文件

发表于 2022-07-11

前言

有时候我们可能需要用手机访问电脑上的文件, 或者用手机测试电脑上编写的程序

此时 在同一个wifi网络的前提下我们可以这么做:

第一种 使用python

直接使用自带python工具开启http服务, 首先打开终端, 进入需要共享的目录,然后运行以下代码即可:

1
python -m SimpleHTTPServer  8000

如果是python3, 则将SimpleHTTPServer改成http.server

1
python -m http.server 8000

image-20220711144617056

紧接着就可以在浏览器上访问了: 在地址栏输入http://127.0.0.1:8000/或者http://localhost:8000/

局域网设备访问

如果局域网内其他设备访问, 则需要先获取到Mac的局域网Ip, 我们可以从系统偏好设置中的网络选项中查看到IP地址:

image-20220711145144222

然后使用http://局域网ip:8000这个地址就可以供其他设备访问啦

第二种 使用Apache

服务开启

Mac本身自带了Apache服务, 我们无需另外安装, 直接开启即可, 打开终端输入以下指令开启:

1
sudo apachectl start

打开服务后, 浏览器输入以下地址即可访问:

1
2
3
4
5
http://127.0.0.1

或者

http://localhost/

img

出现以上页面表示服务启动成功

此时 Apache默认的服务器根目录在:

1
/Library/WebServer/Documents

我们可以将需要共享的文件存放到该目录下, 比如我存放了一张名为111.gif的图片, 那么访问http://127.0.0.1/111.gif即可查看该图

Apache配置目录浏览

可是上面这种操作并不符合我们的预期, 我们想要输入地址后直接列出该目录下的所有文件

这需要对Apache配置文件中进行修改, 其配置文件路径为:

1
/etc/apache2/

文件名为httpd.conf, 修改之前建议大家进行一次备份

打开该文件, 在Options 后面追加一句Indexes

image-20220711151550133

重启apache服务后, 浏览器输入地址就能查看目录了

image-20220711151755973

每次更改了配置, 需要重启服务才能生效, 重启指令如下:

1
2
//重启apache:    
sudo apachectl restart
Apache其他配置
  1. 更改服务根目录

    搜索DocumentRoot关键字

    image-20220711152308158

  2. 更改访问端口

    搜索ServerName关键字, 去掉改行注释, 然后改为ServerName localhost:端口号或者ServerName 127.0.0.1:端口号

    image-20220711152426884

  3. 开启对PHP的支持

    搜索LoadModule, 去掉php7注释

    image-20220711152834896

局域网设备访问

Apache默认开启的是80端口, 因此直接http://局域网ip访问即可

服务关闭

服务一旦开启 每次电脑启动后Apache都会自动跟着开启

平常不用的时候我们可以关闭服务, 减少资源消耗, 关闭指令如下:

1
2
//关闭apache:    
sudo apachectl stop

总结

两种方式, 各有各的好处, apache的强大是毋庸置疑的, 如果只是任意文件夹共享, 直接使用python的方法会更加方便一些

本文为作者原创转载时请注明出处 谢谢

乱码三千 – 点滴积累 ,欢迎来到乱码三千技术博客站

Mac识别二维码 无需安装第三放应用

发表于 2022-07-09

前言

我们在浏览网页的时候经常会碰到二维码扫描需求, 一般情况下 我们会考虑将二维码图片发送到手机上 然后用手机识别 或者干脆装个第三方扫码软件

为了方便 (主要是懒) 接下来给大家介绍一种使用Safari浏览器二维码识别的方法

具体操作

第一步

选中要识别的二维码图片,把它拖到Safar浏览器打开。

第二步

随后右键点击二维码,选择在新标签页中打开...

新标签页中打开的就是二维码中的内容

是不是很简单 赶紧试试吧~

本文为作者原创转载时请注明出处 谢谢

乱码三千 – 点滴积累 ,欢迎来到乱码三千技术博客站

img标签随机获取高质量图片

发表于 2022-07-09

起因

博主打算为自己在vps上挂载的服务, 建立一个导航页, 于是写一个静态页面, 贴了几个超链接

后来, 感觉不美观, 就放了几张图片

服务器存储的图片看了几遍就看腻了, 于是找了一个高质量图片的api, 每次打开导航页都能看到随机的封面

开源图片api的使用

  • 我想获得300*300, 关于book和library的图片”

    1
    https://source.unsplash.com/300x300/?book,library
  • 将随机图片嵌入到html中

    1
    <img src="https://source.unsplash.com/300x300/?book,library">

随机封面效果展示

  • 第一次打开:

img

  • 第二次打开

img

  • 第三次打开

img

  • 第N次打开…

img

随机封面测试地址(页面每次刷新,都能看到不同的封面)

页面部分源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<body>
<section class="clearfix">
<div class="item">
<a href="http://git.zhaoolee.com">
<img src="https://source.unsplash.com/300x300/?program" alt="">
<div class="item-title">私有Git仓库</div>
</a>
</div>


<div class="item">
<a href="http://cloud.zhaoolee.com">
<img src="https://source.unsplash.com/300x300/?document" alt="">
<div class="item-title">私有云网盘</div>
</a>
</div>

<div class="item">
<a href="https://www.jianshu.com/u/c5d047065c42">
<img src="https://source.unsplash.com/300x300/?book,library" alt="">
<div class="item-title">简书主页</div>
</a>
</div>

<div class="item">
<a href="https://github.com/zhaoolee">
<img src="https://source.unsplash.com/300x300/?github" alt="">
<div class="item-title">Github主页</div>
</a>
</div>

<div class="item">
<a href="">
<img src="https://source.unsplash.com/300x300/?cartoon" alt="">
<div class="item-title">在线爬虫(建设中)</div>
</a>
</div>


<div class="item">
<a href="">
<img src="https://source.unsplash.com/300x300/?beauty" alt="">
<div class="item-title">资源分享(建设中)</div>
</a>
</div>
</section>
</body>

小结:

  • 使用随机化开源图片封面, 能让我们每次打开页面都有惊喜.
  • 对于刚刚接触前端的小伙伴, 使用开源的图片库, 能让你的页面更加丰富多彩, 提升学习的兴趣.
  • 对于前端老司机,可以获取定制化的开源图片, 提升页面展示效果.
  • 如果你对图片的质量有极致的追求,https://source.unsplash.com 提供了丰富的接口参数设置,可以定制化随机图片的范围, 当然也可以在unsplash.com 注册一个账号, 订阅特别主题的图片

本文转载自: https://cloud.tencent.com/developer/article/1344365?from=15425

乱码三千 – 点滴积累 ,欢迎来到乱码三千技术博客站

给Hexo添加Github贡献日历图

发表于 2022-07-08

图示

样式一

Zfour's github stats

样式二

样式三

小冰的插件效果

接下来给大家介绍它们的实现方法

代码实现

第一种

只需将username的值设置为你的github用户名即可:

1
https://github-readme-stats.vercel.app/api?username=github用户名

然后以图片的形式进行加载:

1
![](https://github-readme-stats.vercel.app/api?username=github用户名)

如果是放置在html中, 替换用户名后 拷贝以下代码:

1
<img src="https://github-readme-stats.vercel.app/api?username=github用户名" referrerpolicy="no-referrer" ">

项目GitHub: github-readme-stats

第二种

和第一种类似, 尾部改成github用户名即可

1
https://ghchart.rshah.org/github用户名

然后以图片的形式进行加载:

1
![](https://ghchart.rshah.org/github用户名)

如果是放置在html中, 替换用户名后 拷贝以下代码:

1
<img src="https://ghchart.rshah.org/github用户名"  referrerpolicy="no-referrer" ">

项目GitHub: githubchart-api

第三种

这种是以hexo插件的形式实现, 具体步骤如下:

  1. 安装插件

    1
    npm i hexo-githubcalendar --save
  2. hexo根目录下的config文件添加如下配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    # Ice Kano Plus_in
    # Hexo Github Canlendar
    # Author: Ice Kano
    # Modify: Lete乐特
    githubcalendar:
    enable: true
    enable_page: /
    user: 你的github用户名
    layout:
    type: id
    name: recent-posts
    index: 0
    githubcalendar_html: '<div class="recent-post-item" style="width:100%;height:auto;padding:10px;"><div id="github_loading" style="width:10%;height:100%;margin:0 auto;display: block"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50" xml:space="preserve"><path fill="#d0d0d0" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z" transform="rotate(275.098 25 25)"><animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"></animateTransform></path></svg></div><div id="github_container"></div></div>'
    pc_minheight: 280px
    mobile_minheight: 0px
    color: "['#ebedf0', '#fdcdec', '#fc9bd9', '#fa6ac5', '#f838b2', '#f5089f', '#c4067e', '#92055e', '#540336', '#48022f', '#30021f']"
    api: https://python-github-calendar-api.vercel.app/api
    # api: https://python-gitee-calendar-api.vercel.app/api
    calendar_js: https://cdn.jsdelivr.net/gh/Zfour/hexo-github-calendar@1.21/hexo_githubcalendar.js
    plus_style: ""

    将user属性修改为你的github用户名即可,

    • 其他属性用法可参见《教程:hexo-githubcalendar 插件 1.0》

    • 涉及主题: hexo-theme-butterfly

    • 插件GitHub: hexo-github-calendar

本文为作者原创转载时请注明出处 谢谢

乱码三千 – 点滴积累 ,欢迎来到乱码三千技术博客站

解决图片的防盗链导致图片显示不出来

发表于 2022-07-08

前言

你平常有可能将图片存放到github、gitee 或者博客园 简书等等地方, 供静态博客使用, 除了github之外 大部分国内的网站都设置了图片防盗链

如果直接使用会导致图片无法显示

解决防盗链的问题其实也非常简单

解决方案

在html的head标签中添加如下代码即可:

1
<meta name="referrer" content="never">

如果你只想处理某部分图片, 可以针对性设置, 比如:

1
<img src="xxxx.jpg" referrerPolicy="no-referrer" />

批量替换图片域名

偶尔图床CDN挂了需要更换域名, 一些文章存放在数据库,比如wordpress网站 为了方便 可以采用js动态替换的方式, 将以下代码拷贝到html页脚标签中即可

1
2
3
4
5
6
7
8
<script>

let context = Array.prototype.map.call(document.images, (event) => {
event.src = event.src.replace("cdn.jsdelivr.net/gh/xxx/xxx", "raw.staticdn.net/xxx/xxx/master")

});

</script>

另外还可以动态添加meta标签

1
2
3
4
5
6
7
8
9
10
11
const addMeta = (name, content) => {
const meta = document.createElement('meta');
meta.content = content;
meta.name = name;
document.getElementsByTagName('head')[0].appendChild(meta);
};

addMeta(
'referrer',
'never',
);

本文为作者原创转载时请注明出处 谢谢

乱码三千 – 点滴积累 ,欢迎来到乱码三千技术博客站

Android锁屏息屏状态下弹出界面

发表于 2022-07-07

前言

最近公司客户端项目需要支持锁屏息屏状态下弹出应用界面, 类似于微信来电显示, 实现方法很简单, 如下:

实现步骤

第一步 在清单文件中添加休眠唤醒和解锁权限
1
2
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
第二步 在需要弹出显示的Activity的onCreate方法中添加相应flag代码
1
2
3
4
5
6
7
8
9
10
11
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED //锁屏显示
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD //解锁
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON //保持屏幕不息屏
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);//点亮屏幕

setContentView(R.layout.activity_main);

}
第三步 触发Activity启动

比如推送触发 后台Service触发 或者IM长连接信令触发等等

1
2
3
4
private void openActivity(Context context, String msg) {
Intent intent = new Intent(context, MainActivity.class)ialarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(intent);
}
完毕

本文为作者原创转载时请注明出处 谢谢

乱码三千 – 点滴积累 ,欢迎来到乱码三千技术博客站

关于Github加速方法总结

发表于 2022-07-07

前言

最近网站大部分图片访问变慢, 原因出在jsdelivr加速失效, 为此我更换了CDN域名, 顺带总结一下github加速小技巧

GitHub访问加速

1. 使用镜像访问

这相当于是克隆版的 GitHub , 网站的内容和 GitHub 是完整同步, 可以在这个网站里面进行下载克隆等操作, 镜像地址如下:

  • https://hub.fastgit.org

使用示范:

1
2
3
4
5
https://github.com/typecho/typecho

可以改成

https://hub.fastgit.xyz/typecho/typecho
2.修改Host文件加速

首先需要获取对应域名实际ip地址, 可以通过以下网站查询:

  • https://www.itdog.cn/

  • https://www.ipaddress.com/

image-20220707154831063

需要查询的地址有:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 基本地址
'github.com',
'gist.github.com',
'assets-cdn.github.com',
'raw.githubusercontent.com',
'gist.githubusercontent.com',
'cloud.githubusercontent.com',
'camo.githubusercontent.com',
'avatars0.githubusercontent.com',
'avatars1.githubusercontent.com',
'avatars2.githubusercontent.com',
'avatars3.githubusercontent.com',
'avatars4.githubusercontent.com',
'avatars5.githubusercontent.com',
'avatars6.githubusercontent.com',
'avatars7.githubusercontent.com',
'avatars8.githubusercontent.com',
'avatars.githubusercontent.com',
'github.githubassets.com',
'user-images.githubusercontent.com',
'codeload.github.com',
'favicons.githubusercontent.com',
'api.github.com'

一个一个查询太过麻烦, 可以使用python脚本快速批量获取, 代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# coding:utf-8

import socket

def output_hosts():
domains = ['github.com',
'gist.github.com',
'assets-cdn.github.com',
'raw.githubusercontent.com',
'gist.githubusercontent.com',
'cloud.githubusercontent.com',
'camo.githubusercontent.com',
'avatars0.githubusercontent.com',
'avatars1.githubusercontent.com',
'avatars2.githubusercontent.com',
'avatars3.githubusercontent.com',
'avatars4.githubusercontent.com',
'avatars5.githubusercontent.com',
'avatars6.githubusercontent.com',
'avatars7.githubusercontent.com',
'avatars8.githubusercontent.com',
'avatars.githubusercontent.com',
'github.githubassets.com',
'user-images.githubusercontent.com',
'codeload.github.com',
'favicons.githubusercontent.com',
'api.github.com'
]

with open('hosts.txt', 'w') as f:
f.write('```\n')
f.write('# GitHub Start \n')
for domain in domains:
print('Querying ip for domain %s'%domain)
ip = socket.gethostbyname(domain)
print(ip)
f.write('%s %s\n'%(ip, domain))
f.write('# GitHub End \n')
f.write('```\n')



if __name__ == '__main__':
output_hosts()

执行脚本后, 得到如下结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# GitHub Start 
140.82.121.3 github.com
140.82.121.3 gist.github.com
185.199.110.153 assets-cdn.github.com
185.199.108.133 raw.githubusercontent.com
185.199.111.133 gist.githubusercontent.com
185.199.110.133 cloud.githubusercontent.com
185.199.111.133 camo.githubusercontent.com
185.199.111.133 avatars0.githubusercontent.com
185.199.110.133 avatars1.githubusercontent.com
185.199.111.133 avatars2.githubusercontent.com
185.199.109.133 avatars3.githubusercontent.com
185.199.108.133 avatars4.githubusercontent.com
185.199.111.133 avatars5.githubusercontent.com
185.199.109.133 avatars6.githubusercontent.com
185.199.109.133 avatars7.githubusercontent.com
185.199.110.133 avatars8.githubusercontent.com
185.199.108.133 avatars.githubusercontent.com
185.199.111.154 github.githubassets.com
185.199.109.133 user-images.githubusercontent.com
140.82.112.9 codeload.github.com
185.199.110.133 favicons.githubusercontent.com
192.30.255.116 api.github.com
# GitHub End

将以上内容拷贝到系统Host文件中即可, 不同操作系统host文件所在路径不一样:

  1. Windows系统:修改C:\Windows\System32\drivers\etc\hosts文件
1
2
# 网络刷新
ipconfig /flushdns
  1. Linux系统:修改C:\Windows\System32\drivers\etc\hosts文件

    1
    2
    # 网络刷新
    systemctl restart network

仓库Clone下载加速

1. 将仓库克隆到Gitee

image-20220707151023271

2.使用Fast-GitHub浏览器插件

Fast-GitHub

image-20220707151433012

3.第三方网站解析加速

Toolwa

image-20220707151746721

gh-proxy

image-20220707152513916

Ghproxy

image-20220707155957192

image-20220707160024075

Raw资源加速

1. 使用fastgit

将raw.githubusercontent.com替换成raw.staticdn.net或者raw.gitmirror.com

使用示例

实际上fastgit功能很丰富, 几乎囊括了github所有. 具体如下表:

反代列表

站源 地址 缓存
github.com hub.fastgit.xyz 无
raw.githubusercontent.com raw.staticdn.net 无
github.githubassets.com assets.fastgit.org 无
customer-stories-feed.github.com customer-stories-feed.fastgit.org 480 分钟
Github Download download.fastgit.org 480 分钟
GitHub Archive archive.fastgit.org 无

fastgit官网

2.使用ghproxy

在https://raw.githubusercontent.com地址前面添加https://ghproxy.com/

比如:

1
https://ghproxy.com/https://raw.githubusercontent.com/stilleshan/ServerStatus/master/Dockerfile

本文为作者原创转载时请注明出处 谢谢

乱码三千 – 点滴积累 ,欢迎来到乱码三千技术博客站

Hexo NexT 主题渲染 Mermaid 绘图

发表于 2022-07-05

前言

由于我的Hexo博客中的Next主题是旧版, 并不支持mermaid, 因此需要手动配置, 步骤如下

配置步骤

第一步 安装 mermaid 插件

在博客的根目录下,执行以下命令安装 hexo-filter-mermaid-diagrams 插件

1
$ npm install hexo-filter-mermaid-diagrams --save
第二步 NexT 启用 Mermaid

打开 NexT 主题的 _config.yml 配置文件,添加以下代码:

1
2
3
4
5
# Mermaid tag
mermaid:
enable: true
# Available themes: default | dark | forest | neutral
theme: default
第三步 添加script脚本

打开next/layout/_partials/footer.swig文件, 添加以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{% if theme.mermaid.enable %}
<script type="text/javascript" src='https://unpkg.com/mermaid@9.0.0/dist/mermaid.min.js'></script>
<script>
if (window.mermaid) {
var mermaid_config = {
startOnLoad: true,
theme: '{{theme.mermaid.theme}}',
flowchart:{
useMaxWidth: false,
htmlLabels: true
}
}
mermaid.initialize(mermaid_config);
}
</script>
{% endif %}

至此 配置完毕


js本地引用

如果你打算将js文件存放在本地, 可以将js文件放置到next/source/js/src目录下, 那么script脚本改成如下即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{% if theme.mermaid.enable %}
<script type="text/javascript" async src='js/src/mermaid.min.js'></script>
<script>
if (window.mermaid) {
var mermaid_config = {
startOnLoad: true,
theme: '{{theme.mermaid.theme}}',
flowchart:{
useMaxWidth: false,
htmlLabels: true
}
}
mermaid.initialize(mermaid_config);
}
</script>
{% endif %}

本文为作者原创转载时请注明出处 谢谢

乱码三千 – 点滴积累 ,欢迎来到乱码三千技术博客站

1…131415…48

乱码三千

android程序员一枚,擅长java,kotlin,python,金融投资,欢迎交流~

479 日志
139 标签
RSS
© 2024 乱码三千
本站总访问量次
由 Hexo 强力驱动
|
主题 — NexT.Muse v5.1.4
0%