Wednesday, January 16, 2019

在温哥华办理美国签证攻略

在温哥华办理美国签证攻略

非移民签证常见类型

  • CNMI-only(仅限于美国北玛利安纳群岛) transitional worker(CW-1).
  • business visitor商务访问(B-1)
  • Exchange visitor交换访问(J)
  • Intra-company transferee公司内部穿梭(L)
  • Tourism, vacation, pleasure visitor旅游(B-2)

照片场景要求

  • Sized such that the head is between 1 inch and 1 3/8 inches (22 mm and 35 mm) or 50% and 69% of the image's total height from the bottom of the chin to the top of the head.
  • Taken in front of a plain white or off-white background

照片拍摄和处理要求


Dimensions The image dimensions must be in a square aspect ratio (the height must be equal to the width). Minimum acceptable dimensions are 600 x 600 pixels. Maximum acceptable dimensions are 1200 x 1200 pixels.
Color The image must be in color (24 bits per pixel) in sRGB color space which is the common output for most digital cameras.
File Format The image must be in JPEG file format
File Size The image must be less than or equal to 240 kB (kilobytes).
Compression The image may need to be compressed in order for it to be under the maximum file size. The compression ratio should be less than or equal to 20:1.

详细流程

  1. 浏览 领事电子申请中心 以申请非移民签证。
  2. ...

Friday, November 30, 2018

Understanding Events in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class TransactionEventArgs : EventArgs
{
    private int _transactionAmount;
    // "Credited": deposit
    // "Debited" : withdraw
    private string _transactionType;
    public TransactionEventArgs(int amt, string type)
    {
        this._transactionAmount = amt;
        this._transactionType = type;
    }
    public int TranactionAmount
    {
        get
        {
            return _transactionAmount;
        }
    }
    public string TranactionType
    {
        get
        {
            return _transactionType;
        }
    }
}

/*like:
public delegate void EventHandler(object sender, EventArgs e);

*/
public delegate void TransactionHandler(object sender, TransactionEventArgs e);
class Account
{
    //like:
    //public event EventHandler Click;
    //
    //the TransactionMade event and its TransactionHandler delegate(s)
    public event TransactionHandler TransactionMade; // Event Definition
    public int BalanceAmount;
    public Account(int amount)
    {
        this.BalanceAmount = amount;
    }
    //publisher invokes a event
    public void Debit(int debitAmount)
    {
        if (debitAmount < BalanceAmount)
        {
            BalanceAmount = BalanceAmount - debitAmount;
            TransactionEventArgs e = new TransactionEventArgs(debitAmount, "Debited");
            OnTransactionMade(e); // Debit transaction made
        }
    }

    public void Credit(int creditAmount)
    {
        BalanceAmount = BalanceAmount + creditAmount;
        TransactionEventArgs e = new TransactionEventArgs(creditAmount, "Credited");
        OnTransactionMade(e); // Credit transaction made
    }
    protected virtual void OnTransactionMade(TransactionEventArgs e)
    {
        if (TransactionMade != null)
        {
            TransactionMade(this, e); // Raise the event
        }
    }
}

class TestMyEvent
{
    private static void SendNotification(object sender, TransactionEventArgs e)
    {
        Console.WriteLine(
            "Your Account is {0} for ${1} ",
            e.TranactionType,
            e.TranactionAmount);
    }
    private static void Main()
    {
        Account MyAccount = new Account(10000);
        //like: this.button1.Click += new System.EventHandler(this.button1_Click);
        //
        //note: the += operator of event will subscribe the event append a delegate
        MyAccount.TransactionMade += new TransactionHandler(SendNotification);
        MyAccount.Credit(500);
        Console.WriteLine("Your Current Balance is : " + MyAccount.BalanceAmount);
        Console.ReadLine();
    }
}

Tuesday, July 3, 2018

_NT_SYMBOL_PATH and extra

_NT_SYMBOL_PATH cache*C:\Temp\Newfolder\_NT_SYMBOL_PATH;srv*https://msdl.microsoft.com/download/symbols

.sympath to view current setting

.sympath+ to add path:
.sympath+ C:\Chromium\debug_v8_02\v8\out.gn\ia32.debug\

// .srcpath C:\Chromium\debug_v8_02\v8\src

// bp d8_exe!main

db poi(poi(argv)+4)
00685050  43 3a 5c 43 68 72 6f 6d-69 75 6d 5c 64 65 62 75  C:\Chromium\debu
00685060  67 5f 76 38 5f 30 32 5c-69 6e 73 74 61 6e 63 65  g_v8_02\instance
00685070  30 31 5c 31 2e 6a 73 00-fd fd fd fd ab ab ab ab  01\1.js.........

Tuesday, June 19, 2018

build_and_debug_v8_on_windows

This artical refers to https://medium.com/dailyjs/how-to-build-v8-on-windows-and-not-go-mad-6347c69aacd4

Setting up environment

/*
VS2013 Requirements:
  • at least 8.5 GB disk space;If your windows has been updated to October 2013, you can delete some not used files in winsxs to free up disk space: apply "Clean up system files" button from windows disk cleanup utility(to run it with system adiminister, view its path through windows task mgr, then right click it and select run as admin).
  • for the express installer, select the installer for Windows Desktop instead of Windows(the later can be used to create windows store app).
  • To install vs2013 express, I make my win7 genenuine first by input the product key W4TGB-8HFJV-QB794-P6MDG-XWGF6 found in my disk packer and machine sticker
  • VS 2013 will use dnet 4.5.1 first, so better remove your old install(to check version of installed dnet, check HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP)
*/
VS2017 Requirements:
  • at least 30 GB disk space

Install git(if has no installation in your system)

From https://git-scm.com/downloads download and install git.

Install VS /*2015|*/2017(if has no installation in your system)

Depending on the system, may needing to install dnet 4.6 first.
Install VS(do not change default install path for VS), making sure the installer has installed Debug Interface Access (DIA) SDK(msdia*.dll), vcvarsall.bat, (and the Universal CRT?).

Install and config depot_tools

V8 uses part of a toolchain named depot_tools for Chromium project, Download depot_tools.zip and extract it(to C:\Chromium\depot_tools), then adds it to PATH. At the same time, add two new env var into your system:
DEPOT_TOOLS_WIN_TOOLCHAIN=0 //If you are a non-googler you need to set DEPOT_TOOLS_WIN_TOOLCHAIN=0
GYP_MSVS_VERSION=2017 //windows is not using GN but GYP for Ninja?
From a cmd.exe shell, run the command `gclient`, it will install all the bits needed to work with the code, including msysgit and python; After running gclient, open a new command prompt and type "where python" and confirm that python.bat comes ahead of python.exe (adjust PATH to let python.bat being searched first).

Install windows sdk

Windows sdk must be installed at default dir; and Debugging Tools For Windows must be selected(building v8 requires windows sdk, so if you only installed `Debugging Tools For Windows`, remove it)
After installing, windbg may be found at following locations:
C:\Program Files (ia32)\Windows Kits // C:\Program Files (x86)\Windows Kits
C:\Program Files (ia32)\Microsoft SDKs\Windows Kits

Building and use V8

Get source code

Go into the directory where you want to download the V8 source into and execute the following in your terminal/shell:
  • cd /d C:\Chromium\debug_v8_02
  • fetch v8
    Running: 'C:\depot_tools\win_tools-2_7_6_bin\python\bin\python.exe' 'C:\depot_tools\gclient.py' root
    Running: 'C:\depot_tools\win_tools-2_7_6_bin\python\bin\python.exe' 'C:\depot_tools\gclient.py' config --spec 'solutions = [
      {
        "url": "https://chromium.googlesource.com/v8/v8.git",
        "managed": False,
        "name": "v8",
        "deps_file": "DEPS",
        "custom_deps": {},
      },
    ]
    '
    C:\Chromium\depot_tools\win_tools-2_7_6_bin\python\bin\python.exe C:\Chromium\depot_tools\gclient.py sync --with_branch_heads
    ...

build debug_v8_02

prepare build file for ninja: cd /d C:\Chromium\debug_v8_02\v8 && python tools/dev/v8gen.py ia32.debug
modify config file C:\Chromium\debug_v8_02\v8\out.gn\ia32.debug\args.gn :
#ia32.debug x64.release ...
is_debug = true
target_cpu = "x86"
v8_enable_backtrace = true
v8_enable_slow_dchecks = true
v8_optimized_debug = false
" ninja -C out.gn/ia32.debug " and produce the product d8.
check if v8 works: C:\Chromium\debug_v8_02\v8\out.gn\ia32.debug\d8.exe C:\Chromium\debug_v8_02\instance01\1.js
debug d8:
  • windbg with C:\Chromium\debug_v8_02\v8\out.gn\ia32.debug\d8.exe C:\Chromium\debug_v8_02\instance01\1.js
  • set symbols: .sympath+ C:\Chromium\debug_v8_02\v8\out.gn\ia32.debug\
  • set srcpath: .srcpath C:\Chromium\debug_v8_02\v8\src
  • bp d8_exe!main
  • let windbg run and break
  • db poi(poi(argv))
    0068501c  43 3a 5c 43 68 72 6f 6d-69 75 6d 5c 64 65 62 75  C:\Chromium\debu
    0068502c  67 5f 76 38 5f 30 32 5c-76 38 5c 6f 75 74 2e 67  g_v8_02\v8\out.g
    0068503c  6e 5c 69 61 33 32 2e 64-65 62 75 67 5c 64 38 2e  n\ia32.debug\d8.
    
  • db poi(poi(argv)+4)
    00685050  43 3a 5c 43 68 72 6f 6d-69 75 6d 5c 64 65 62 75  C:\Chromium\debu
    00685060  67 5f 76 38 5f 30 32 5c-69 6e 73 74 61 6e 63 65  g_v8_02\instance
    00685070  30 31 5c 31 2e 6a 73 00-fd fd fd fd ab ab ab ab  01\1.js.........
    

















Friday, June 15, 2018

googletest

Locate GTEST_ROOT

after you (git) clone google test from master, your dir contains both google test and google mock. googletest is google's suggestion.

GTEST_ROOT may looks like ..\googletest-master\googletest

Locate gtest.sln or makefile to work on

googletest provides build files for some popular build systems: msvc/ for Visual Studio, xcode/ for Mac Xcode, make/ for GNU make, codegear/ for Borland C++ Builder, and the autotools script (deprecated) and CMakeLists.txt for CMake (recommended). In my case, it's under msvc\2010 .

test a project or build target

Created ConsoleApplication1 under the sln, its dir is msvc\ConsoleApplication1.

copy code for the target's int main() func form the project gtest_main.

config the tgt's runtime to "Multi-threaded Debug (/MTd)" //same as gtest

add dependency to gtest(note: in vs2017, add it from project properties menu), and add C:\Temp\Tasks\googletest\test2\googletest-master\googletest\msvc\2010\gtest\Win32-Debug as additional lib dir.

add testing code:

TEST(dummy_case, dummy_test)
{
 //use EXPECT_* when you want the test to continue to reveal more errors after the assertion failure,
 //and use ASSERT_* when continuing after failure doesn't make sense. 
 EXPECT_EQ(3, 3);
 ASSERT_EQ(3, 3);

}

For a c++ class tester

we can create c++ class tester(fixture) public on ::testing::Test; the fixture's tests can use TEST_F.

For each test defined with TEST_F(cls_name,test_name), Google Test will:

Create a fresh test fixture named cls_name at runtime
Immediately initialize it via SetUp()
Run the test
Clean up by calling TearDown()
Delete the test fixture. Note that different tests in the same test case have different test fixture objects, and Google Test always deletes a test fixture before it creates the next one.
Google Test does not reuse the same test fixture for multiple tests. Any changes one test makes to the fixture do not affect other tests.

further readings

https://github.com/google/googletest/blob/master/googletest/docs/primer.md

Tuesday, May 15, 2018

Windows_Protocols__2017_Dec_01_cfb

2 Structures

2.1 Compound File Sector Numbers and Types

Each sector, except for the header, is identified by a nonnegative, 32-bit sector number. The following sector numbers above 0xFFFFFFFA are reserved and MUST NOT be used to identify the location of a sector in a compound file.

Followings are definitions of SectIDs:

#define SID_MAXREG (0xfffffffa)

#define SID_FUTURE  ((SectID)(SID_MAXREG + 1))

#define SID_MSAT_SECTOR ((SectID)(SID_MAXREG + 2))

#define SID_SAT_SECTOR ((SectID)(SID_MAXREG + 3))

#define SID_END_OF_CHAIN    ((SectID)(SID_MAXREG + 4))

#define SID_UNUSED_SECTOR ((SectID)(SID_MAXREG + 5))

/*
[MS-CFB] or [MS-CFB] errata 2.9 Compound File Size Limits:
...4,096 bytes/sector x MAXREGSECT (0xFFFFFFFA) sectors...
so SID_MAXREG is also a special ID.
*/
#define SID_IS_SPECIAL(sid) ((SectID)(sid) >= SID_MAXREG)

The following list contains the types of sectors that are allowed in a compound file:

Header: A single sector with fields that are needed to read the other structures of the compound file.For version 4 compound files, the header size (512 bytes) is less than the sector size (4,096 bytes), so the remaining part of the header (3,584 bytes) MUST be filled with all zeroes. We can take head_size as equals with sect_size.

FAT: Sector Allocation Table(OpenOffice: SAT).

DIFAT: Used to locate FAT sectors in the compound file(OpenOffice: MSAT).

Mini FAT: FAT for short streams(OpenOffice: SSAT).

Directory:
User-defined Data:
Unallocated Free:

Range Lock:A single sector that is used to manage concurrent access to the compound file. This sector must cover file offset 0x7FFFFFFF(OpenOffice:Not used).

2.6 Compound File Directory Sectors

2.6.1 Compound File Directory Entry

The valid values for a stream ID, which are used in the Child ID, Right Sibling ID, and Left Sibling ID fields, are 0 through MAXREGSID (excluding).
Directory Entry Name (64 bytes):
storage and stream names are limited to 32 UTF-16 code points, including the terminating null character. When locating an object in the compound file except for the root storage, the directory entry name is compared by using a special case-insensitive uppercase mapping, described in Red-Black Tree. The following characters are illegal and MUST NOT be part of the name: '/', '\', ':', '!'.

Directory Entry Name Length (2 bytes):
This field MUST match the length of the Directory Entry Name Unicode string in bytes. The length MUST be a multiple of 2 and include the terminating null character in the count.
A secured parser shall not use this field.

Object Type (offset 66, 0x42): This field MUST be 0x00, 0x01, 0x02, or 0x05, depending on the actual type of object. All other values are not valid: 0 for Unknown or unallocated; 1 for Storage Object; 2 for Stream Object; 5 for Root Storage Object. 

Color Flag (offset 67, 0x43): This field MUST be 0x00 (red) or 0x01 (black). 

Left Sibling ID(offset 68, 0x44): This field contains the stream ID of the left sibling. If there is no left sibling, the field MUST be set to NOSTREAM (0xFFFFFFFF).

Right Sibling ID (offset 72, 0x48): 

Child ID (offset 76, 0x4C): This field contains the stream ID of a child object. If there is no child object, the field MUST be set to NOSTREAM (0xFFFFFFFF). 

CLSID (offset 80, 0x50): This field contains an object class GUID(can be used as a parameter to start applications.), if this entry is a storage or root storage. If no object class GUID is set on this object, the field MUST be set to all zeroes. 

State Bits (offset 96, 0x60): This field contains the user-defined flags if this entry is a storage object or root storage object. If no state bits are set on the object, this field MUST be set to all zeroes. 

Creation Time(8 bytes):Modified Time (8 bytes): 

Starting Sector Location (offset 116, 0x74): This field contains the first sector location if this is a stream object. For a root storage object, this field MUST contain the first sector of the mini stream, if the mini stream exists.

Stream Size (8 bytes): Streams whose size is less than the Cutoff value exist in the mini stream. Parsers must trust Stream Size to decide it's mini or standard stream,
while maintains a size telling the size figured out through sector chain of this stream.

2.6.4 Red-Black Tree

According rbtree, followings are true:
The root storage object MUST always be black. 
wo consecutive nodes MUST NOT both be red.(if one node is red, it's left/right must be black)
The left sibling MUST always be less than the right sibling. (root object has const name, its name don't compare; root object has no left and right)

This sorting relationship is defined as follows:

A node that has a shorter name is less than a node that has a longer name. 

For each UTF-16 code point, convert to uppercase by using the Unicode Default 
Case Conversion Algorithm

Wednesday, May 2, 2018

review_RRSP_deduction_of_TaxYear2014

How to check if your RRSP contributions deducted from your income? This article discuss it with example of tax year 2014.

As we know, RRSP deduction is MIN(deduction_limit, contributions_of_the_year), normally, deduction_limit is larger than contributions_of_the_year, so we simply query from 2014 Assessment's Schedule 7 at line 245 which is added from:

  • your PRPP contributions made from March 4, 2014, to December 31, 2014
  • your PRPP contributions made from January 1, 2015, to March 2, 2015

From 2014 Notice of Assessment, you will see `Deductions from total income` is the same as line 245. If you decide that `Deductions from total income` and line 245 happen to be the same. We can get back to 2014 Assessment's RRSP deduction at line 208 and recheck it.