分類彙整: 未分類

Xcode 12 Build Errors

Error Message: building for iOS Simulator, but linking in XXX built for iOS, architecture arm64

If you are not using Apple Silicon processor, the reason is that Xcode 12 does not allow build arm64 architecture for Simulator. We should set x86_64 for Simulator building by excluding arm64 via Build Settings -> Excluded Architectures:

Recompile the project again.

If you are using Apple Silicon processor, EXCLUDED_ARCHS for arm64 on the simulator means that people with Apple Silicon macs won't be able to use your framework. Therefore, don't do that. Check the warning messages for your target to identify other conflicts.

Cannot find VALID_ARCHS?

Forget about it. The Build Settings editor no longer includes the Valid Architectures build setting (VALID_ARCHS), and its use is discouraged. Instead, there is a new Excluded Architectures build setting (EXCLUDED_ARCHS). If a project includes VALID_ARCHS, the setting is displayed in the User-Defined section of the Build Settings editor.

Two libraries have the same architectures and in the same fat output file?

fatal error: lipo: /Users/pacowong/Library/Developer/Xcode/DerivedData/Demo-iOS-gxavdlvyqcmylawrmtuqoebcsva/Build/Products/Debug-iphoneos/libSVGKit-iOS.2.1.0.a and /Users/pacowong/Library/Developer/Xcode/DerivedData/Demo-iOS-gxavdlgvyqcmylawrmtuqoebcsva/Build/Products/Debug-iphonesimulator/libSVGKit-iOS.2.1.0.a have the same architectures (arm64) and can't be in the same fat output file

To resolve the conflict in Xcode, go to Build Settings -> Excluded Architectures, set set the following:

If you only have a .a or .framework file, you need to use lipo remove to remove the library that uses arm64 architecture. This can be done using the following command:

$ lipo XXX.a -remove arm64 -output XXX.a

Still does not work?

You need to set it for ALL targets. You can find the targets in Issue Navigator (but not in Project navigator, which is quite weird). You need to modify excluded architectures accordingly.

References:

[1] https://stackoverflow.com/questions/63993084/problems-after-upgrading-to-xcode-12ld-building-for-ios-simulator-but-linking

[2] https://stackoverflow.com/questions/64123206/xcode-12-problems-build-input-file-cannot-be-found-building-for-release-on

[3] https://stackoverflow.com/questions/63259053/xcode-12-beta-valid-architectures-missing-in-build-settings

[4] https://blog.csdn.net/huawt520/article/details/109305833

GitLab: Feature Branch Workflow

Make Your Feature Branch

  1. Clone project:
    • git clone git@example.com:your-project.git
  2. Create a new branch with your feature:
    • git checkout -b new-feature-branch
  3. Create a file:
    • touch test.py
  4. Update the index using the current content found in the working tree, to prepare the content staged for the next commit:
    • git add test.py
  5. Record changes to the repository:
    • git commit -m "Make some updates on test.py"
  6. Push the branch to GitLab as explained in [2]:
    • git push -u origin new-feature-branch
  7. Find the merge request URL in the prompt:
    • remote: http://gitlab-server/your-username/your-repo-name/merge_requests/...
  8. Open the merge request URL using a web browser

What can you do on the merge request page?

https://docs.gitlab.com/ee/user/project/merge_requests/getting_started.html

Two useful features for beginners:

References

[1] https://docs.gitlab.com/ee/gitlab-basics/feature_branch_workflow.html
[2] https://stackoverflow.com/questions/17096311/why-do-i-need-to-explicitly-push-a-new-branch/17096880#17096880

Some Abbreviations

a.k.a.: also known as

a.s.a.p: as soon as possible

ca.: about

cf.: compare

et. al.: and others

f.: and the following page

ff.: and the following pages

ibid.: in the same place

i.e.: that is

loc. cit.: in the place cited

N.B.: take notice

p.s.: post script

pro tem: temporarily

viz: namely; as follows

vs.: versus; as against

de novo: from the beginning

ad hoc: a solution designed for a specific problem or task

in situ: locally; on site; on the premises

per se: through itself

 

https://en.wikipedia.org/wiki/List_of_Latin_phrases

 

Tableless Layout

[1] http://www.w3.org/2002/03/csslayout-howto

[2] http://en.wikipedia.org/wiki/Tableless_web_design

[3] http://www.ilovecolors.com.ar/detect-screen-size-css-style/

What is tableless layout?

It is a web design philosophy to avoid the use of HTML tables for page layout control purposes [2]. CSS will be responsible for the design of the layout.

Motivation [2]

Table is not flexible. The position and style of the content cannot be easily maintained. A lot of nested <tr>, <td> and <th> tags will also be used to built the layout, which is inconvenient, and waste bandwidth. With CSS, you can do that by specifying the positions.

Search engine Web crawler does not know whether your table is used as a layout control or storing relevant contents, e.g. the price table. This gives inaccurate search results.

As many devices of different screen size may visit your web site, it is possible  to specifu a different style sheet to hide and show different elements on the pages for better user experience across different screen size.

How to implement tableless layout?

There are multiple ways to implement tableless layout.

Method 1: Absolute layout [1]

1. Divide a HTML pages with divisions, each with a unique ID. For example,

<div id="login" class="side_module">, <div id="content">, <div id="search" class="side_module">

2. Apply the CSS on these divisions

/* Properties that both side lists have in common */
div.side_module {
width:10.2em;
position:absolute;
top:0;
font-size:80%;
padding-left:1%;
padding-right:1%;
margin-left:0;
margin-right:0;
}
/* we leave some place on the side using the margin-* properties */
#content{
margin-left:10.2em;
margin-right:10.2em;
padding-left:1em;
padding-right:1em;
}
/* and then we put each list on its place */
#login{
left:0;
}
#search{
right:0;
}

Method 2: Relative layout

The advantage of this method is that the browser can adjust the position for you.

A few words

If you want to adjust the page layout for different screen size, you may use JavaScript to detect and load the stylesheet correspondingly.

//Code from [3]

$(document).ready(function() {
if ((screen.width>=1024) && (screen.height>=768)) {
alert('Screen size: 1024x768 or larger');
$("link[rel=stylesheet]:not(:first)").attr({href : "detect1024.css"});
}else {
alert('Screen size: less than 1024x768, assume it is 800x600');
$("link[rel=stylesheet]:not(:first)").attr({href : "detect800.css"});
}
});

 

 

Virtual Memory

Adopt from

[1]Java NIO, written by Ron Hitchens, published by O'Reilly


What is Virtual Memory?

"All modern operating systems make use of virtual memory. It means that artficial addresses are used in place of physical(hardware RAM) memory addresses."[1]

What are the advantages of using virtual memory?

1. Provide larger memory space

The idea is to use the harddisk to store the data in RAM. Memory paging is necessary. This is a scheme whereby the pages of a virtual memory space can be persisted to external disk storage to make room in physical memory for other virtual pages. Essentially, physical memory acts as a cache for a paging area, which is the space on disk where the content of memory pages is stored when forced out of physical memory. Aligning memory page sizes as multiples of the disk block size allows the kernel to issue direct commands to the disk controller hardware to write memory pages to disk or reload them when needed. It turns out that all disk I/O is done at the page level in paged operating systems. (Modern CPUs contain a subsystem known as the Memory Management Unit(Wikipedia), which contains the mapping information needed to translate virtual addresses to physical memory addresses.)

2. Reuse or share physical memory location

It is because more than one virtual address can refer to the same physical memory location. Due to the fact that all I/O flows through kernel space, all data (from/to) I/O device must be stored in a buffer B of kernel space first before copying to/from the buffer B' of a process in user space. With virtual memory, the addresses of B and B' are different virtual memory addresses V and V' respectively, but the V and V' both refer to the same physical memory location. Hence, no buffered data copy is needed between kernel space and user space which can save a lot of time.

OS - Paging

Adopt from

http://en.wikipedia.org/wiki/Paging

http://en.wikipedia.org/wiki/Intel_x86


In computer operating systems, paging is one of the memory-management schemes by which a computer can store and retrieve data from secondary storage for use in main memory. In the paging memory-management scheme, the operating system retrieves data from secondary storage in same-size blocks called pages. The main advantage of paging is that it allows the physical address space of a process to be noncontiguous. Before the time paging was used, systems had to fit whole programs into storage contiguously, which caused various storage and fragmentation problems.[1]

Paging is used extensively by modern multitasking operating systems. Linux, 386BSD and Windows NT were developed for the 386 because it was the first Intel architecture CPU to support paging and 32-bit segment offsets. The 386 architecture became the basis of all further development in the x86 series.

Computer Security–Comparisons - 1

Compare Password with Fingerprint Authentication

Password authentication uses “a secret only you know” while fingerprint authentication uses “who you are”, i.e. biometric schemes, to authenticate your identity.

Besides, when the system checks your password, it will give you a binary decision only. However, in fingerprint authentication, the authentication is based on the similarity between the stored template and the user input. False positive and false negative are possible in fingerprint authentication.

Moreover, fingerprint is something you cannot change while password can be changed very frequently.

Fingerprint is also unique for every user while password can be the same for different users.

Fingerprint, unlike the password, can be found everywhere, which is not a secret.

Compare block cipher with stream cipher

Block cipher process the message block by block. Each block goes through multiple rounds of permutation and substitution. It has a complex key scheduling.

Stream cipher processes the message bit by bit/byte by byte. Typically have a (pseudo) random stream key.

Compare the difference when computing MAC to provide message authentication using conventional encryption with hash function.

When using conventional encryption, only sender and receivers share the keys. A nonce should be included to prevent replay attack. Some message structures should be imposed to identify the garbage.

MAC can be computed using a one way hash function and it is appended at the end of the message.

Using hash function is faster than using encryption. It is also cheaper in terms of hardware cost. It will not subject to US export control and be covered by patents.

Compare MD5 with HMAC-MD5.

MD5 is a hash algorithm processes input as 512-bit blocks and generate a 128bits hash code. HMAC-MD5 is MAC derived from a cryptographic hash codes. It uses MD5 in generating the digest from a secure key and the message. It is more secure than MD5.

Generalization of Pythagorean Theorem

Adopt from

http://en.wikipedia.org/wiki/Law_of_cosines


In trigonometry, the law of cosines (also known as the cosine formula or cosine rule) is a statement about a general triangle that relates the lengths of its sides to the cosine of one of its angles. Using notation as in Fig. 1, the law of cosines states that

c^2 = a^2 + b^2 - 2ab\cos\gamma\ ,

where γ denotes the angle contained between sides of lengths a and b and opposite the side of length c.

The law of cosines generalizes the Pythagorean theorem, which holds only for right triangles: if the angle γ is a right angle (of measure 90° or π/2 radians), then cos(γ) = 0, and thus the law of cosines reduces to

c^2 = a^2 + b^2 \,

Real-time operating system–Simple Description

Adopt from

[1]http://en.wikipedia.org/wiki/Real-time_operating_systems

[2]http://web.mit.edu/16.070/www/year2001/RTOS27.pdf


What is an operating system (OS)?

It is an organized collection of software extensions of hardware that serve as:

  • control routines for operating a computer (for example, to gain access to computer resources)
  • an environment for execution of programs (for example, to use notepad in Windows or Linux)

OS also manages computer system resources (RAM, Camera, Processor, Graphic Card …) and the programs that want to use the resources. OS usually provides a user interface for users to control the OS.[2]

What is Real-time operating system (RTOS)?

RTOS is an operating system intended for real-time application.[1] In most of the case, RTOS is the same as the OS kernel. You can control over timing by allowing manipulation of task priorities and choice of scheduling options.[2]