Some words from people who has been ahead of me

表面上的努力都是无谓的,最重要的是灵魂的提升。
SICP,CSAPP,CLRS,OSTEP,EoPL,PRML*书读好了没
语法都不是最难的,最难的是算法。
能想出算法的都是神

从今以后,我只爱学习和运动

同学的10km,我以前没做到过吗?我喜欢的跑步,从来应该紧随我。做一个好自己。

php 问题总结

脚本语言的通病

  • 弱类型语言
$a = 1;
$b = array();
$c = "test";

<?php
  $a = null; $b = false;  
  if($a == $b){  
      echo “a和b相等!”;  
  }else{  
      echo “a和b不相等!”;  
  }  
  $a = ''; $b = 0; 
  if($a == $b){  
      echo “a和b相等!”;  
  }else{  
      echo “a和b不相等!”;  
  }  
?>
  • require( )包含文件 可以文件注入
<form>Choose theme:
    <select name = theme>
        <option value = blue>Blue</option>
        <option value = green>Green</option>
        <option value = red>Red</option>
    </select>
    <input type = submit>
</form>
<?php
    if($theme) {
        require($theme.'.txt');
    }
?>
  • sql 注入 拼装字符串,addslashes/stripslashes防御
$sql =”select * from phpben where user_name=’admin’ and pwd =’123′”;  
$sql =”select * from phpben where user_name=’ ‘or’=’or” and pwd =” “;  
$sql =”select * from phpben where user_name=’ ‘or 1=’1′ and pwd =” “;
  • Xss攻击
<body>
<?php
$searchQuery = $_GET['q'];
/* some search magic here */
?>
<h1>You searched for: <?php echo $searchQuery; ?></h1>
<p>We found: Absolutely nothing because this is a demo</p>
</body>

直接打 search.php?q=%3Cscript%3Ealert(1)%3B%3C%2Fscript%3E

Reference

  1. https://www.kancloud.cn/chunyu/php_basic_knowledge/840701
  2. https://www.cnblogs.com/Renyi-Fan/p/10856650.html#_label0_1
  3. https://www.runoob.com/w3cnote/php-safe-collection.html
  4. https://www.oschina.net/translate/top-6-security-attacks-php?print

P5003 跳舞的线 - 乱拐弯

这道DP有点精妙~,大概最优子结构的转移函数写法长这样:

$$f_{max,i,j,0}=max(f_{max,i,j-1,0},f_{max,i,j-1,1}+1)$$

$$f_{max,i,j,1}=max(f_{max,i-1,j,0}+1,f_{max,i-1,j,1})$$

$$f_{min,i,j,0}=max(f_{min,i,j-1,0},f_{min,i,j-1,1}+1)$$

$$f_{min,i,j,1}=max(f_{min,i-1,j,0}+1,f_{min,i-1,j,1})$$

为了防止在起始点拐弯,最好的办法是-1越界。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define re register int 
#define LL long long 
using namespace std;
int n,m;
int f[1010][1010][2],g[1010][1010][2];
char a[1010][1010];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	cin>>a[i][j];
	memset(f,63,sizeof(f));
	if(a[1][1]=='#'){cout<<-1;return 0;}
	g[1][1][0]=g[1][1][1]=0;
	f[1][1][0]=f[1][1][1]=0;//0 left 1 down
	for(int i=1;i<=m;i++)g[0][i][1]=g[0][i][0]=-2147483647;
	for(int i=1;i<=n;i++)g[i][0][1]=g[i][0][0]=-2147483647;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	if(a[i][j]=='o')
	{
		if(i==1&&j==1)continue;
		g[i][j][1]=max(g[i-1][j][1],g[i][j-1][0]+1);
		f[i][j][1]=min(f[i-1][j][1],f[i][j-1][0]+1);
		g[i][j][0]=max(g[i-1][j][1]+1,g[i][j-1][0]);
		f[i][j][0]=min(f[i-1][j][1]+1,f[i][j-1][0]);
	}
	int Ansa=max(g[n][m][1],g[n][m][0]);
	int Ansb=min(f[n][m][1],f[n][m][0]);
	if(Ansb>n+m-2)cout<<-1<<endl;
	else cout<<Ansa-1<<" "<<Ansb<<endl;
	return 0;
}

linux编译出现 (.text+0x20):对‘main’未定义的引用 collect2: 错误:ld 返回 1 | (.text+0x20): undefined reference to `main' and undefined reference to function 解决方法

操作系统:ubuntu18.04 hpbook2000 gcc版本7.3.0

首先借鉴了国内网站,但大多说的是Makefile 很奇怪,我以为是源码编译的时候的问题但大家都是用”apt install gcc && apt install g++“来安装的,按说是不会出现这种错误的。我那时比较幼稚,就傻吼吼的等了一天源码编译gcc。

搞定了也没用,照样提示以上错误。那怎么办,听网上说只要把main 改成_start 或者不是main的函数名就ok了。又有人说最最主要的原因是Scrt1.o的main函数名定义在了使用它的前面所以报错。好吧,我就算知道也没法改.o文件怎么办。

网上又说有个可以痛改前非的办法,在gcc&g++加个-nostdlib或-nostartfile参数就可以。编译完说内核缺失,错的更离谱了。还有segmentation fault 搞笑。


最终解决办法

cd /usr/lib/ && cp crt1.o Scrt1.o

没有的话就编译一遍gcc就有了。g++和gcc是连带关系所以一并解决。

前天搞定的群辉usb3.0网线驱动

这个安装并不难,这只是保留下安装的链接而已

接下来比较硬核了,需要先给ubuntu18.04装个内核什么的,内核编译网上的3.10.105(这是DSM6.2的linux内核)一开始会提示架构不兼容。那就强制

sudo dpkg -i ***.deb

解压之后会发现/lib/modules会多一个linux-headers-'uname -r' 的文件夹,里面有build文件夹,那就搞定了。其实在/usr/src也会有一个,两个有链接和依赖关系,不管了。为了编译内核光有header是没有用的,去网上下一个linux3.x整合包管理就好,那还是不够,得要有synology 好吧其实关键词是xeonology(黑群辉)toolchain,这才是真正的开源内核,复制到/usr/src后就make整合包,make有个错误,搜错误信息csdn上有大神改源码就编译成功了。(所以压根就不是电脑不行,就是能力太差)不过这是一个兼容的常见问题,传参没传对,得自定义变量传参。

Makefile也是空白,Dockerfile更是,但其实差不多。

好了,搞定之后在asix或者a88178a-179a内编译

make --force --with-kernel=xxx

或者直接改makefile里面的KDIR就好。编译完之后就差拷贝到群辉目录下了

详见http://www.u-share.cn/forum.php?mod=viewthread&tid=9882

 

然而,若你不想这么烦,就直接拷贝吧https://xpenology.com/forum/topic/9508-driver-extension-jun-102bdsm61x-for-3615xs-3617xs-916/

连跳转都帮你写好了,重启都不怕,注意版本号哦!

另参考http://www.gebi1.com/thread-251273-1-1.html

学习到了些新技能,更新下要学的新技能,看来中文的代码圈真的是好齐全。

https://hexo.io/ && https://github.com/iissnan/hexo-theme-next

https://blog.csdn.net/zhangdi2017/article/details/65629589

https://summul.cn/427.html

http://wosn.net/263.html

http://www.inlojv.com/5435.html

期待我的网站新界面吧

更新小张高手帮忙debug的程序!

import re
import sys

s = ''
for line in sys.stdin:
    s += line
    if '}' in line:
        break
    t = re.sub(r'(\s*)\w*:(\s*)', r'\n',
               re.sub(r"\s*bool\s*|\s*main\s*\(\s*\)\s|{", r'', re.sub(r'(\W)(\d+\w*)', r'\1a_\2', s)).strip().replace(
                   '=', ' = '))
    x, y, c = 0, 0, 0
    while t.find('done', x + 1) != -1:
        x0 = x
        x = t.find('done', x)
        y = t.find('while', x0)
        c = len(t)
    q = t[y:x].replace(';', ';;').split()
    if "=" in q:
        q[q.index("=") - 2] += ':'
    else:
        q[q.index("pass") - 1] += ':'
        q[q.index('while')] += ' '
    t = t[:y - 1] + '\n' + "".join(q) + t[x + 4:]
    x = x + len(t) - c + 4
    x, y, c = 0, 0, 0
    while t.find('fi', x + 1) != -1:
        x0 = x
        x = t.find('fi', x)
        y = t.find('if', x0)
        c = len(t)
    q = t[y:x].replace(';', ';;').split()
    if "=" in q:
        q[q.index("=") - 2] += ':'
    else:
        q[q.index("pass") - 1] += ':'
        q[q.index('if')] += ' '
    t = t[:y - 1] + '\n' + "".join(q) + t[x + 2:]
    x = x + len(t) - c + 2
    exec(re.sub(r'\s*:', r":", ('def evaluate():\n\tcount=0\n\t' + re.sub(r';+', r'\n',
                                                                          t.replace('done', '').replace("fi",
                                                                                                        '').replace(
                                                                              'pass', '').replace(';;', "\n\t").replace(
                                                                              ':',
                                                                              ':\n\tcount+=1\n\tif (count)>200:\n\t\treturn "infinite"\n\t')).replace(
        '!', ' not ').replace('&', ' and ').replace('|', ' or ').replace('\n', '\n\t').replace('}', '').replace(
        '\n\t\n',
        '\n'))))
print(evaluate())