Technical Blog of Jian Wang
System area, algorithms, program language, C/C++
Monday, June 1, 2020
mac_apt recover notes
https://github.com/ydkhatri/mac_apt/wiki/Installation-for-Python3.7
https://github.com/ydkhatri/mac_apt/wiki/NOTES
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/sbin
chmod u+w /usr/local/bin /usr/local/lib /usr/local/sbin
brew install python3 git
sudo pip3 install --upgrade virtualenv
git clone --recursive https://github.com/ydkhatri/pylzfse
cd pylzfse
python setup.py build
python setup.py install
pip3 install pytsk3==20170802 libvmdk-python==20181227
tar xfz ./libewf-20140808.tar.gz
cd libewf-20140808
python setup.py build
python setup.py install
pip install biplist construct==2.9.45 xlsxwriter plistutils kaitaistruct lz4 pycryptodome cryptography pybindgen==0.21.0 pillow
cd ..
sudo pip3 install pyaff4-0.31-yk.zip
git clone https://github.com/libyal/libewf-legacy/
cd libewf-20140808
python3 setup.py build
sudo python3 setup.py install
cd
cd mac_apt/
source env/bin/activate
python ./mac_apt.py -x -o output E01 /Users/jianw/Library/Containers/com.apple.Notes/Data/Library/Notes/NotesV7.storedata NOTES
python ./mac_apt.py -x -o output E01 "/Users/jianw/Library/Group\ Containers/group.com.apple.notes/NoteStore.sqlite" NOTES
Wednesday, December 27, 2017
Frequent Interview questions
=====================================================================
LC1TwoSum----------------------------
LC12IntegerToRoman.
LC13RomanToInteger
LC20ValidParentheses----------------
LC21MergeTwoSortedLists. -------------------
LC33SearchRotatedSortedArray---------
LC34Search for a range-----------
LC46PermutationI-------------------
LC47PermutationII---------------
LC50Powerxn-----------
LC53MaximumSubarray-------------------
LC56MergeIntervals---------------------
LC65ValidNumber高频---------------------
LC69SqrtX------------
LC76Min Window SubString-------------------------
LC77Combinations----------------
LC81SearchRotatedSortedArrayII------------------------
LC88MergeSortedArray--------------
LC90SubSetsII---------------------
LC100SameTree--------------------
LC102BinaryTreeLevelOrderTraversal-------------
LC103ZigZag--------------
LC127WordLadder-------------------
LC126WordLadderII-----------------------
LC149MaxPointsInaLine---------
LC150EvaluateReversePolishNotation---------
LC151ReverseWordInAString------------------
LC152MaximumProductSubarray-----------------------
LC156BinaryTreeUpsideDown-------------------
LC160IntersectionTwoLinkedLists. & Union-------------------
LC170TwoSumIII-------------
LC173BinarySearchTreeIterator----------------
LC186ReverseWordsStringII-----------------
LC187RepeatedDNASequences-------------------
LC189RotateArray-------------
LC199BinaryTreeRightSideView----------
LC200 number of islands--------------
LC205IsomorphicStrings------------------
LC215KthLargestArray--------
LC235LowestCommonAncestorBinaryTree-------
LC236LowestCommonAncestorII-----------------
LC243ShortestWordDistance------------
LC244ShortestWordDistanceII----------
LC245ShortestWordDistanceIII-----------
LC254MyFactors----------------------
LC266PalindromePermutation-------------------
LC267------------------------
LC277FindCelebrity--------------
LC297Serilize & deserilize
LC339SumNestedList----------------
LC347TopKFrequentElements--------------
LC364 Nested SumII----------------
LC366PrintTreeLeaf-------------------
LC380InsertDeleteGetRandomI----------------
LC381InsertDeleteGetRandomII---------------
LC409LongestPalindrome------------------------------
LC534TinyURL------------------
LC605Can place flower-------------------------
BoundedBlockingQueue------------------------
GenericClass
LinkedListSingle2Double
MaximumDepth BT----------------------
实现一个hash table,get, put, 最后在加一个resize-----------------
============================================
MaximumIntervalsOverlap
Coding: Maximum number of overlapping intervals
For example – { (0,2), (3, 7), (4,6), (7,8), (1,5) }. The maximum number of intervals overlapped is 3 during (4,5).
===========================================
MultiSum
KNearestPoints2D
QuickSort
RightRotateTree
ThreeClosestElements
Triangle
TriangleII
convert bst to doubly linked list
binary tree to n-ary tree
maximum palindrome subarray
===================
题目: Given一个array of non-negative integers, 找出3组数字可以组成3角形, 每个数字表示边长, 组成3角形的充要条件就是任2边的和要大于第3边 答案: 对这个array做sorting后, 从array的最小的element开始往最大去扫, 以连续3个数字一组确认是否可以构成3角形
====================
一棵树有不限个数的子节点,有多层节点,不规则分布。给定子节点数K,重构这棵树。比如,子节点数是3。那么第一层是1个节点,第二层是3个节点,因为root最多有可以有三个节点。第三层是9个节点,因为第二层的三
===============================
2)retainBestCache,设计一个cache,他给你一个getRank()的方法,当cache满了的时候,要把rank最低的移除,开始以为是LRU Cache,结果发现不是,稍微有点慌,卡住了,说用arraylist来存,说完发现好蠢,每次移除都得O(n)来找rank最低的,然后他提示我还可以更高效,我一下子就想到了PriorityQueue,面完了发现确实该用PriorityQueue,可惜没完全写完,把comparator什么的写完了,但是写得很乱
写一个RetainBestCache的数据结构,给定了getRank函可以直接用来得到当前cache的rank,然后有capacity的限制,当达到capacity的时候要拿出当前所存lowest rank的cache,跟新的cache比较,保留rank较高的那个
================================================
第二题:design a max stack that supports all regular stack operations and peekMax popMax in log time
让你设计一个MaxStack,要求实现以下功能。
class MaxStack {
int Pop(); // Pop the value on top of the stack;
void Push(int); // Push a new value into the stack;
int Peek(); // Return the value on top of the stack;
int PopMax(); // Pop the max value in the stack; logN
int PeekMax(); // Return the max value in the stack;logN
}
===============================================================
Build a tree given a list of relationship (parent -> child, 以及一个boolean isLeft)。
用一个hashmap做的。
LC1TwoSum----------------------------
LC12IntegerToRoman.
LC13RomanToInteger
LC20ValidParentheses----------------
LC21MergeTwoSortedLists. -------------------
LC33SearchRotatedSortedArray---------
LC34Search for a range-----------
LC46PermutationI-------------------
LC47PermutationII---------------
LC50Powerxn-----------
LC53MaximumSubarray-------------------
LC56MergeIntervals---------------------
LC65ValidNumber高频---------------------
LC69SqrtX------------
LC76Min Window SubString-------------------------
LC77Combinations----------------
LC81SearchRotatedSortedArrayII------------------------
LC88MergeSortedArray--------------
LC90SubSetsII---------------------
LC100SameTree--------------------
LC102BinaryTreeLevelOrderTraversal-------------
LC103ZigZag--------------
LC127WordLadder-------------------
LC126WordLadderII-----------------------
LC149MaxPointsInaLine---------
LC150EvaluateReversePolishNotation---------
LC151ReverseWordInAString------------------
LC152MaximumProductSubarray-----------------------
LC156BinaryTreeUpsideDown-------------------
LC160IntersectionTwoLinkedLists. & Union-------------------
LC170TwoSumIII-------------
LC173BinarySearchTreeIterator----------------
LC186ReverseWordsStringII-----------------
LC187RepeatedDNASequences-------------------
LC189RotateArray-------------
LC199BinaryTreeRightSideView----------
LC200 number of islands--------------
LC205IsomorphicStrings------------------
LC215KthLargestArray--------
LC235LowestCommonAncestorBinaryTree-------
LC236LowestCommonAncestorII-----------------
LC243ShortestWordDistance------------
LC244ShortestWordDistanceII----------
LC245ShortestWordDistanceIII-----------
LC254MyFactors----------------------
LC266PalindromePermutation-------------------
LC267------------------------
LC277FindCelebrity--------------
LC297Serilize & deserilize
LC339SumNestedList----------------
LC347TopKFrequentElements--------------
LC364 Nested SumII----------------
LC366PrintTreeLeaf-------------------
LC380InsertDeleteGetRandomI----------------
LC381InsertDeleteGetRandomII---------------
LC409LongestPalindrome------------------------------
LC534TinyURL------------------
LC605Can place flower-------------------------
BoundedBlockingQueue------------------------
GenericClass
LinkedListSingle2Double
MaximumDepth BT----------------------
实现一个hash table,get, put, 最后在加一个resize-----------------
============================================
MaximumIntervalsOverlap
Coding: Maximum number of overlapping intervals
For example – { (0,2), (3, 7), (4,6), (7,8), (1,5) }. The maximum number of intervals overlapped is 3 during (4,5).
===========================================
MultiSum
KNearestPoints2D
QuickSort
RightRotateTree
ThreeClosestElements
Triangle
TriangleII
convert bst to doubly linked list
binary tree to n-ary tree
maximum palindrome subarray
===================
题目: Given一个array of non-negative integers, 找出3组数字可以组成3角形, 每个数字表示边长, 组成3角形的充要条件就是任2边的和要大于第3边 答案: 对这个array做sorting后, 从array的最小的element开始往最大去扫, 以连续3个数字一组确认是否可以构成3角形
====================
一棵树有不限个数的子节点,有多层节点,不规则分布。给定子节点数K,重构这棵树。比如,子节点数是3。那么第一层是1个节点,第二层是3个节点,因为root最多有可以有三个节点。第三层是9个节点,因为第二层的三
===============================
2)retainBestCache,设计一个cache,他给你一个getRank()的方法,当cache满了的时候,要把rank最低的移除,开始以为是LRU Cache,结果发现不是,稍微有点慌,卡住了,说用arraylist来存,说完发现好蠢,每次移除都得O(n)来找rank最低的,然后他提示我还可以更高效,我一下子就想到了PriorityQueue,面完了发现确实该用PriorityQueue,可惜没完全写完,把comparator什么的写完了,但是写得很乱
写一个RetainBestCache的数据结构,给定了getRank函可以直接用来得到当前cache的rank,然后有capacity的限制,当达到capacity的时候要拿出当前所存lowest rank的cache,跟新的cache比较,保留rank较高的那个
================================================
第二题:design a max stack that supports all regular stack operations and peekMax popMax in log time
让你设计一个MaxStack,要求实现以下功能。
class MaxStack {
int Pop(); // Pop the value on top of the stack;
void Push(int); // Push a new value into the stack;
int Peek(); // Return the value on top of the stack;
int PopMax(); // Pop the max value in the stack; logN
int PeekMax(); // Return the max value in the stack;logN
}
===============================================================
Build a tree given a list of relationship (parent -> child, 以及一个boolean isLeft)。
用一个hashmap做的。
Wednesday, July 8, 2015
WAFL file system
http://www.slideshare.net/taotao1240/wafl-overview
Advfs
BMT: (block map table) BMT stores all inode blocks index
RBMT: reserved BMT
TAG dir: stores directory TAG
TAG ID | BMT ID | GEN | ..
Advfs like ext4, is also a extended fs, means use (offset, len) to directly locate data blocks,
don't need indirect blocks to locate.
Under ext3,
hardlink is just a new dentry which has the same inode
softlink is just a new dentry
For hardlinks, if file inode migrates, hardlink would become dangling denty.
The problem is hard to find all the hardlinks. But with TAG dir table,
all hardlink dentry share the same TAGID, then it won't have the same dangling dentry issue.
TAGID should be able to find BMT ID
Journaling
Replay journal: mostly use by File System
Rollback journal: used by database
Data journal: everything writes to journal including data blocks
Writeback?? journal: journal only commits after real data commits
... journal: journal doesn't ganranttee real data commits.
Donedone:
Snapshot:
Each snapshot has [birth, death]
death = -1 means still alive
snapshot chain, COW,
new -> .... -> old
All hard links to a physical file share the same inode, and have the same inode id number. Therefore, if you know the inode number of a file, you can find all hard links to the file by searching for files with the same inode number.
To display a file's inode number, use ls -i:
$ ls -li file1 2655341 -rw-r--r-- 3 peter peter 0 2008-09-02 19:09 file1
-xdev means don't search in other filesystem
$ find /home -xdev -inum 2655341 /home/peter/file1 /home/peter/tmp/file3 /home/peter/file2
Thursday, December 4, 2014
Convert and burn mp4/flv/avi to dvd
Converting/burning .mp4 or .flv to dvd
You can do it 'by hand' if you like. First convert the video, pal 16:9 in this case:
Code:
ffmpeg -i input.mp4 -target pal-dvd -aspect 16:9 -ac 2 output.mpg
Then create the dvd structure:
Code:
dvdauthor -t -o dvd --video=pal -f output.mpg
dvdauthor -T -o dvd
and finally create the iso and burn it:
Code:
mkisofs -dvd-video -o output.iso dvd/
growisofs -dvd-compat -Z /dev/sr0=output.iso
Saturday, November 15, 2014
How to find files with modify time in certain range
find . -newermt '2013-01-01' ! -newermt '2013-05-01' -print
Subscribe to:
Posts (Atom)