Sam's Chest of Drawers

Thinking about Programming and Lifestyle


  • Home

  • Categories

  • Archives

  • Tags

ES2015

Posted on 02-27-2017 | In Programming

A better length method for unicode text

1
2
3
4
function codePointLen(text) {
let result = text.match(/[\s\S]/gu);
return result ? result.length : 0;
}

Default param

A trivial version

1
2
3
4
function getID(name, defaultValue) {
defaultValue = defaultValue || 1000;
// ...
}

The problem is defaultValue would be ignored with falsy value like 0. As a result, a more decent version before ES2015 is

1
2
3
4
function getID(name, defaultValue) {
defaultValue = (typeof defaultValue !== "undefined") ? defaultValue : 0;
// ...
}

In ES2015, it can be simplified as

1
2
3
function getID(name, defaultValue=1000) {
// ...
}

Read more »

Hello Hexo (Migration to hexo)

Posted on 02-14-2017

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

PPT with HTML

Posted on 02-13-2017 | In Tool

How to set up

Download the bundle from webslides

Sample can be found in index.html.

Here is a simple page for title:

1
2
3
4
5
6
<section>
<div class="wrap aligncenter">
<h1><strong>Title</strong></h1>
<p class="text-intro">Subtitle <br> some introduction to the topic</p>
</div>
</section>

A contents page:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<section>
<div class="wrap">
<h2>Contents</h2>
<ul class="flexblock features">
<li>
<div>
<h2>Section 1</h2>
Section 1 details
</div>
</li>
<li>
<div>
<h2>Section 1</h2>
Section 1 details
</div>
</li>
</ul>
</div>
</section>

A page with points:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<section>
<div class="wrap size-50 aligncenter">
<h2><strong>Section with points</strong></h2>
<p class="text-intro">Section 1 introduction</p>
<div class="bg-white shadow">
<ul class="flexblock reasons">
<li>
<h2>Point 1</h2>
<p>Point 1 reason</p>
</li>
<li>
<h2>Point 2</h2>
<p>Point 2 reason</p>
</li>
<!-- It's better not to put too many points on one slide, especially for the demo on small screen devices -->
</ul>
</div>
<!-- .end .bg-white shadow -->
</div>
</section>

A page with two columns:

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
<section>
<!--.wrap = container 1200px -->
<div class="wrap">
<div class="grid vertical-align">

<div class="column">
<h3><strong>Section in two columns</strong></h3>
<p class="text-intro">Put source code <code>System.out.println("Hello world");</code> in the middle of text with <strong>strong</strong> effect.</p>
</div>
<!-- .end .column -->

<div class="column">
<!-- remove the leading space for source code to get a better format -->
<pre>
let greeting = n => `Hello, ${n}`;
let print = console.log;
print(greeting("Sam"));
</pre>
</div>
<!-- .end .column -->

</div>
<!-- .end .grid -->

</div>
<!-- .end .wrap -->

</section>

A last-word page:

1
2
3
4
5
6
7
8
9
10
11
12
<section class="slide-bottom">
<div class="wrap">
<div class="content-right text-serif">
<h2><strong>One more thing</strong></h2>
<p>
I still have something to say ...
</p>
</div>
<!-- .end .content-right -->
</div>
<!-- .end .wrap -->
</section>

Hexo - How to publish site on Github

Posted on 01-09-2017 | In Tool

It’s a tool that supports generating static HTML from Markdown, which makes it suitable to publish personal blog on website (e.g. github-pages).

Installation

1
npm install -g hexo-cli

Issue of cannot-find-module-DTraceProviderBindings

After playing a hexo project for some time, I happened to try a yarn install, which may update some underlying dependencies. Then I found hexo didn’t work anymore. The complain is:

1
Cannot find module './build/Release/DTraceProviderBindings

I tried:

  • npm i hexo. No use.
  • rm -rfd node_modules && npm i. No use.
  • npm i hexo --no-optional. It works for me.
  • npm uninstall hexo-cli -g && npm i hexo-cli -g. It should work but I haven’t tried it.

Workflow

1
2
3
4
5
6
hexo init <folder>
cd <folder>
hexo clean
hexo n "Title"
hexo g[enerate]
hexo s[erver]

Deploy to github-pages

It’s better to create a repo (on github) for the hexo project itself and another repo for the generated HTML files so that we can add contents even on different machines.

1
2
3
npm install --save hexo-deployer-git
// add repo, branch setting to config file
hexo d[eploy]

Theme

There is a dedicate topic on Hexo at Zhihu.com
A good starting point is Next

How to generate category and tag pages (in Next theme)

By default, even enable these two in menu section of the theme config file, you will still get 404 error when nevigating to “categories” or “tags” pages. The reason is due to the missing index.html under the folder of the above two names. The fix is to add pages with hexo new page categories and hexo new page index. Then modify the generated index.md to:

1
2
3
4
5
6
7
// index.md for categories
type: "categories"
comments: false

// index.md for tags
type: "tags"
comments: false

Code First in Entity framework

Posted on 06-09-2016 | In Programming

Why choose code first

There are three major advantages to use code first:

  1. Less configuration (no mapping file, no design model, no need to create table first)
  2. Easier to write code (no need to build complicated model or query)
  3. With some extra configuration, the generated/target database can be adapted to DBA’s requirements. At least, the difficulty is less than the opposite way.

Configure the correct connection string in DbContext

1
public EFSampleContext() : base(@"Data Source=(LocalDB)\MSSQLLocalDB; AttachDbFilename=the-path-to-local-mdf; MultipleActiveResultSets=true; Integrated Security = True; Connect Timeout = 30")

Please note that MultipleActiveResultSets by default is false, making it impossible to use DbReader nested inside loop

Read more »

Git & Github Basic

Posted on 06-01-2016 | In Tool

Git

  • reference http://www.jianshu.com/p/6d1ce5b65523 and http://learngitbranching.js.org/?demo
  • Install http://cmder.net/ (including MsysGit)
  • Config
    1
    2
    3
    4
    5
    6
    7
    git config --global user.name "xxx" 
    git config --global user.email "xxx@yyy"
    git config --global alias.st status
    git config --global alias.co checkout
    git config --global alias.ci commit
    git config --global alias.br branch
    git config --list //~\.gitconfig

Check in

1
2
3
4
5
git init
git status
git add .
git commit -m "xxx"
git commit -a -m "xxx" // without git add

Revert

1
2
3
4
git reflog //review commit id for revert
git reset --hard xxx //commit id or HEAD^ (the next version), HEAD^^ (the next next version)
git checkout -- filename //revert when there is no local change **added**
git reset HEAD filename && git checkout -- filename //revert **added** change, then revert local change

Change

1
2
3
4
git rm xxx
git rm --cache xxx // remove tracked file, but keep it locally
git rm -f xxx // remove file physically.
git mv xxx yyy

Branch

1
2
3
git checkout -b xxx // git branch xxx && git checkout xxx
git merge xxx
git branch -d xxx //delete branch

gitignore when it doesn’t work:

1
2
3
git rm -r --cached .
git add .
git commit -m 'update .gitignore'

Github

Generate SSH key

1
2
ssh-keygen -t rsa -C"mail" //id_rsa and id_rsa.pub
ssh -T github.com

.ssh/config

1
2
3
4
5
6
Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

Upload

1
2
3
4
git remote add origin git@github.com:sevenbamboos/test.git
git push --set-upstream origin master
git push origin master
git pull origin master

Merge

1
git mergetool

What I Learned From Workplace Part 2

Posted on 03-13-2016 | In Lifestyle

Catch up with the trend

I have advanced knowledge in both connectivity of healthcare systems and web-based technology.

In 2014, I designed a processor for HL7 messages (in Java). The next generation of HL7 standard (FHIR), is a RESTful protocol using JSON format to transfer messages. To make better use of the new protocol, it is better to use the architecture of full-stack Javascript. That is to use a NodeJS sever as the connectivity module to handle FHIR requests and to use NodeJS client to do integration test. In this way, we can unify the data format as JSON on both server side and client side and save the time of converting data back and forth between two sides. I work with my colleagues on this new architecture and I contribute part of my work, a HL7 message parser written in pure Javascript, to Github and publish it in Node Package Manager (NPM) under the name “sam-utility”. The new architecture can simplify the structure of connectivity module and most providers of radiology information system can benefit from it.

Read more »

What I Learned From Workplace Part 1

Posted on 02-03-2016 | In Lifestyle

Technical practice and its limits

In general maturity and cost can influence a technology’s acceptance and popularity. After 2001, I took part in several projects and most of them were built on Java Enterprise Edition (JavaEE), a popular platform for enterprise applications. One reason of this trend was that a large number of developers were creating open-source software with Java technology, which has the following advantage over proprietary software: no license fee, vendor-free and good code quality. Another reason is that there were plenty of Java programmers available at the market. A similar trend happened after 2010, when more companies (including my company) are switching their platform to web-based technologies. The trend started with standardisation of web browser and the popularity of mobile devices.

Read more »

What I Learned From Workspace Part 0

Posted on 01-14-2016 | In Lifestyle

Research and analyse in design

Before designing a software system, I will do use case analysis first, which helps me understand how the system interacts with external resource. Sometimes, a clear user case diagram also serves as a good communication with non-technical participants. Besides, performance specification also needs to be taken into consideration either with pseudo-code or prototype. In the passed 10 years as a senior software developer, I participated in the requirement analysis of enterprise applications in multiple domains ranging from manufacturing (2001), auction (2002-2006), entertainment (2006-2009) to healthcare.

Read more »

What I Learned From School Part 3

Posted on 12-19-2015 | In Lifestyle

Knowledge to support practice

I chose software as my research direction from the third year of university under the influence of “data structure” course.

As what the name suggests, the course helped me understand two basic elements of a program: data structure and algorithms, and their relationship.

The order of growth (𝛩-notation) is the most fundamental concept to help understand why various data structures and algorithms are designed. For instance, most programming languages provide support for array or list, which stores data in a sequence of blocks of memory. The expectation of the time to look for an item in an array is 𝛩(n). It is an efficient data structure for cases that the number of the items are small. But there are exceptions.

Read more »
1…345
Yuping Wang

Yuping Wang

85608565

43 posts
5 categories
30 tags
Github Twitter
© 2016 - 2020 Yuping Wang
Powered by Hexo
Theme - NexT.Muse