0%

Debugging FUSE Filesystem.

Collect some tip/tricks for debugging FUSE.

Program options

  1. -f : Run foreground
  2. -s : Disable multiple threading
  1. Enable debugging
    1. Compiling with debugging symbols enabled(-g to gcc)
    2. enable core dumps: ulimit -c unlimited
    3. If program crashes, it will have core dump in current directory
    4. load the core file: `gdb

Tools

  1. Valgrind: Valgrind is an instrumentation framework for building dynamic analysis tools.

    #include <valgrind/valgrind.h>
    
    if (RUNNING_ON_VALGRIND) {
        fprintf(stderr,
            "******** Valgrind has been detected by %s\n"
            "******** If you have difficulties getting %s to work under"
            " Valgrind,\n"
            "******** see the following thread:\n"
            "******** http://www.nabble.com/valgrind-and-fuse-file-systems"
            "-td13112112.html\n"
            "******** Sleeping for 5 seconds so this doesn't fly by ....",
                progname, progname);
        sleep(5);
        fprintf(stderr, "\n");
    }

    Reference: Code from Tim Post

  2. User-Mode Linux

Documents/Tutorials

  1. CS135 FUSE Document
  2. Use GDB to Understand FUSE File System

最近VSCode真香中…人老了就感觉不喜欢话时间再折腾一些生产工具, 当然Emacs/Vim还是用的很多,但是越来越多在source code reading 的时候会更倾向与打开vscode了。

换一种编辑器最大问题在于熟悉快捷键(反之一款好编辑器就应该让快捷键很直观,就像”The design of Everyday Everything” 中有提到的那样, 符合人们的mentor model)

分享一些不常用但很有用的快捷键, 根据个人喜好可以改一下和系统的冲突。 有新发现的会继续更新

官方的文档可以通过Ctrl-P然后输入”> help keyboard shortcuts” 获取
文档

Select

原生支持:

  1. Expand Select

    1
    Shift + Alt + RightArrow
  2. Shrink Select

    1
    Shift + Alt + LeftArrow
  3. Select In Words

    这个我一直习惯用Ctrl+Alt+Left/Right, 但是和Ubuntu的workspace切换冲突了..

    1
    Ctrl + Shift + Right/LeftArrow

插件:

  1. “Quick and Simple Text Selection” by David Bankier. 支持更多的快速选择

    Ctrl+k 之后再按一个以下字符,可以选择被包括在其中的字符串

    1
    2
    3
    4
    5
    6
    7
    8
    Ctrl + K ' select everything between single quotes
    Ctrl + K " select everything between double quotes
    Ctrl + K ` select everything between back ticks
    Ctrl + K ( select everything inside parenthesis
    Ctrl + K ) select everything inside parenthesis and include them
    Ctrl + K [ or ] select everything between square brackets and include them
    Ctrl + K { or } select everything between curly braces and include them
    Ctrl + K < or > select everything between angle brackets and include them

Windows management

原生支持:

  1. Re-open a closed editor

    1
    Ctrl+Shift+T

    这个操作和Chrome浏览器一样, Nice~!

  1. Keyboard Shortcuts

    1
    Ctrl-K Ctrl-S
  2. Open file always in a new tab

    VSCode大概是新开文件默认预览模式,不会保存窗口。 在settings里做以下设置可以总是保持打开新窗口(Ctrl-P)

    1
    "workbench.editor.enablePreview": false

Text Edition

原生支持

  1. Move line up/down

    1
    Alt + Up/DownArrow
  2. Bracket matching

    1
    Ctrl+Shift+\

References

21 VSCode Shortcuts To Code Faster and Funner


欢迎在留言补充更多Tricks;)

《商业模式全史》这本书是日本作家三谷宏治所作。

在亚马逊关掉国内的网站前买了这本书,很早之前看到过,这位作者也还有另外一本和商业相关的书。

全书一共有以下几个章节。 会慢慢概括和罗列一些书中提到的公司和模式。

什么是商业模式

商业模式/Business Model, 这个词语听起来还挺高大上的。说通俗一点其实就是通过什么方法赚钱/盈利。

创生期(1673-1969)

变革期(1970=1990)

创造期(1991-2001)

巨无霸战争与“小个子”崛起

如何进行商业模式创新

相关

推荐另一本我读过的Business Model Generation。这是一本教读者怎么去“画”一个商业模式的书。像slide 一样一页一页的书, 能从中读出一些新的思考方式和角度。

Share a script I used today to generate batch of barcodes by using Python.

  1. generate the range of barcode you want.
  2. use label to generate an image.
  3. fill the image generated in step 2 into a PDF and save it.
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

#!/usr/bin/env python3
from itertools import product

from typing import List
from reportlab.lib.pagesizes import A4
from reportlab.graphics.shapes import Drawing, String
from reportlab.graphics.barcode.eanbc import Ean13BarcodeWidget
from reportlab.graphics import renderPDF
from reportlab.pdfgen.canvas import Canvas

PAGESIZE = A4 # choose the final print page size
NUM_LABELS_X = 3 # how many barcodes per line
NUM_LABELS_Y = 5 # how many barcodes per column
BAR_WIDTH = 1.5 # barcode length
BAR_HEIGHT = 51.0 # barcode height
TEXT_Y = 80
BARCODE_Y = 17

LABEL_WIDTH = PAGESIZE[0] / NUM_LABELS_X
LABEL_HEIGHT = PAGESIZE[1] / NUM_LABELS_Y
SHEET_TOP = PAGESIZE[1]

def codes(number):
""" Generate all the possible barcodes
params
number: the range number of each position
"""
for barcode in product(range(10), repeat = number):
yield "".join(map(str, barcode))

def label(ean13: str, description: str) -> Drawing:
"""
Generate a drawing with EAN-13 barcode and descriptive text.
:param ean13: The EAN-13 Code.
:type ean13: str
:param description: Short product description.
:type description: str
:return: Drawing with barcode and description
:rtype: Drawing
"""
print(ean13)
text = String(0, TEXT_Y, description, fontName="Helvetica",
fontSize=10, textAnchor="middle")
text.x = LABEL_WIDTH / 2 # center text (anchor is in the middle)

barcode = Ean13BarcodeWidget(ean13)
barcode.barWidth = BAR_WIDTH
barcode.barHeight = BAR_HEIGHT
x0, y0, bw, bh = barcode.getBounds()
barcode.x = (LABEL_WIDTH - bw) / 2 # center barcode
barcode.y = BARCODE_Y # spacing from label bottom (pt)
label_drawing = Drawing(LABEL_WIDTH, LABEL_HEIGHT)
label_drawing.add(text)
label_drawing.add(barcode)
return label_drawing

def fill_sheet(canvas: Canvas, label_drawings: List[Drawing]):
"""
Simply fill the given ReportLab canvas with label drawings.
:param canvas: The ReportLab canvas
:type canvas: Canvas
:param label_drawing: Contains Drawing of configured size
:type label_drawing: Drawing
"""
index = 0
for u in range(0, NUM_LABELS_Y):
for i in range(0, NUM_LABELS_X):
x = i * LABEL_WIDTH
y = SHEET_TOP - LABEL_HEIGHT - u * LABEL_HEIGHT
if index >= len(label_drawings):
break
renderPDF.draw(label_drawings[index], canvas, x, y)
index += 1

if __name__ == '__main__':
raw_codes = [code for code in codes(3)]
labels = [label("490177241" + code, '') for code in raw_codes[:200]]
total = NUM_LABELS_X * NUM_LABELS_Y
page = 1
while labels:
canvas = Canvas("{}.pdf".format(page), pagesize=PAGESIZE)
page += 1
fill_sheet(canvas, labels[:min(total, len(labels))])
canvas.save()
labels = labels[min(total, len(labels)):]

Previously I was using pyinotify to do some event notify jobs on local files.

This blog(with the testing script attached) is simply a summary which lists the events type and happening orders when doing different operations.

Script

Downlaod the test script here

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python2
import subprocess
import pyinotify
import os
import shutil
mask = pyinotify.ALL_EVENTS
rootdir = '/tmp/test-pyinotify'

def _process_watcher_events(event):
print("event = %s" % event)

def _(path):
return os.path.join(rootdir, path)

def commands():
commands = [
['ls', rootdir],
['touch', _('origin.txt')],
['cp', _('origin.txt'), _('cp.txt')],
['mv', _('cp.txt'), _('mv.txt')],
['mv', _('mv.txt'), '/tmp/mv.txt'],
['rsync', '-a', '/tmp/mv.txt', _('rsync.txt')],
['scp', '/tmp/mv.txt', _('scp.txt')],
['ln', '-s', _('origin.txt'), _('ln.txt')],
['rm', _('ln.txt')],
['mkdir', _('testdir')],
['ln', _('origin.txt'), _('lnhard.txt')],
['python', '-c', "import os; f = open(os.path.join('%s', 'python.txt'), 'w'); f.write('test_python'); f.close()" % rootdir]
]
for cmd in commands:
print cmd
output = subprocess.check_output(cmd)
yield


if __name__ == "__main__":
if os.path.exists(rootdir):
shutil.rmtree(rootdir)
os.makedirs(rootdir)
watcher = pyinotify.WatchManager()
watcher.add_watch(rootdir, mask=mask, rec=True, auto_add=True, quiet=False)
notifier = pyinotify.Notifier(watcher, _process_watcher_events)
commands = commands()
while True:
notifier.process_events()
try:
next(commands)
while notifier.check_events(timeout=3):
notifier.read_events()
notifier.process_events()
print('===========================================\n')
except StopIteration:
while notifier.check_events(timeout=3):
notifier.read_events()
notifier.process_events()
print('finished')
break
shutil.rmtree(rootdir)

Summary

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
>>> python2 test_pyinotify.py

>>>
['ls', '/tmp/test']
event = <Event dir=True mask=0x40000020 maskname=IN_OPEN|IN_ISDIR name='' path=/tmp/test pathname=/tmp/test wd=1 >
event = <Event dir=True mask=0x40000001 maskname=IN_ACCESS|IN_ISDIR name='' path=/tmp/test pathname=/tmp/test wd=1 >
event = <Event dir=True mask=0x40000010 maskname=IN_CLOSE_NOWRITE|IN_ISDIR name='' path=/tmp/test pathname=/tmp/test wd=1 >
===========================================

['touch', '/tmp/test/origin.txt']
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=origin.txt path=/tmp/test pathname=/tmp/test/origin.txt wd=1 >
event = <Event dir=False mask=0x20 maskname=IN_OPEN name=origin.txt path=/tmp/test pathname=/tmp/test/origin.txt wd=1 >
event = <Event dir=False mask=0x4 maskname=IN_ATTRIB name=origin.txt path=/tmp/test pathname=/tmp/test/origin.txt wd=1 >
event = <Event dir=False mask=0x8 maskname=IN_CLOSE_WRITE name=origin.txt path=/tmp/test pathname=/tmp/test/origin.txt wd=1 >
===========================================

['cp', '/tmp/test/origin.txt', '/tmp/test/cp.txt']
event = <Event dir=False mask=0x20 maskname=IN_OPEN name=origin.txt path=/tmp/test pathname=/tmp/test/origin.txt wd=1 >
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=cp.txt path=/tmp/test pathname=/tmp/test/cp.txt wd=1 >
event = <Event dir=False mask=0x20 maskname=IN_OPEN name=cp.txt path=/tmp/test pathname=/tmp/test/cp.txt wd=1 >
event = <Event dir=False mask=0x8 maskname=IN_CLOSE_WRITE name=cp.txt path=/tmp/test pathname=/tmp/test/cp.txt wd=1 >
event = <Event dir=False mask=0x10 maskname=IN_CLOSE_NOWRITE name=origin.txt path=/tmp/test pathname=/tmp/test/origin.txt wd=1 >
===========================================

['mv', '/tmp/test/cp.txt', '/tmp/test/mv.txt']
event = <Event cookie=416768 dir=False mask=0x40 maskname=IN_MOVED_FROM name=cp.txt path=/tmp/test pathname=/tmp/test/cp.txt wd=1 >
event = <Event cookie=416768 dir=False mask=0x80 maskname=IN_MOVED_TO name=mv.txt path=/tmp/test pathname=/tmp/test/mv.txt src_pathname=/tmp/test/cp.txt wd=1 >
===========================================

['mv', '/tmp/test/mv.txt', '/tmp/mv.txt']
event = <Event cookie=416769 dir=False mask=0x40 maskname=IN_MOVED_FROM name=mv.txt path=/tmp/test pathname=/tmp/test/mv.txt wd=1 >
===========================================

['rsync', '-a', '/tmp/mv.txt', '/tmp/test/rsync.txt']
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=.rsync.txt.o0Quqe path=/tmp/test pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
event = <Event dir=False mask=0x20 maskname=IN_OPEN name=.rsync.txt.o0Quqe path=/tmp/test pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
event = <Event dir=False mask=0x4 maskname=IN_ATTRIB name=.rsync.txt.o0Quqe path=/tmp/test pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
event = <Event dir=False mask=0x8 maskname=IN_CLOSE_WRITE name=.rsync.txt.o0Quqe path=/tmp/test pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
event = <Event dir=False mask=0x4 maskname=IN_ATTRIB name=.rsync.txt.o0Quqe path=/tmp/test pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
event = <Event cookie=416770 dir=False mask=0x40 maskname=IN_MOVED_FROM name=.rsync.txt.o0Quqe path=/tmp/test pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
event = <Event cookie=416770 dir=False mask=0x80 maskname=IN_MOVED_TO name=rsync.txt path=/tmp/test pathname=/tmp/test/rsync.txt src_pathname=/tmp/test/.rsync.txt.o0Quqe wd=1 >
===========================================

['scp', '/tmp/mv.txt', '/tmp/test/scp.txt']
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=scp.txt path=/tmp/test pathname=/tmp/test/scp.txt wd=1 >
event = <Event dir=False mask=0x20 maskname=IN_OPEN name=scp.txt path=/tmp/test pathname=/tmp/test/scp.txt wd=1 >
event = <Event dir=False mask=0x8 maskname=IN_CLOSE_WRITE name=scp.txt path=/tmp/test pathname=/tmp/test/scp.txt wd=1 >
===========================================

['ln', '-s', '/tmp/test/origin.txt', '/tmp/test/ln.txt']
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=ln.txt path=/tmp/test pathname=/tmp/test/ln.txt wd=1 >
===========================================

['rm', '/tmp/test/ln.txt']
event = <Event dir=False mask=0x200 maskname=IN_DELETE name=ln.txt path=/tmp/test pathname=/tmp/test/ln.txt wd=1 >
===========================================

['mkdir', '/tmp/test/testdir']
event = <Event dir=True mask=0x40000100 maskname=IN_CREATE|IN_ISDIR name=testdir path=/tmp/test pathname=/tmp/test/testdir wd=1 >
===========================================

event = <Event dir=True mask=0x40000020 maskname=IN_OPEN|IN_ISDIR name=testdir path=/tmp/test pathname=/tmp/test/testdir wd=1 >
event = <Event dir=True mask=0x40000020 maskname=IN_OPEN|IN_ISDIR name='' path=/tmp/test/testdir pathname=/tmp/test/testdir wd=2 >
event = <Event dir=True mask=0x40000001 maskname=IN_ACCESS|IN_ISDIR name=testdir path=/tmp/test pathname=/tmp/test/testdir wd=1 >
event = <Event dir=True mask=0x40000001 maskname=IN_ACCESS|IN_ISDIR name='' path=/tmp/test/testdir pathname=/tmp/test/testdir wd=2 >
event = <Event dir=True mask=0x40000001 maskname=IN_ACCESS|IN_ISDIR name=testdir path=/tmp/test pathname=/tmp/test/testdir wd=1 >
event = <Event dir=True mask=0x40000001 maskname=IN_ACCESS|IN_ISDIR name='' path=/tmp/test/testdir pathname=/tmp/test/testdir wd=2 >
event = <Event dir=True mask=0x40000010 maskname=IN_CLOSE_NOWRITE|IN_ISDIR name=testdir path=/tmp/test pathname=/tmp/test/testdir wd=1 >
event = <Event dir=True mask=0x40000010 maskname=IN_CLOSE_NOWRITE|IN_ISDIR name='' path=/tmp/test/testdir pathname=/tmp/test/testdir wd=2 >
===========================================

['ln', '/tmp/test/origin.txt', '/tmp/test/lnhard.txt']
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=lnhard.txt path=/tmp/test pathname=/tmp/test/lnhard.txt wd=1 >
===========================================

['python', '-c', "import os; f = open(os.path.join('/tmp/test', 'python.txt'), 'w'); f.write('test_python'); f.close()"]
event = <Event dir=False mask=0x100 maskname=IN_CREATE name=python.txt path=/tmp/test pathname=/tmp/test/python.txt wd=1 >
event = <Event dir=False mask=0x20 maskname=IN_OPEN name=python.txt path=/tmp/test pathname=/tmp/test/python.txt wd=1 >
event = <Event dir=False mask=0x2 maskname=IN_MODIFY name=python.txt path=/tmp/test pathname=/tmp/test/python.txt wd=1 >
event = <Event dir=False mask=0x8 maskname=IN_CLOSE_WRITE name=python.txt path=/tmp/test pathname=/tmp/test/python.txt wd=1 >
===========================================

finished

pyinotify result table