Author: Blaok
“屁股决定脑袋”这句话真是好悲伤啊。许多人连自己屁股在哪里都搞不清楚。
#!/bin/bash max_jobs=${JOBS:=$(nproc)} pipe_file=$(mktemp --dry-run) mkfifo ${pipe_file} exec {pipe_fd}<>${pipe_file} rm ${pipe_file} printf "%-${max_jobs}s" >&${pipe_fd} for job in ... do read -n 1 -u ${pipe_fd} ( echo "start ${job}" # do stuff for ${job} ... echo "finish ${file}" printf '%-1s' >&${pipe_fd} )& done wait
This piece of script uses a FIFO to manage the parallel jobs. Initially, the FIFO is filled with n characters, each representing an available slot for a job. Before a job starts, it reads a character from the FIFO. Once a job finishes, a character is written back to the FIFO. Thus the FIFO is empty if and only if there are n jobs running. New jobs will not be spawned because the FIFO read will block until at least 1 running job finishes.
{varname}
style automatic file descriptor allocation requires bash 4.1+.
Reference:
https://superuser.com/questions/184307/bash-create-anonymous-fifo
2018,괜찮아요
Force Registering in Vivado HLS
Make Cosim Great Again
There are problems in the rt2800usb
driver on Linux and according to this post I have to set nohwcrypt=1
for the rt2800usb
kernel module.
sudo ifconfig wlan0 down sudo rmmod -f rt2800usb sudo modprobe rt2800usb nohwcrypt=1 sudo ifconfig wlan0 up
To make it permenant I have to put the following in /etc/modprobe.d/rt2800usb.conf
options rt2800usb nohwcrypt=1
Damn it… I really should have found this earlier…
2017,路漫漫
记得初中的时候经常有作文题讲,人生是两杯酒,一杯苦酒,一杯甜酒,以此教育大家先苦后甜。
然而,任何智力正常的人,不都应该把甜酒喝了吧苦酒倒了吗 (╯ ̄Д  ̄)づ╧═╧
今天洗澡的时候,突然想到,这个事情其实可以更严谨一点建模:
人类出生的时候有两杯酒,一杯苦酒,一杯甜酒。规定酒必须一杯一杯喝。如果喝掉苦酒,则会再端上来一杯苦酒和一杯甜酒;如果喝掉甜酒,则自动有一杯苦酒被倒掉。酒不允许超支和借贷,也不会随意消失或出现。人类喜欢喝甜酒,不喜欢喝苦酒。
于是想喝甜酒就必须先喝苦酒,要是图一时之快喝光了甜酒就不再有机会喝到更多的甜酒,因为喝苦酒是唯一获得更多甜酒的方式。所以还是乖乖地先苦后甜吧。
然而,都说了是反鸡汤,因为事实上——
有的人出生的时候是带了一箱甜酒啊 (╯ ̄Д  ̄)づ╧═╧
有的人出生的时候是带了一箱苦酒,而且喝前面一大半的时候还不给带甜酒 (╯ ̄Д  ̄)づ╧═╧
有的人好死不死就是会被天上掉下来的甜酒砸啊 (╯ ̄Д  ̄)づ╧═╧
不说了,我去喝苦酒去了 *~( ̄▽ ̄)~[]
2016,活久见
Pass a Device to a Linux Container
If you are working with some software which requires you to source some code and messes up with your PATH
and other environment variables like Vivado and Merlin compiler, here is a simple and straightforward method to get rid of the mess (to some extent).
#!/bin/bash VERSION=2016.1 . /space/Xilinx/SDAccel/${VERSION}/settings64.sh # do something if necessary if ! test "$0" -ef "$(which $(basename $0))" then exec $(basename $0) "$@" else if test -t 2 then echo "Recursive call detected!" 1&>2 fi fi
Some notes:
- Start with
#!/bin/bash
if you or your script use bash-specific syntax! - Give this file execution permission with
chmod +x
! - Make sure this file itself has the same name as the target program, or is soft-linked to it!
- Use
.
instead ofsource
, which improves compatibility!
On Linux, if you see
mtr: unable to get raw sockets.
The following might help:
sudo chmod 4755 $(which mtr)
The reason this happens is that only privileged processes (or processes with proper capabilities(7)
on Linux) can create raw sockets, which is needed to send/receive ICMP packets. By chmod(2)
, the executable will get the S_ISUID
mode, which means it can set process effective user ID when execve(2)
.
A safer solution is
sudo setcap cap_net_raw+ep $(which mtr)
which only gives mtr
the cap_net_raw
capability.
Reinstalling the mtr
package via the package manager should also solve the problem since it will do whatever appropriate to make it work.
Protected: Renee Go
Farewell
According to cplusplus.com, std::vector<bool>
in C++ is specialized and consumes only 1/8 space as you may have expected. However, as 8-bit bytes are usually the shortest available type in most implementations, thread-safety is not guaranteed. This could have caused significant trouble in my current project. How lucky I am to notice this interesting feature before I have actually encountered trouble.
Besides, std::bitset
provides a fixed size bit array whose length is fixed at compile-time.
μtorrent Optimization Guide
Enable HTTP/2 in Nginx
一碗古老的鸡汤
2015,逝者如斯
今天看到一句话,“不理解,但尊重”。且不说社会,就是放在一个人身上,又有谁能说到做到呢。
别人家的地图
世间事,总有一些,我可以不反对,但绝不会赞同。
我为什么还在用Windows
突然有一天,我的iPad播不出声音了……耳机不行……扬声器也不行……蓝牙都不行……不是静音的问题……重启没有用……所有的播放器都没声了……直到我找到了这篇帖子。其实只要删除
/System/Library/PrivateFrameworks/IAP.framework/Support/iapd
然后重启就行了……