JAVA-and-J2EE
最长公共子串问题的java版计算
星期三, 五月 17th, 2023 | algorithm-learn, JAVA-and-J2EE, linux | 没有评论
1.最长公共子串问题
【题目】给定两个字符串str1和str2,返回两个字符串的最长公共子串。
【举例】str1="1AB2345CD",str2="12345EF",返回"2345"。
【要求】如果 str1 长度为 M,str2 长度为N,实现时间复杂度为 O(M×N),额外空间复杂度为 O(1)的方法。
【难度】3星
/** * * 1.最长公共子串问题 【题目】给定两个字符串str1和str2,返回两个字符串的最长公共子串。 * 【举例】str1="1AB2345CD",str2="12345EF",返回"2345"。 【要求】如果 str1 长度为 M,str2 长度为 * N,实现时间复杂度为 O(M×N),额外空间复杂度为 O(1)的方法。 【难度】3星 * * @author sara * */ public class MaxSubStr { public static void main(String[] args) { String str1="1AB2345CD",str2="12345EF"; String str = getMaxSub(str1,str2); System.out.println(str); } public static String getMaxSub(String s1, String s2) { String sStr = s1, mStr = s2; if (s1.length() > s2.length()) { sStr = s2; mStr = s1; } String str = ""; for (int i = 0; i < sStr.length(); i++) { for (int j = 1; j < sStr.length() - i; j++) { if (mStr.contains(sStr.substring(i, i + j)) && j > str.length()) { str = sStr.substring(i, i + j); } } } return str; } public static void getDp(char[] str1, char[] str2) { } } |
linux、centos等配置不输入密码切换sudo指令
星期二, 五月 16th, 2023 | JAVA-and-J2EE, linux | 没有评论
使用 pkexec 安全配置指定用户不输入密码切换sudo su指令
1.pkexec su可进入你的root
pkexec visudo 进入visudo命令
直接编辑修改
ctrl + x 保存退出
编辑的也是此文件,在对应的用户前面加上NOPASSWD即可
在/etc/sudoers文件
sa ALL=(ALL) NOPASSWD:ALL
2.小问题修复 为了能编辑/etc/sudoers 执行给了777权限
出现如下错误
sudo: /etc/sudoers is world writable
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
修复此错误:
pkexec chmod 0440 /etc/sudoers |
基于phantomjs的截图优化JS信息
星期三, 四月 5th, 2023 | computer, JAVA-and-J2EE, linux | 没有评论
phantomjs是比较老的一种模拟抓取及截图,这个是以前处理截图的一种优化js信息做个留档
以后应该是不用了
img.js和rasterize.js两个文件
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 | var page = require('webpage').create(), system = require('system'), address, output, size; if (system.args.length < 3 || system.args.length > 5) { phantom.exit(1); } else { address = system.args[1]; output = system.args[2]; //定义宽高 /* page.viewportSize = { width : 1024, height : 768 };*/ page.open(address, function(status) { var bb = page.evaluate(function() { return document.getElementsByTagName('html')[0].getBoundingClientRect(); }); page.clipRect = { top : bb.top, left : bb.left, width : bb.width, height : bb.height }; window.setTimeout(function() { page.render(output); page.close(); console.log('渲染成功...'); console.log(address); phantom.exit(); }, 1000); }); } |
SpringBoot应用的jar包重新打包
星期三, 三月 15th, 2023 | JAVA-and-J2EE | 没有评论
1.对应历史的运行中的jar包,需要更改下对应配置 或者其中的一个class文件可以直接使用命令重新打包
2.如下即可
unzip ../my-boot-app.jar vim BOOT-INF/classes/application-pro.properties jar uf ../my-boot-app.jar BOOT-INF/classes/application-pro.properties |
3.这样只更新对应的文件即可
美化Eclipse链式调用的代码格式化(Formatter)
星期二, 十月 18th, 2022 | JAVA-and-J2EE | 没有评论
eclipse下的链式调用格式化的时候挤成一行,看起来很难受.
需要调整 Eclipse 默认的代码格式化——在按下「Ctrl + Shift + F」后,编辑器能够自动将链式调用代码换行。怎么办呢?
在 Eclipse 中按照以下顺序打开代码格式化的配置项:
Windows → Preferences → Java → Code Style → Formatter
选择「New…」新建一个格式化的配置。
关键的配置项如下:
1、Maximum line width:120「一行最大宽度,120」(超过 120 就自动换行)
2、Function Calls → Qualified Invocations「方法调用 → xxxxx」
其中 line wrapping policy 「换行策略」选择:
wrap all elements, except first element if not necessary「第一个元素可以不换行,其他都换行」
并且勾选复选框 force split, even if line shorter than maximum line width「强制换行,即使该行没有达到最大换行的宽度」
这样设置后,Eclipse 就能够为链式调用的代码自动换行了。效果如下图。
不过,这样的换行效果仍然不够理想,如果换行策略优化为:
wrap all elements, except second element if not necessary「前两个元素可以不换行,其他都换行」
这样就更好了。
datart更新到jdk17及springboot2.7.4版本执行调整
星期日, 十月 16th, 2022 | JAVA-and-J2EE, linux | 没有评论
datart简介:
新一代数据可视化开放平台,支持报表、仪表板、大屏、分析和可视化数据应用的敏捷构建
对应文档地址:https://running-elephant.gitee.io/datart-docs/docs/
GIT地址:https://gitee.com/running-elephant/datart/releases
https://github.com/running-elephant/datart/releases
当前使用版本 datart-1.0.0-rc.1,即此刻master版本
尝试使用jdk17进行编译,使用SpringBoot2.7.4进行parent迁移,修改如下可以比较完美的升级过来.
1.更换 swagger版本,移除springfox相关maven
<dependency> <groupid>io.springfox</groupid> <artifactid>springfox-boot-starter</artifactid> <version>3.0.0</version> </dependency> |
2.引入nashorn的maven,在jdk17中已经移除
<dependency>> <groupid>org.openjdk.nashorn</groupid> <artifactid>nashorn-core</artifactid> <version>15.4</version> </dependency> |
3.BaseService 启动延迟加载accessLogService服务类
@Autowired public void setAccessLogService(@Lazy AsyncAccessLogService accessLogService) { this.accessLogService = accessLogService; } |
4.更改引用包
import org.openjdk.nashorn.internal.parser.TokenType; import org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory; import org.apache.calcite.sql.parser.impl.SqlParserImpl; |
5.更换路由匹配模式
spring.mvc.pathmatch.matching-strategy=ant_path_matcher |
Nginx解决http host头攻击及Method漏洞
星期一, 十月 10th, 2022 | computer, JAVA-and-J2EE, linux | 没有评论
一、HTTP Host头攻击漏洞解决
检测应用是否在请求目标站点时返回的URL是直接将Host头拼接在URI前。
解决方法:验证host
server { listen 80; server_name 127.0.0.1 192。168.1.8 xxx.com; if ($http_Host !~* ^192.168.1.8|127.0.0.1|xx.com$) { return 403; } } |
二、 HTTP Method非POST和GET方式击漏洞解决
尽量用get和post的api的应用,禁用OPTIONS
解决方案:在nginx的server中配置,只允许GET、POST、PUT、DELETE 类型请求通过,其余不安全的请求方式返回403状态码,代码如下。
if ($request_method !~* GET|POST|PUT|DELETE) { return 403; } |
解决yum安装docker慢,更换阿里源
星期五, 九月 16th, 2022 | JAVA-and-J2EE, linux | 没有评论
1、yum install -y yum-utils 2、yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 3、yum install docker-ce |
设置系统及myslq时区信息,避免程序时间不配置
星期五, 七月 29th, 2022 | JAVA-and-J2EE, linux | 没有评论
起因程序用了 date 做查询判断,因系统及mysql不一致,导致插入到数据库的时间和系统时间有差距
造成查询失误,重复插入的问题,故需要调成一致即可.
timedatectl set-timezone "America/New_York" ##在[mysqld]区域中加上 vim /etc/my.cnf default-time_zone = '-4:00' ###或者## default-time_zone = 'America/New_York' #/etc/init.d/mysqld restart ##重启mysql使新时区生效 |
Java 开发常用的 Linux命令比较全
星期三, 四月 27th, 2022 | JAVA-and-J2EE, linux | 没有评论
Linux关机,重启
# 关机 shutdown -h now #或者 init 0 # 重启 shutdown -r now #或者 更常用 reboot |
查看系统,CPU信息
# 查看系统内核信息 uname -a # 查看系统内核版本 cat /proc/version # 查看当前用户环境变量 env cat /proc/cpuinfo # 查看有几个逻辑cpu, 包括cpu型号 cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c # 查看有几颗cpu,每颗分别是几核 cat /proc/cpuinfo | grep physical | uniq -c # 查看当前CPU运行在32bit还是64bit模式下, 如果是运行在32bit下也不代表CPU不支持64bit getconf LONG_BIT # 结果大于0, 说明支持64bit计算. lm指long mode, 支持lm则是64bit cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l |
建立软连接
ln -s /usr/local/jdk1.8/ jdk |
rpm相关
# 查看是否通过rpm安装了该软件 rpm -qa | grep 软件名 |
Search
相关文章
热门文章
最新文章
文章分类
- ajax (10)
- algorithm-learn (3)
- Android (6)
- as (3)
- computer (83)
- Database (30)
- disucz (4)
- enterprise (1)
- erlang (2)
- flash (5)
- golang (3)
- html5 (18)
- ios (4)
- JAVA-and-J2EE (184)
- linux (142)
- mac (10)
- movie-music (11)
- pagemaker (36)
- php (50)
- spring-boot (2)
- Synology群晖 (2)
- Uncategorized (6)
- unity (1)
- webgame (15)
- wordpress (33)
- work-other (2)
- 体味生活 (40)
- 前端 (21)
- 大数据 (8)
- 游戏开发 (9)
- 爱上海 (19)
- 读书 (4)
- 软件 (3)