以太坊入门(三)用web3j进行以太转账及代币转账

上章讲到账户的查询,本章讲述账户转账。

  1. 以太坊转账 We3j web3j = Web3j.build(new HttpService(ConstantLibs.WEB3_ADDRESS)); Credentials credentials = WalletTool.loadCredentials(fromAddress); EthGetTransactionCount ethGetTransactionCount = web3j.ethGetTransactionCount( fromAddress, DefaultBlockParameterName.LATEST).sendAsync().get(); BigInteger nonce = ethGetTransactionCount.getTransactionCount(); RawTransaction rawTransaction = RawTransaction.createEtherTransaction( nonce, Convert.toWei("18", Convert.Unit.GWEI).toBigInteger(), Convert.toWei("45000", Convert.Unit.WEI).toBigInteger(), toAddress, new BigInteger(amount)); byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials); String hexValue = Numeric.toHexString(signedMessage); EthSendTransaction ethSendTransaction = web3.ethSendRawTransaction(hexValue).sendAsync().get(); if (ethSendTransaction.hasError()) { log.info("transfer error:", ethSendTransaction.getError().getMessage()); } else { String transactionHash = ethSendTransaction.getTransactionHash(); log.info("Transfer transactionHash:" + transactionHash); }
  2. 以太坊代币转账 Web3j web3j = Web3j.build(new HttpService(ConstantLibs.WEB3_ADDRESS)); Credentials credentials = WalletTool.loadCredentials(fromAddress); EthGetTransactionCount ethGetTransactionCount = web3j.ethGetTransactionCount( fromAddress, DefaultBlockParameterName.LATEST).sendAsync().get(); BigInteger nonce = ethGetTransactionCount.getTransactionCount(); Function function = new Function( "transfer", Arrays.asList(new Address(toAddress), new Uint256(new BigInteger(amount))), Arrays.asList(new TypeReference<Type>() { })); String encodedFunction = FunctionEncoder.encode(function); RawTransaction rawTransaction = RawTransaction.createTransaction(nonce, Convert.toWei("18", Convert.Unit.GWEI).toBigInteger(), Convert.toWei("100000", Convert.Unit.WEI).toBigInteger(), contractAddress, encodedFunction); byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials); String hexValue = Numeric.toHexString(signedMessage); log.debug("transfer hexValue:" + hexValue); EthSendTransaction ethSendTransaction = web3.ethSendRawTransaction(hexValue).sendAsync().get(); if (ethSendTransaction.hasError()) { log.info("transfer error:", ethSendTransaction.getError().getMessage()); } else { String transactionHash = ethSendTransaction.getTransactionHash(); log.info("Transfer transactionHash:" + transactionHash); }

代币转账和以太转账的区别在于,to地址是合约地址,而input是有三部分数据构成:transfer方法的哈希+收款人的地址+转账金额。此处比较难理解的正是Function部分,设置好参数以后,调用rawTransaction就可以了。

本站始发,转载于 https://www.jianshu.com/p/8ae984e6bafc

以太坊入门(二)用web3j进行以太查询及通证查询

以太坊的开发,基本都是go语言和nodejs的天下,web3j出现给java开发人员提供了很大的便利。本文会对一些以太坊的基本操作用java语言来实现。

本章会讲述通过web3j进行账户余额的查询。

  1. 以太余额查询
    以太的余额查询比较简单,直接调用web3j的ethGetBalance就可以。 Web3j web3j = Web3j.build(new HttpService(ConstantLibs.WEB3_ADDRESS)); EthGetBalance ethGetBalance = web3j.ethGetBalance( address, DefaultBlockParameterName.LATEST).sendAsync().get(); BigInteger balance = ethGetBalance.getBalance();
  2. 通证的余额查询
    代币的查询就比较复杂一些,研究了好长时间,最后发现每个代币合约都会实现balanceOf方法,可以通过这个方法来查询通证的余额。 Web3j web3j = Web3j.build(new HttpService(ConstantLibs.WEB3_ADDRESS)); Function function = new Function( "balanceOf", Arrays.asList(new Address(address)), // Solidity Types in smart contract functions Arrays.asList(new TypeReference<Type>() { })); String encodedFunction = FunctionEncoder.encode(function); org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall( org.web3j.protocol.core.methods.request.Transaction.createEthCallTransaction(address, contract, encodedFunction), DefaultBlockParameterName.LATEST) .sendAsync().get(); String returnValue = response.getValue(); //返回16进制余额 returnValue = returnValue.substring(2); BigInteger balance = new BigInteger(returnValue, 16);

本站始发,转载于https://www.jianshu.com/p/0f3e65622d65

以太坊入门(一)账户和nonce的关系

什么是nonce?

在以太坊的交易数据中,大家都可以看到一个数字,nonce,从0开始,一直向上递增,这个代表什么意思呢?

以太坊所有的交易都是基于account的,不同于基于utxo的比特币,因此需要对每次交易都按顺序记录,nonce值就是这个顺序,主要用来防止重放攻击。

发起一笔交易,nonce就会加一。对于发起的解释:

1.外部账户每发送一笔交易;

2.合约账户每创建一个合约

而转入交易、合约调用其他合约等属于内部调用,因此nonce值不变。

如何使用nonce

发起转账或者创建合约的时候,通过web3从以太坊网络查询当前的nonce(ethGetTransactionCount)值,使用此值作为当前交易的nonce值,发送到以太坊网络即可。

nonce使用的几条规则

1. 当nonce太小(小于当前的nonce值),交易会被直接拒绝,Transactions with too low a nonce get immediately rejected;

2. 当nonce太大,大于当前nonce,交易会一直处于队列之中,Transactions with too high a nonce get placed in the transaction pool queue;

3.当发送一个比较大的nonce值,然后补齐开始nonce到那个值之间的nonce,那么交易依旧可以被执行,If transactions with nonces that fill the gap between the last valid nonce and the too high nonce are sent and the nonce sequence is complete, all the transactions in the sequence will get processed and mined.

4. 交易队列只保存最多64个从同一个账户发出的交易,The transaction pool queue will only hold a maximum of 64 transactions with the same From:address with nonces out of sequence. 也就是说,如果要批量转账,同一节点不要发出超过64笔交易。

5.当某节点queue中还有交易,但此时停止geth客户端,queue中的交易会被清除掉,When the geth instances are shut down and restarted, transactions in the transaction pool queue disappear.

6.当前nonce合适,但是账户余额不足时,会被以太坊拒绝;

7.如果发起一笔交易,但是因为gwei比较低或者网络比较忙的时候,该交易还没矿工挖出,可以通过使用相同的nonce和较高的gas费用,从而“覆盖”前一笔交易;

树莓派充当airplay接收器

iOS升级以后,新版本经常不兼容xbian之类自带的airplay功能,目前来Shairport的支持还是不错的。我在新的树梅派3b+上编译了一下,支持ios 11.0.4版本。

首先升级树莓派

sudo apt-get update
sudo apt-get upgrade

然后安装依赖包

sudo apt-get install autoconf automake avahi-daemon build-essential git libasound2-dev libavahi-client-dev libconfig-dev libdaemon-dev libpopt-dev libssl-dev libtool xmltoman

下载shairport源码

git clone https://github.com/mikebrady/shairport-sync.git

生成配置文件

cd shairport-sync
autoreconf -i -f
./configure --with-alsa --with-avahi --with-ssl=openssl --with-systemd --with-metadata

编译安装

make
sudo make install

设置为自动启动

sudo systemctl enable shairport-sync

启动

sudo service shairport-sync start

然后就可以在手机里面找到airplay设备,raspberrypi了。

Nginx反向代理跨域option问题解决

CORS on Nginx

The following Nginx configuration enables CORS, with support for preflight requests.

#
# Wide-open CORS config for nginx
#
location / {
     if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        #
        # Custom headers and headers various browsers *should* be OK with but aren't
        #
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        #
        # Tell client that this pre-flight info is valid for 20 days
        #
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain; charset=utf-8';
        add_header 'Content-Length' 0;
        return 204;
     }
     if ($request_method = 'POST') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
     }
     if ($request_method = 'GET') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
     }
}

First is tricking Nginx that a 405 status is actually a 200 OK and then proxy_pass it to your HAProxy like this:

error_page 405 =200 @405;
location @405 {
    root /;
    proxy_pass http://yourproxy:8080;
}

The second solution is just to catch the OPTIONS request and build a response for those requests:

location / {
    if ($request_method = OPTIONS ) {
        add_header Content-Length 0;
        add_header Content-Type text/plain;
        return 200;
    }
}

春风十里

春风十里
作曲作词 倍倍

我在二环的里边 想着你
你在远方的山上 春风十里
今天的风吹向你 下了雨
我说所有的酒 都不如你

我在鼓楼的夜色中 为你唱花香自来
在别处 沉默相遇和期待
飞机飞过 车水马龙的城市
千里之外 不离开

把所有的春天 都揉进了一个清晨
把所有停不下来的言语变成秘密 关上了门
莫名的情愫啊 请问 谁来将它带走呢
只好把岁月化成歌 留在山河

 

时间过得很快,2017年就这么过去了。

这两天一直在循环播放《春风十里》这首歌。最喜欢的一句就是:我说所有的酒,都不如你,千里之外 不离开。

酒,对于每个人来说,都是不同的东西,有喜、有恶。正如小站的名字,酒趣琴音,达是酒中趣,琴上偶然音。前两天朋友圈有人晒出在米国时候的照片,一想已经毕业了七年。三五好友凑一起,小酌,谈谈古,论论今,甚是怀念。当年春田还是留下了太多的身影,十一叔,River,Candy,十三姨,老姑…回国以后,各奔东西,即使是同一城市,也难得碰一次。虽然联系很少,偶尔在异地出差,聚在一起,总还是有说不完的话题。从城市各个角落聚拢,陪吃,陪喝,陪聊,还有陪压马路,当今的快节奏,每个人都很忙,花时间陪伴,也只有真切的同学之间才可能做到了。鸿鹄也好,鹡鸰也好,缘分让大家聚在春田,也让大家留下了这份纯真。

对我来说2017,算是比较动荡的一年,在某个字母公司待了8年,终于下定决心离开了,跑到另外一座城市,迎接未知的挑战。虽然和来之前的初衷有很大的偏差,人性好的、坏的都见识和领教过,至少不算好也不算坏,这一年就这么过去了。生活不只有眼前苟且,还有诗远方。要用眼睛看到诗和远方,还要尝试把诗与远方变成生活,2018谈谈理想吧。

所有的酒,都不如你;千里之外,不曾离开。

 

区块链翻译文章系列(一)初学者指南 Blockchain For Dummies: A Beginner’s Guide

Blockchain For Dummies: A Beginner’s Guide

 

Blockchain: the single most confusing term since Bitcoin. Everyone has a vague idea of what it does. It’s either the ultimate evolution of financial technologies, or a silly fad that can be summed up in the disconcerting phrase: “dogechain.” In reality, major companies around the world have already shown favor to the burgeoning money exchange system and it may become harder and harder to stay away from the financial dark art.
In reality, it is all relatively easy to understand. The Blockchain is a public ledger where transactions are recorded and confirmed anonymously. It’s a record of events that is shared between many parties. More importantly, once information is entered, it cannot be altered. So, if the blockchain is the public record, what is being recorded? What are all of these “transactions”?

Cryptocurrencies, like bitcoin, are currencies that exist solely in digital. There are no physical golden coins with a big “B” on them. Moreover, owning these non-real coins entails a new idea of “ownership.” You don’t literally have it in your hands, or even in your bank account, but you have the ability to transfer “ownership” to someone else simply by creating a record in the blockchain. Rather than using bills, your transfer is pure data.

Where exactly is this chain located? Due to the open nature of cryptocurrencies, and the importance of the public having access to other blocks, the blockchain isn’t located on just one guy’s large computer. For example, the bitcoin blockchain is actually managed by distributed nodes. These nodes all have a copy of the entire blockchain. Nodes will forever come and go, synchronizing their own copies of the chain with those of other users. By distributing copies and access, the chain can’t simply “go down,” or disappear. It’s a decentralized system that is both sturdy and secure.

All of your dogecoins are in a row, but what do you do with them? Whether you’re using them IRL or online, the blockchain makes it happen. There are many reasons people are falling in love with cryptocurrencies: it’s anonymous, decentralized, and there are no fees or third parties trying to grab a percentage. However, if there were absolutely no regulations in place, the new currency would quickly become a greedfest of users trying to screw each other over. The public nature of the blockchain means that anyone can check it. It is effectively anonymous, yet public, simultaneously, and it is in the best interest of users if it remains so.
You can accept and trade coins, or you can mine for them. Miners can spend thousands of dollars on the right equipment just to mine coin. But what do they really do? What miners do is quite similar to real-world miners in that they are actively looking for something. Their computer repeatedly works through complex calculations to find a very specific answer.

Miners solve problems, but how in the world is that helpful? Short story, miners are actually verifying that transactions posted by other users are legitimate, and the numbers all add up. Long story…

Miners collect transactions and put them into a single block. A block generally contains four pieces of information: a reference to the previous block, a summary of included transaction, a time stamp, and Proof of Work that went into creating the secure block. The blocks are strung together into a chain—a fluid chain that does not allow for any inconsistencies; this means there are no “bad cheques” in the system, and transactions entered are necessarily valid and can be processed. By checking the blockchain and confirming transactions, the entire system is effectively self-regulated and fully secure. No, that doesn’t mean some kid cooped up in a basement can just click “okay” and confirm a billion dollar transfer. Blocks generally need numerous independent confirmations, and the equations are intended to be hard to crack. Not to mention, the hardware required is far more specialized than the average laptop. Finally, what’s to stop someone from simply going back and editing existing blocks? Each block is securely hashed—meaning it is rendered into seeming gibberish and nearly impossible to invert or undo. Once it’s in the blockchain, it’s there forever.

rough idea of blockchain
A rough idea of what a block chain may look like, courtesy of Yevgeniy Brikman

python for dummies pdf
A rough idea of what a block chain may look like, courtesy of Yevgeniy Brikman

So, why waste time and resources helping other people, or the blockchain? Why not let someone else do all that “confirmation stuff,” while you just mine? Because, you don’t necessarily have a choice. Confirmation of the blockchain is central to mining. It’s part of the actual mining process; however, miners are generally given incentives. For example, after solving a problem (and creating a new hash) they are rewarded with coins.

Will you be seeing a blockchain-styled ledger in your future? Short answer: oh yes. Blockchain and cryptocurrencies have caused quite a stir over the past years. However, it seems their real importance has yet to be fully realized. The future isn’t just in businesses around the globe sporting happy “Now Accepting Bitcoins” signs, but rather emerging companies (and revolutionary existing ones, too) finding new uses for the cutting edge technology. VC firms and investors are placing their bets on the blockchain because there is untapped potential. Identity management, international contracts, and all sorts of complicated bank transactions can be greatly altered with the public ledger system. The process could (in an ideal world) work seamlessly, crossing boundaries where banks, logistics or a plethora of other obstacles once existed. They could be combined with the Internet of Things to create a more connected and automated world. Future companies may be able to absorb mountains of new data, or even digitize real-world things that are hard to quantify. Unfortunately, many big companies are remaining mum on the studies in the blockchain field for obvious reasons.

However, it is public knowledge that nine major banks (including JP Morgan and Goldman Sachs) recently joined a partnership to develop blockchain technologies. That’s not to say major companies are getting in on the cryptocurrency game; rather, they realize that the blockchain system, itself, could be a powerful tool for efficiency. With a system as versatile and secure as the blockchain, there may many unexpected innovations in the coming months and years.

Origin post:

Blockchain For Dummies: A Beginner’s Guide

BY: HANNAH AUGUR

http://byteacademy.co/blockchain-for-dummies-a-beginners-guide/

CentOS 7 下 firewalld的基本操作

这两天服务器升级,升级后发现有些服务不能用了。后来研究了一下,是因为防火墙的原因。之前调试,为了偷懒,把防火墙关了,就没启动过,现在想想裸奔了几个月,心真是大。

对外增加服务:

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

对内设置安全区

firewall-cmd –permanent –zone=internal –change-interface=enp03s

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

最后,再重新加载firwalld策略

firewall-cmd --reload

以下转载:

http://qianxunclub.com/linux-centos-7-fang-huo-qiang-zhi-ju-you-ming-ling-xing-de-firewalldde-ji-ben-cao-zuo/

启动FirewallD服务:

?

1
2
systemctl enable firewalld.service #设置开机启动
systemctl start firewalld.service #开启服务

查看防火墙状态:

?

1
systemctl status firewalld

1. 区域管理

1.1. 网络区域简介

通过将网络划分成不同的区域,制定出不同区域之间的访问控制策略来控制不同程序区域间传送的数据流。例如,互联网是不可信任的区域,而内部网络是高度信任的区域。网络安全模型可以在安装,初次启动和首次建立网络连接时选择初始化。该模型描述了主机所连接的整个网络环境的可信级别,并定义了新连接的处理方式。有如下几种不同的初始化区域:

  • 阻塞区域(block):任何传入的网络数据包都将被阻止。
  • 工作区域(work):相信网络上的其他计算机,不会损害你的计算机。
  • 家庭区域(home):相信网络上的其他计算机,不会损害你的计算机。
  • 公共区域(public):不相信网络上的任何计算机,只有选择接受传入的网络连接。
  • 隔离区域(DMZ):隔离区域也称为非军事区域,内外网络之间增加的一层网络,起到缓冲作用。对于隔离区域,只有选择接受传入的网络连接。
  • 信任区域(trusted):所有的网络连接都可以接受。
  • 丢弃区域(drop):任何传入的网络连接都被拒绝。
  • 内部区域(internal):信任网络上的其他计算机,不会损害你的计算机。只有选择接受传入的网络连接。
  • 外部区域(external):不相信网络上的其他计算机,不会损害你的计算机。只有选择接受传入的网络连接。

注:FirewallD的默认区域是public。

1.2. 显示支持的区域列表

?

1
firewall-cmd --get-zones

1.3. 设置为家庭区域

?

1
firewall-cmd --set-default-zone=home

1.4. 查看当前区域

?

1
firewall-cmd --get-active-zones

1.5. 设置当前区域的接口

?

1
firewall-cmd --get-zone-of-interface=enp03s

1.6. 显示所有公共区域(public)

?

1
firewall-cmd --zone=public --list-all

1.7. 临时修改网络接口(enp0s3)为内部区域(internal)

?

1
firewall-cmd --zone=internal --change-interface=enp03s

1.8. 永久修改网络接口enp03s为内部区域(internal)

?

1
firewall-cmd --permanent --zone=internal --change-interface=enp03s

2. 服务管理

2.1. 显示服务列表

Amanda, FTP, Samba和TFTP等最重要的服务已经被FirewallD提供相应的服务,可以使用如下命令查看:

?

1
firewall-cmd --get-services

2.2. 允许SSH服务通过

?

1
firewall-cmd --enable service=ssh

2.3. 禁止SSH服务通过

?

1
firewall-cmd --disable service=ssh

2.4. 打开TCP的8080端口

?

1
firewall-cmd --enable ports=8080/tcp

2.5. 临时允许Samba服务通过600秒

?

1
firewall-cmd --enable service=samba --timeout=600

2.6. 显示当前服务

?

1
firewall-cmd --list-services

2.7. 添加HTTP服务到内部区域(internal)

?

1
2
firewall-cmd --permanent --zone=internal --add-service=http
firewall-cmd --reload #在不改变状态的条件下重新加载防火墙

3. 端口管理

3.1. 打开端口

?

1
2
#打开443/TCP端口
firewall-cmd --add-port=443/tcp

?

1
2
3
4
5
#永久打开3690/TCP端口
firewall-cmd --permanent --add-port=3690/tcp
#永久打开端口好像需要reload一下,临时打开好像不用,如果用了reload临时打开的端口就失效了
#其它服务也可能是这样的,这个没有测试
firewall-cmd --reload

?

1
2
#查看防火墙,添加的端口也可以看到
firewall-cmd --list-all

4. 直接模式

FirewallD包括一种直接模式,使用它可以完成一些工作,例如打开TCP协议的9999端口

?

1
2
firewall-cmd --direct -add-rule ipv4 filter INPUT 0 -p tcp --dport 9000 -j ACCEPT
firewall-cmd --reload

5. 关闭服务的方法

你也可以关闭目前还不熟悉的FirewallD防火墙,而使用iptables,命令如下:

?

1
2
3
4
5
systemctl stop firewalld
systemctl disable firewalld
yum install iptables-services
systemctl start iptables
systemctl enable iptables

擦干眼泪,继续工作

昨天注定是个悲伤的日子。

网上流传不会炒币的码农不是一个好码农,我也加入了,昨天中央发文严管ICO和虚拟货币,所有虚拟货币在半小时内价格一落千丈,跌掉20%以上的比比皆是,我相信是哀鸿遍野了。韭菜党估计已经早就开始割了。今早还有同学发来贺电,说老外昨晚好不容易把价格救上来一些,昨晚哭了一晚的韭菜党早上又开始割了,价格继续下跌,慢慢接着哭吧。

还有一件事就是昨天发现博客不能访问了,到邮箱里面看到催缴费的邮件,续费完发现还是找不到我的服务器,提了ticket后,工作人员说服务器已经删除,无法再恢复。虽然一个人絮絮叨叨的自说自话,也没多少人看,这可是俺写了10多年的博客啊。翻箱倒柜,总算找到一个3月份的数据备份,最后几篇也找不到了。前不久博客被鬼子黑过,插入了木马,google的所有的链接都被变成了他们的广告,正好备份了网站文件。把这两个加一起基本恢复到了3月份的状态,也算是不幸中的万幸。

放上中岛美嘉的雪の華、经历了多少不甘之后还能站出来在舞台上用自己沙哑的声音重新演绎自己的前半生。不幸又能怎么样,擦干眼泪,大不了重新再来。

 

雪の華-中島美嘉

のびた人陰(かげ)を舗道にならべ
不断延伸的影子 在红砖道上并列
夕闇のなかを君と歩いてる
在深夜里与你并肩走着
手をつないでいつまでもずっと
永远紧紧牵着手
そばにいれたなら
只要能在你身旁
泣けちゃうくらい
我就感动得快要哭了
風が冷たくなって
风儿变得寒冷
冬の匂いがした
有了冬天的味道
そろそろこの街に
这条街也即将到了
君と近付ける季節がくる
能和你接近的季节来临
今年、最初の雪の華を
今年 最初的雪花
ふたり寄り添って
向我俩靠近
眺めているこの瞬間(とき)に
在眺望着的这个瞬间里(时间)
幸せがあふれだす
充满了幸福的喜悦
甘えとか弱さじゃない
没有撒娇和脆弱
ただ、君を愛してる
只是 爱你
心からそう思った
打从心底爱你
君がいるとどんなことでも
只要有你在 无论发生什么
乗りきれるような気持ちになってる
都会有可以克服的心情
こんな日々がいつまでもきっと
我祈祷着 这样的日子
続いてくことを祈っているよ
一定会直到永远
風が窓を揺らした
风儿吹的窗摇
夜は揺り起こして
把夜晚摇醒
どんな悲しいことも
无论多么悲伤的事情
僕が笑顔へと変えてあげる
我用笑容为你改变
舞い落ちてきた雪の華が
雪花飞舞飘落
窓の外ずっと
在窗外一定
降りやむことを知らずに
不知何时雪已停
僕らの街を染める
把我们的街道染色
誰かのために何かを
为某人想做
したいと思えるのが
些什么事
愛ということを知った
原来 这就是爱
もし、君を失ったとしたなら
如果 失去了你
星になって君を照らすだろう
我会变成星星照亮你
笑顔も涙に濡れてる夜も
微笑或被泪水沾湿的夜晚
いつもいつでもそばにいるよ
我会永远在你身旁
今年、最初の雪の華を
今年 最初的雪花
ふたり寄り添って
向我俩靠近
眺めているこの瞬間(とき)に
在眺望着的这个瞬间里
幸せがあふれだす
充满了幸福的喜悦
甘えとか弱さじゃない
没有撒娇和脆弱
ただ、君とずっと
只是 想永远地
このまま一緒にいたい
就这么一直在一起
素直にそう思える
我真心地这么想
この街に降り積もってく
在这条街上堆积的
真っ白な雪の華
纯白雪花
ふたりの胸にそっと想い出を描くよ
悄悄地在我俩胸口画上回忆
これからも君とずっと…
从今而后也要永远和你在一起

候鸟模式

在一个字母公司一待就是8年,8年没有感情是不可能的,但是上升无望,如果继续无忧无虑的下去,不知道前途在何方。在去年年底终于下定决心离开,来到另外一家字母公司。

也许本身对这家字母公司也是短期跳板的期望,没有过多融入,在三观还没有完全毁尽之前快速离开,来到现在这家研究院。

这项技术目前处于风口,是否能够让我成功转型尚属未知。未知的自己,未知的明天。也正因为如此,抛妻弃子,开启了周末候鸟模式,铁老大该发笑了。

在公寓里还能听取外边还能蛙声一片,但愿今年能够稻花香里说丰年吧。

Auto start a java Swing GUI program when raspberry boots

I planed make an self-desgin photo or movie player base on Raspberry. Also I can use it as photo frame. If I need improve the performance of the PI, I need write it with Python, I think.

 

Part 1 – Build the Foundation

In this part, we will focus on preparing Raspbian Lite.

1. Download the latest Raspbian Lite image.
2. Format the SD / microSD card with Raspbian Lite (Plenty of guides out there on how to do this. For macOS, Linux, and Windows users, Etcher is an easy to use application that can help you do this.)
3. Insert the SD / microSD card into the Pi.
4. Connect the Pi to the Internet using an Ethernet cable. If you want to use Wi-Fi instead, you will have to read on how to configure your wireless receiver using the command line after your Pi has finished booting.
5. Connect your TV / Monitor and keyboard. (Mouse is optional at this time.) Turn on the Pi. The Pi should boot up successfully and a prompt to log in will appear.
6. Log into Raspbian. The username is pi and the password is raspberry.

 

7. We will install Xorg. To do this type in:

sudo apt-get install –no-install-recommends xserver-xorg

sudo apt-get install –no-install-recommends xinit

now, you can write you java program now. For example, I wrote a test program with a button in the center of screen. once I click the button, the window will change to the full size of the screen.

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;

public class FullScreenTest {
public static void main(String[] args) {
final JFrame f = new JFrame(“FullScreenTest”);
final JButton btn = new JButton(“FullScreen”);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (btn.getText().equals(“FullScreen”)) {
f.dispose();
f.setUndecorated(true);
f.getGraphicsConfiguration().getDevice().setFullScreenWindow(f);
f.setVisible(true);
btn.setText(“NormalMode”);
} else {
f.dispose();
f.setUndecorated(false);
f.getGraphicsConfiguration().getDevice().setFullScreenWindow(null);
f.setVisible(true);
btn.setText(“FullScreen”);
}
}
});

f.getContentPane().setLayout(new FlowLayout());
f.getContentPane().add(btn);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}

 

Pack the file into a jar file like GUI.jar.

In order to have a command or program run when the Pi boots, you can add commands to the rc.local file. This is especially useful if you want to be able to plug your Pi in to power headless, and have it run a program without configuration or a manual start.

EDITING RC.LOCAL

On your Pi, edit the file /etc/rc.local using the editor of your choice. You must edit with root, for example:

sudo nano /etc/rc.local

Add commands below the comment, but leave the line exit 0 at the end, then save the file and exit.

sudo xinit /usr/local/jdk1.8.0_77/bin/java -jar /usr/local/mypi/GUI.jar — :1 &

 

 

Reboot your PI, then done!

I have crossed the oceans of time, to find you

I have crossed the oceans of time, to find you

对白台词,煽情的,经典的,听得也不少
很多早就过耳既忘
可是,这一句,却常常响起在耳畔
抑或早已铭刻于心
“我穿越了时间的瀚海来寻找你……”
时间,海洋,爱情,四百年,等待,轮回,
一幅幽远,广阔,空旷的场景
如果用时间来丈量爱情,四百年够不够长?
如果用空间来丈量爱情,无边的海洋够不够宽广?

我却可以将时空的阻碍一一跨越,
纵使灵魂坠入无边的深渊
纵使绝望与痛苦的阴风霾雨要将我吞噬
只是,只是为了找到你

洗心2:安心就能闲下来

秋雨,毛毛雨,散文一样下着,下着光线,湿湿的光线。织布机织出来的一匹秋雨。而秋寒的灯光,湘绣一样,把窟窿绣在秋雨的布匹上。秋雨套在夜的身上,套在夜的里面做内衣,也套在夜的外面,作为披风。

一盏灯,一颗心,一杯禅,一杯茶,无限的寂寞与孤独,超越了就无限自在,就像一位老人。

秋雨夜眠

白居易

凉冷三秋夜,安闲一老翁。

卧迟灯灭后,睡美雨声中。

灰宿温瓶火,香添暖被笼。

晓晴寒未起,霜叶满阶红。

此诗为大和六年秋(832),白居易任河南尹时作。这时他已经60多岁,体衰多病,官务清闲,加上亲密诗友元稹已经谢世,心情寂寞。该诗多少反映诗人暮年政治上的心灰意懒、生活上孤寂闲散的状况。

全诗紧紧把握老翁秋雨夜安眠的特征,富有生活味道,实际上这时写面对生活历程最后的冷静淡定。

洗心1:用心洗干净心,用血洗干净血

泥土笑话了多少人间垃圾,大自然消化了多少人的黑暗与邪恶。泥土希望维持自己的高尚与干净,自然希望坚持自己的青青微笑去绿化人间。

泥土愿意洗干净人的欲望,但人的很多不正当欲望太邪恶,泥土也深感辛苦,它没有受到人对它的尊重。

颂七处心偈

西余净端

七处征心心不遂,懵懂阿难不瞥地。

直饶征得见无心,也是泥中洗土块。

生命的本质就是要超越人间不自由的极限,去掉枷锁而得到真正的自在

寻心10:没有人类的春天更像另外一种春天

水的书法决定了一个世界的格局。江河湖海,小溪池塘,凡水的点点滴滴,一笔一画,谁的偏旁部首,都爱建筑世界的施工,有水才有墨汁,有水才有原油。

春天为一粒行囊,打开一丝诗歌的出路,发芽。一粒山的种子,说出自己的枝枝叶叶偏旁部首一笔一画的书法组织,春天就生机了自己。

春行即兴

李华

宜阳城下草萋萋,涧水东流复向西。

芳树无人花自落,春山一路鸟空啼。

李华,唐代诗人。这首景物小诗,是诗人在春天经由宜阳时,对眼前景物有感,即兴抒发了国破山河在、花落鸟空啼的愁绪。但诗更展示了比坐着的感受更大的境界:世界无人时,它们有自己的完整。