Skip to content

Instantly share code, notes, and snippets.

@hplc
hplc / Kid_Monitor.py
Last active September 17, 2023 11:56
Monitor Kid using computer, just let kid using some limited programs, close other browsers. If the kid switch window, then make sound to alerm. Works for Windows system.
# To run this program in backgorund, run it on command line: pythonw Kid_Monitor.py
# SoundVolumeView.exe is a simple tool for Windows that adjust system volume level.
# Can be downloaded from https://www.nirsoft.net/utils/sound_volume_view.html.
import win32gui
import time
import winsound
import os
i = 0
while i<=1:
@hplc
hplc / kill_slow_mysql_query.sh
Created April 1, 2020 12:34
Kill slow mysql query.
#!/bin/sh
cmd="mysql -uusername -ppassword";
$cmd -e 'show processlist\G' |\
egrep -b5 'Time: [0-9]{2,}' |\
grep 'Id:' |\
cut -d':' -f2 |\
sed 's/^ //' |\
while read id
@hplc
hplc / monitor_ocserv.sh
Created April 1, 2020 08:36
Test ocserv running status in OpenWrt, and restart it if not.
#!/bin/sh
service=ocserv
if test $(netstat -na | grep 0.0.0.0:443 | wc -l) = 2
then
echo "$service is running!"
else
/etc/init.d/$service start
fi
@hplc
hplc / monitor_atd.php
Created March 30, 2020 12:36
Monitor atd service and restart it if not running.
#!/usr/bin/php
<?php
$cmd = '/sbin/service atd';
$atd = `$cmd status`;
// var_dump($atd);
if (! preg_match('/is running/', $atd))
{
$result = `$cmd start`;
echo $result;
@hplc
hplc / coronavirus.html
Last active March 3, 2020 11:36
Display coronavirus infected communities of Shenzhn on Amap.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<link rel="shortcut icon" href="https://www.helloit.info/sites/www.helloit.info/files/helloit_0.ico" type="image/vnd.microsoft.icon" />
<style type="text/css">
body,html,#container{
height: 100%;
@hplc
hplc / grab_coronavirus_infected_communities.php
Last active February 6, 2020 12:44
Get the name of coronavirus infected communities in Shenzhen and convert to JSON.
<?php
$url = 'http://sz.bendibao.com/news/202023/827759.htm';
$page = file_get_contents($url);
$page = substr($page, strpos($page, '<strong>福田区</strong>')); // Start position
$page = substr($page, 0, strpos($page, '确诊病例曾到过我的小区,怎么办?')); // End position
$page = preg_replace('/&nbsp;/', '', $page);
$page = str_replace('<section powered-by="xiumi.us" font-size:15px;letter-spacing:0.544px;background-color:#ffffff;text-align:center;word-wrap:break-word="" !important;"="" style="margin: 10px 0px; padding: 0px; max-width: 100%; box-sizing: border-box; color: rgb(51, 51, 51);">', '', $page);
// echo $page;
@hplc
hplc / exam.php
Last active November 12, 2019 23:19
PHP Script to do exam.
#!/usr/bin/php
<?php
/* Contents of exam.csv file like this:
奈奎斯特定理是哪一年提出来的?,1928
已知无线电频率为1GHz,其波长为(单位为m):,0.3
已知WiFi的频率为2.4GHz,其波长为(单位为m):,0.125
已知WiFi的频率为5GHz,其波长为(单位为cm):,6
......
*/
@hplc
hplc / check_web_servers.php
Created October 22, 2019 09:58
Check a bunch of web servers' online status.
<!DOCTYPE html>
<html>
<head>
<title>16CNetG5-2</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
/* Contents of 16CNetG5-2.csv file like this:
#!/usr/bin/php
<?php
$terms = [
"TD-LTE与WLAN系统共存的干扰隔离度要求为多少(dB)" => "87",
"TD-LTE与WLAN系统共存的空间距离要求为水平距离多少m" => "54",
"TD-LTE与WLAN系统共存的空间距离要求为垂直距离多少m" => "2.3",
"LTE相对3G“少一层,多一口”中的少一层是少了哪一层" => "RNC",
"LTE相对3G“少一层,多一口”中的多一口是多了哪个口" => "X2",
"采用256-QAM高阶调制技术时,每个符号能代表多少位比特的信息" => "8",
#!/usr/bin/php
<?php
$terms = [
"干扰发生影响的基本要素有三个:干扰源、传播途径和" => "被干扰源",
"控制共站干扰影响的三要素是:抑制干扰源、切断干扰传播途径,提高被干扰源敏感器件的" => "抗干扰性能",
"抑制干扰源的手段有:提高发射机的性能和" => "增加发射端滤波器",
"切断干扰传播途径的手段有:调整频点、设置保护带宽和" => "增加隔离度",
"提高被干扰源敏感器件的抗干扰性能的主要手段:" => "提高接收机的性能",
"空间隔离度需求由两个因素决定:发射端发送干扰大小和" => "接收机允许接收的最小干扰",