笔记

简介

记笔记用,持续更新。

cmd

cd指定路径:

win10: cd /d [path]

改控制台编码:

CHCP [num]
936 GBK(一般情况下为默认编码)
437 美国英语
65001 utf-8

滚动效果
dir /s
配合color 2食用

gcc

编译

g++ [fileNameIn] -std=c++11 -o [fileNameOut]
-std=c++11 : 指定标准
-o :指定输出文件

ffmpeg

一个强大硬核的视频类软件下载地址

ffmpeg简单使用教程 转码、压制、提取、截取、合并、录屏等
常用命令:

流式mp4转mp4(摘自cv7306643)

ffmpeg.exe -i [vedioInput.mp4] -f mp4 [videoOutput.mp4]

mp4转mp3(摘自此处):

ffmpeg -i a.mp4 -f MP3 a1.mp3

更多命令
ffplay:
FFplay使用指南
ffplay的快捷键以及选项

C++

try exception

#include <stdio.h>
#include <iostream>
using namespace std;
int f(int x) {
	if ( x<0 ) {
		throw double(1);
	} else if ( x==0 ) {
		throw int(10);
	}
	return 1/x;
}

int g(int x) {
	if (x==0) {
		cout << "here" << endl;
		throw bool(false);
	}
	return f(x);
}

int main(void){
	while(true){
		int a;
		cin>>a;
		try{
			g(a);
		} catch (int & e) {
			cout << "e = " << e << endl; //log
		} catch (double &e){
			cout << "e = " << e << endl; //log
		} catch (bool &e) {
			cout << "e = " << e << endl; //log
		}
	}
	return 0;
}

windows自带的文件选择器

(摘自此处)

string openDlg(){
	TCHAR szBuffer[MAX_PATH] = {0};   
	OPENFILENAME ofn= {0};   
	ofn.lStructSize = sizeof(ofn);   
	ofn.hwndOwner = NULL;   
	ofn.lpstrFilter = ("Exe文件(*.exe)\0*.exe\0所有文件(*.*)\0*.*\0");//要选择的文件后缀   
	ofn.lpstrInitialDir =  ("C:\\Program Files");//默认的文件路径   
	ofn.lpstrFile = szBuffer;//存放文件的缓冲区   
	ofn.nMaxFile = sizeof(szBuffer)/sizeof(*szBuffer);   
	ofn.nFilterIndex = 0;   
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER ;//标志如果是多选要加上OFN_ALLOWMULTISELECT  
	BOOL bSel = GetOpenFileName(&ofn);   
	return szBuffer;
}

添加/删除windows右键菜单

(摘自此处)
原作者没有在函数末尾返回true表成功,这里补上了

bool add(string strMenuText, string strApplication){
	//添加右键菜单项"加密该文件"
	HKEY hresult;  
	long value;
	//string strRegKeyName = "我的加密";
	string strRegKeyName = strMenuText;
	string strRegKey = "*\\shell\\" + strRegKeyName;//if txt file, please use "txtfile\\shell\\用我的文本编辑程序打开"
	string strRegSubkey="*\\shell\\" + strRegKeyName + "\\command";
	//string strMenuText="加密该文件"; 
	//string strApplication="E:\\Desktop\\Use\\xsearch_CHS.exe %1";
	strApplication = strApplication + " %1";
	DWORD dwPos;  
	//创建“加密”子键,并设置右键菜单项的名称
	value=RegCreateKeyEx(HKEY_CLASSES_ROOT,(LPSTR)(LPCSTR)strRegKey.c_str(),0,NULL,REG_OPTION_NON_VOLATILE,KEY_CREATE_SUB_KEY|KEY_ALL_ACCESS,NULL,&hresult,&dwPos);
	if(0 != value){
        cout << "1 value!=0" << endl;
        cout << "value = " << value << endl;
		return false;
	}
	
	value=RegSetValueEx(hresult,NULL,0,REG_SZ,(BYTE*)(LPCTSTR)strMenuText.c_str(), strMenuText.length()); 
	if(0 != value){
        cout << "2 value!=0" << endl;
        cout << "value = " << value << endl;
		return false;
	}
	//创建“command”子键,并设置关联的应用程序
	value=RegCreateKeyEx(HKEY_CLASSES_ROOT,(LPSTR)(LPCSTR)strRegSubkey.c_str(),0,NULL,REG_OPTION_NON_VOLATILE,KEY_CREATE_SUB_KEY|KEY_ALL_ACCESS,NULL,&hresult,&dwPos);
	if(0 != value){
        cout << "3 value!=0" << endl;
        cout << "value = " << value << endl;
		return false;
	}
	
	value=RegSetValueEx(hresult,NULL,0,REG_SZ,(const BYTE*)(LPCTSTR)strApplication.c_str(),strApplication.length());
	if(0 != value){
        cout << "4 value!=0" << endl;
        cout << "value = " << value << endl;
		return false;
	}
	//关闭注册表
	::RegCloseKey(hresult);
    return true;
}
bool del(string strMenuText){
	HKEY hKey;
	//string strRegKeyName = "我的加密";
	string strRegKeyName = strMenuText;
	string strRegKey="*\\shell\\" + strRegKeyName;  
	string strRegSubkey="*\\shell";  
	
	//打开父键
	long lRet=::RegOpenKeyEx(HKEY_CLASSES_ROOT,(LPSTR)(LPCSTR)strRegKey.c_str(),0,KEY_READ,&hKey);  
	if(0 != lRet){
		return false;
	}
	//删除“command”子键  
	lRet = ::RegDeleteKey(hKey,LPCTSTR("command"));  
	if(0 != lRet){
		return false;
	}
	::RegCloseKey(hKey);  
	
	lRet=::RegOpenKeyEx(HKEY_CLASSES_ROOT,(LPSTR)(LPCSTR)strRegSubkey.c_str(),0,KEY_READ,&hKey);
	if(0 != lRet){
		return false;
	}
	//删除“加密”子键  
	lRet = ::RegDeleteKey(hKey,LPCTSTR(strRegKeyName.c_str()));  
	if(0 != lRet){
		return false;
	}
	::RegCloseKey(hKey);
    return true;
}

bmp转 LED|OLED C51字模

使用方式:
将图片保存为24位bmp格式,将取所有非白色(0xFFFFFF)像素。数据排列方式为从左到右、从上到下:
在这里插入图片描述

#include <sys/types.h>
#include <sys/stat.h>
// #include <unistd>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char const *argv[]){
	// freopen("out.txt", "w", stdout);
	int fd = open("c.bmp", O_RDONLY);
	for ( int i=0; i<54; i++ ) {
		char ch;
		read(fd, &ch, 1);
		printf("%d\n", ch);
	}
	//load bmp
	int w;
	int h;
	lseek(fd, 0x1c, SEEK_SET);
	short bitCount;
	read(fd, &bitCount, 2); int error_line = __LINE__;
	if ( bitCount != 24 ) {
		printf("文件'%s'中第%d行错误: 请保存为24位bmp格式\n", __FILE__, error_line);
		printf("error in file '%s' line %d: please save as 24 bit bmp\n", __FILE__, error_line);
		return -1;
	}
	lseek(fd, 0x12, SEEK_SET);
	read(fd, &w, 4);
	read(fd, &h, 4);
	bool is_daoxiang = h>0;
	if ( h<0 ) {
		h = -h;
	}
	lseek(fd, 54, SEEK_SET);
	char buf[w*h];
	for( int y=0; y<h; y++ ) {
		for ( int x=0; x<w; x++ ) {
			unsigned char r,g,b;
			read(fd, &r, 1);
			read(fd, &g, 1);
			read(fd, &b, 1);
			// if ( r==0xff && g==0xff && b==0xff ) {
			// 	printf("..");
			// } else {
			// 	printf("[]");
			// }
			if (is_daoxiang) {
				buf[(h-1-y)*w+x] = !( r==0xff && g==0xff && b==0xff );
			} else {
				buf[y*w+x] = !( r==0xff && g==0xff && b==0xff );
			}
		}
		char tmp[4];
		read(fd, &tmp, 4-(w*3)%4);
		// printf("\n");
	}
	printf("\n");

	// print bmp
	printf("/*\n");
	for ( int y=0; y<h; y++ ) {
		for (int x=0; x<w; x++) {
			printf(buf[y*w+x]?"[]":"..");
		}
		printf("\n");
	}
	printf("*/\n");

	// output C51
	int line_width = 16;
	unsigned char ch = 0;
	printf("/*w = %d, h = %d, %d bytes total*/\n", w,h, w*h/8);
	for (int i=0; i<w*h; i++) {
		ch <<= 1;
		ch += buf[i];
		if (i%8==7) {
			printf("0x%02x,", ch);
			ch = 0;
			if (i%(8*line_width)==8*line_width-1) {
				printf("\n");
			}
		}
	}
	// fclose(stdout);
	// system("out.txt");
	return 0;
}

python

import的用法

(摘自此处)
from . import module_name。导入和自己同目录下的模块。
from .package_name import module_name。导入和自己同目录的包的模块。
from … import module_name。导入上级目录的模块。
from …package_name import module_name。导入位于上级目录下的包的模块。

高级用法

二维遍历:

入门:

for x in range(10):
	for y in range(10):
		print( (x,y) )

初级:

for p in [(x,y) for x in range(10) for y in range(10)]:
	print(p)

高级(笛卡尔积):

from itertools import product
for p in product(range(10), range(10)):
	print(p)
列表推导式

例如:求小于30的数字中4、7的倍数的平方,要求装入列表中
朴素代码:

numbers = []
for x in range(30):
	if x%4==0 or x%7==0:
		numbers.append(x*x)
print(numbers)

列表推导式:

print([x*x for x in range(30) if x%4==0 or x%7==0])

更改控制台字体颜色

(摘自此处)

import colorama
from colorama import Fore, Back, Style

colorama.init()

text = "The quick brown fox jumps over the lazy dog"

print(Fore.RED + text)
print(Back.GREEN + text + Style.RESET_ALL)
print(text)

自动输入

参考自Python自动输入【新手必学】
17行贪吃蛇出处

import pyautogui
import time
# pyautogui.click(415,149)
# pyautogui.typewrite([ 'tab' ,'tab'],'0.25')#pyautogui.typewrite( 'tab' , '0.25')
# pyautogui.typewrite(['l','i',' h','a','i','g' , 'u',' a' ,'n','1', 'tab'], '0.25')
# pyautogui.typewrite(['1','7','0','6','3' ,'0' ,'0', '1' , 'tab'],'0.25')
# pyautogui.typewrite(['z','y','x','y','1','tab'],'0.25')
# pyautogui.typewrite( '130035122' ,'0.25')


time.sleep(5)
s = """#include <windows.h>
#include <conio.h>
int main() {
int W = 20, S = W * W, * m, z[2] = { 0 }, l = 3, i, c = 'D', C, * p, f;
SetConsoleCursorInfo(GetStdHandle((DWORD)-11), &(CONSOLE_CURSOR_INFO){25});
for (srand(m = calloc(S, 4)), C = m[1] = -1; C - 27; Sleep(100)) {
if (_kbhit())C = _getch() & 95, C - 65 && C - 68 &&
C - 83 && C - 87 || (C ^ c) & 20 ^ 4 && (c = C);
p = z + !!(c & 2), * p += c / 3 & 2, * p = (-- * p + W) % W;
f = 1, * (p = m + *z + z[1] * W) > 0 && (C = 27);
for (; *p && (m[i = rand() % S] || (--m[i], ++l, --f)););
SetConsoleCursorPosition(GetStdHandle((DWORD)-11), (COORD){0});
for (i = 0, *p = l; i < S; _cputs("  "), ++i % W || _cputs("\\n"))
SetConsoleTextAttribute(GetStdHandle((DWORD)-11),
m[i] > 0 ? m[i] -= f, 192 : m[i] ? 160 : 240);"""
for i in s:
	pyautogui.typewrite([i], '0')

文本文件搜索

import os

file_list = []

def get_files(dir = ''):
	# print(dir)
	for file in os.listdir(dir):
		path = dir + '/' + file
		if os.path.isdir(path):
			get_files(path)
		else:
			file_list.append(path)
			# print(path)
get_files(os.getcwd())

while True:
	key = input()
	for file in file_list:
		line_cnt = 1
		for line in open(file):
			if key in line:
				print(file)
				print(line_cnt, ":")
				print(line)
			line_cnt += 1

sublime build system(编译系统)

以启动新控制台的方式,解决sublime自带控制台不能输入的问题

python

{
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.py",
    "variants":
    [
        {
            "name": "Run",
            "cmd": ["cmd", "/c","pyflakes","${file}","&&","start","cmd","/c","python ${file} & pause"]
        }
    ]
}


C++

{
    "cmd": ["g++", "${file}", "-fexec-charset=gbk", "-o", "${file_path}/${file_base_name}"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",
    "variants":
    [
        {
            "name": "Run",
            "cmd": ["cmd", "/c", "g++", "${file}", "-std=c++11", "-o", "${file_path}/${file_base_name}", "&&", "start", "cmd", "/c", "${file_path}/${file_base_name} & pause"]
        }
    ]
}

支持Winsock2:

{
    "cmd": ["g++", "${file}", "-fexec-charset=gbk", "-o", "${file_path}/${file_base_name}"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",
    "variants":
    [
        {
            "name": "Run",
            "cmd": ["cmd", "/c", "g++", "${file}", "-std=c++11",  "-lwsock32", "-o", "${file_path}/${file_base_name}", "&&", "start", "cmd", "/c", "${file_path}/${file_base_name} & pause"]
        }
    ]
}

Java

{
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.java",
    "encoding": "cp936",
    "cmd": ["cmd", "/c","javac","${file}","&&","start","cmd","/c","java ${file_base_name} & pause"]
}

C#

{
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.cs",
    "encoding": "cp936",
    "cmd": ["cmd", "/c","csc","${file}","&&","start","cmd","/c","${file_path}/${file_base_name} & pause"]
}

lua

{
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.lua",
    "encoding": "cp936",
    "variants":
    [
        {
            "name": "Run",
            "cmd": ["cmd", "/c","start","cmd","/c","lua ${file} & pause"]
        }
    ]
}

自动匹配语言

我这里包括了C、C++、Python、Java、Lua,其他的自己看着加
前提是配好了python,因为python好实现我就懒得用别的了
实现方式就是简单的指令字符串的替换

compie.py

import sys
import os
import time

if 1 in range(len(sys.argv)):
	file_path = sys.argv[1]
	file_type = file_path.split('.')[-1]
	file_name = file_path.split('\\')[-1].split('.')[0]

	# print('file_path = ', file_path)
	# print('file_type = ', file_type)
	# print('file_name', file_name)

	type_cmd = eval(open(sys.argv[0].replace('compie.py', 'config.txt')).read())
	cmd = str(type_cmd[file_type])
	
	# print(type_cmd)
	# print(type(cmd))
	# print(cmd)


	cmd = cmd.replace('[path]', file_path)
	cmd = cmd.replace('[fileName]', file_name)
	cmd = cmd.replace('[fileType]', file_type)
	start_time = time.time()
	print('cmd =', cmd)
	print('--------------------------------------------------------program start')
	os.system(cmd)
	print('\n--------------------------------------------------------program end')
	print('finished in %.3fs' % (time.time() - start_time))

config.txt
就是个python的字典

{
'c' : 'gcc "[path]" -o "[fileName].exe" && [fileName].exe',
'cpp' : 'g++ "[path]" -o "[fileName].exe" -std=c++11 && [fileName].exe',
'py' : 'python "[path]"',
'java' : 'javac [path] && java [fileName]',
'lua' : 'lua [path]'
}

.sublime-build里这么写:
(注意,“python D:/compie/compie.py”是我自己的绝对路径,记得改)

{
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "encoding": "cp936",
    "cmd": ["cmd", "/c","start","cmd","/c","python D:/compie/compie.py ${file} & pause"]
}

unity

控制移动:BV15W411976h p4
移动

序列化BV15W411976h p7
序列化
携程?BV15W411976h p7
携程?

汇编

打开dosbox
输入指令

mount c [masm_path]
c:

编辑hello.asm文件(完整汇编程序框架):

codes segment
	assume cs:codes
start:
	mov dl,'h'
	mov ah,2
	int 21h ; print the char in dl

	mov ah,4ch
	int 21h ; exit
codes ends
	end start

产生obj文件:

masm [file_base_name]

链接

link [file_base_name]

lua

栈:
链表实现
!!!front和tail的含义反了,稍后有时间了再改!!!

-- Stack definition begin
--[[
top -> [value] -> [value] -> [value] -> [value] -> [value] -> None
]]
Stack = {}
function Stack.new()
	return {size = 0, top = None} -- per node: {value = '', next = None}
end

function Stack.size(self)
	return self.size
end

function Stack.top(self)
	if self.top then
		return self.top.value
	else
		error("Stack empty!")
	end
end

function Stack.push(self, v)
	local t = self.top
	self.top = {value = v, next = t}
	self.size = self.size+1
end

function Stack.pop(self)
	local t = self.top
	if t then
		self.top = t.next
		self.size = self.size-1
		return t.value
	else
		error("Stack empty!")
	end
end
-- Stack definition end


-- Stack example begin
s = Stack.new()
for i=1, 10 do
	Stack.push(s, i)
end
while Stack.size(s) > 0 do
	print(Stack.pop(s))
	-- print(Stack.top(s))
end
-- Stack.pop(s) -- Stack empty!
-- Stack example end

队列:
链表实现

-- Queue definition begin
--[[
None <- [value] <- [value] <- [value] <- [value]
        ^                                ^
        |                                |
       tail                            front
]]
Queue = {}
function Queue.new()
	return {size = 0, front = None, tail = None}
end

function Queue.size(self)
	return self.size
end

function Queue.front(self)
	return self.front.value
end

function Queue.push(self, v)
	if self.size==0 then
		self.front = {value=v, next = None}
		self.tail = self.front
	else
		self.tail.next = {value=v, next = None}
		self.tail = self.tail.next 
	end
	self.size = self.size + 1
end

function Queue.pop(self)
	if self.size > 0 then
		local t = self.front.value
		self.front = self.front.next
		self.size = self.size - 1
		return t
	else 
		error("Queue empty!")
	end
end
-- Queue definition end

-- Queue example begin
q = Queue.new()
for i=1, 10 do
	Queue.push(q, i)
end

while Queue.size(q) > 0 do
	-- print(Queue.front(q))
	print(Queue.pop(q))
end
-- Queue example end

-- bfs example begin -base on this Queue 
local n = 100
local base = n+1
local _xy = {0,1,0,-1,0}
local vis = {}
local q = Queue.new()
local start_x = 1
local start_y = 1
Queue.push(q, start_x*base+start_y)
vis[start_x*base+start_y] = true
local cnt = 0
while true do
	local size = Queue.size(q)
	-- print("size = ", size)
	if size==0 then
		break
	end
	for t=1, size do
		local v = Queue.pop(q)
		vis[v] = true
		local curr_x = math.floor(v/base)
		local curr_y = v % base
		print(curr_x .. "," .. curr_y)
		cnt = cnt + 1
		for i=1,4 do
			local next_x = curr_x + _xy[i]
			local next_y = curr_y + _xy[i+1]
			-- print(next_x, next_y)
			if (next_x<=n and next_x >=1 and
				next_y<=n and next_y >=1 and
				vis[next_x*base+next_y] == nil) then

				vis[next_x*base+next_y] = true
				Queue.push(q, next_x*base+next_y)
				-- print("push", next_x*base+next_y)
			end
		end
	end
	print()
end
print(cnt)
-- bfs example end

之前网上找到一个版本(略做修改):

--<Queue definition begin>
Queue = {}

function Queue.new()
	return {first = 0, last = -1}
end

function Queue.pushFront(list, value)
	local first = list.first - 1
	list.first = first
	list[first] = value
end

function Queue.pushBack(list, value)
	local last = list.last + 1
	list.last = last
	list[last] = value
end

function Queue.popFront(list)
	local first = list.first
	if first > list.last then
		error("Queue is empty")
	end
	local value = list[first]
	list[first] = nil
	list.first = first + 1
	return value
end

function Queue.popBack(list)
	local last = list.last
	if list.first > last then
		error("Queue is empty")
	end
	local value = list[last]
	list[last] = nil
	list.last = last - 1
	return value
end

function Queue.isEmpty(list)
	local ret = list.first > list.last
	return ret
end
--<Queue definition end>


-- example begin
local q = Queue.new()

for i=1,10 do
	Queue.pushBack(q,i)
end

while not Queue.isEmpty(q) do
	print(Queue.popFront(q))
end

-- example end

Linux 服务器

1.下载tomcat
2.安装tomcat
3.打开8080端口
4.重启防火墙

wget https://mirrors.bfsu.edu.cn/apache/tomcat/tomcat-9/v9.0.44/bin/apache-tomcat-9.0.44.tar.gz

tar -zxvf apache-tomcat-9.0.44.tar.gz

firewall-cmd --zone=public --add-port=8080/tcp --permanent

systemctl restart firewalld.service

其他相关指令:

更新一下:在设置好端口后,需要执行

firewall-cmd --reload

5、查看已经打开的端口

firewall-cmd --list-all

alias永久有效

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值