Skip to content

Instantly share code, notes, and snippets.

View vector4wang's full-sized avatar
🕶️
For Freedom!

wangxc vector4wang

🕶️
For Freedom!
View GitHub Profile
@vector4wang
vector4wang / Coin.sol
Created December 25, 2018 10:01
智能合约发币测试
pragma solidity ^0.4.0;
contract Coin{
// 声明 一个 address 类型 变量 256 bits, 用于 存储启动该智能合约的账户地址。
address public minter;
// 声明 mapping 类型 变量 类似于 java map ,用于存储账户的资产信息
mapping(address => uint) public balances;
// 声明 一个事件 ,客户端可以来监听该事件
@vector4wang
vector4wang / Probability.java
Created May 28, 2019 02:48
[概率命中否] 传递一个概率值,计算一次此次是否中奖 #Java #概率命中
/**
* 传入一个概率值,基于此概率计算一次是否有“中奖”
*
* @param proVal 概率值,如概率为0.01,则proVal为1,概率为0.2,则proVal为20
* @return
*/
public static boolean isLuckyVal(int proVal) {
int val = new Random().nextInt(100)+1;
if (proVal <= val) {
return true;
@vector4wang
vector4wang / oneKey.sh
Last active May 28, 2019 06:18
[jenkins打包java项目脚本] jenkins打包的配置脚本,通过端口号找到服务并停止 #Java #SSH
cd /app/resume-engine-rc/
curServicePid=`netstat -anp|grep 8989|awk '{printf $7}'|cut -d/ -f1`
if [ -n "$curServicePid" ];then
kill -9 $curServicePid
fi
rm -rf *
cp /app/jenkins-temp/* /app/resume-engine-rc/
unzip *.zip
cd resume-update-engine/
pwd
@vector4wang
vector4wang / 需求.java
Last active May 28, 2019 11:36
[code timer statistics] #Java
Timer t1 = new Timer();
t1.start(); // 针对每一个方法需要 new一个,并且需要制定start()和stop()
fun1();
t1.sotp;
Timer t2 = new Timer();
t2.start()
fun2();
t2.stop();
@vector4wang
vector4wang / pom.xml
Created May 29, 2019 11:19
[pom use jdk1.8] pom中使用java8编译 #Java #Pom
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@vector4wang
vector4wang / map.java
Created May 29, 2019 11:29
[Awesome lambda ] #Java #Lambda
ConcurrentHashMap<String, Long> taskCallCountMap = new ConcurrentHashMap<>(8);
taskCallCountMap.merge(this.currentTaskName, 1L, (a, b) -> a + b); // awosome jdk 1.8
// 原子性操作,酷毙了
@vector4wang
vector4wang / bytecodeInterpreter.cpp
Created June 11, 2019 05:54
HotSpot解释器的代码片段 #HotSpot
//确保常量池中存放的是已解释的类
if(!constants->tag_at(index).is_unresolved_klass()){
//断言确保是klassOop和instanceKlassOop(这部分下一节介绍)
oop entry=(klassOop)*constants->obj_at_addr(index);
assert(entry->is_klass(),"Should be resolved klass");
klassOop k_entry=(klassOop)entry;
assert(k_entry->klass_part()->oop_is_instance(),"Should be instanceKlass");
instanceKlass * ik=(instanceKlass*)k_entry->klass_part();
//确保对象所属类型已经经过初始化阶段
if(ik->is_initialized()&&ik->can_be_fastpath_allocated())
@vector4wang
vector4wang / pom.xml
Last active June 17, 2019 14:23
[pom中指定仓库地址] 优先级高 #Java #Spring #Maven #Pom
<repositories>
<repository>
<id>baza</id> 唯一
<name>Baza Repository</name>
<url>http://192.168.1.191:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
@vector4wang
vector4wang / pom.xml
Last active June 18, 2019 01:08
[多模块项目不引入springboot paremt] 解决maven项目的父项目中引入springboot的parent而出现的问题 #Java #Springboot #Maven
<!-- https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-maven-without-a-parent -->
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
@vector4wang
vector4wang / loadresource.java
Last active June 18, 2019 07:19
[springboot读取资源文件] 万金油? #Java #Springboot
// 方法1:获取文件或流
this.getClass().getResource("/")+fileName;
this.getClass().getResourceAsStream(failName);
// 方法2:获取文件
File file = org.springframework.util.ResourceUtils.getFile("classpath:test.txt");
// 方法3:获取文件或流
ClassPathResource classPathResource = new ClassPathResource("test.txt");
classPathResource .getFile();
classPathResource .getInputStream();