0%

先从最基础的开始

3. Longest Substring Without Repeating Characters

这道题就是使用一个dict来维护字符出现的位置,一旦发现新字符出现在字典里并且start的位置<= 记录位置(就是连续同样字符保留最后一个) start更新为上个出现该字符的index+1,类似滑动窗口,一旦发现重复元素就去把上一次的元素位置+1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
dic = {}
res = 0
start = 0
for i in range(len(s)):
if s[i] in dic and start <= dic[s[i]]:
start = dic[s[i]] + 1
else:
res = max(res, i - start + 1)
dic[s[i]] = i
return res

159. Longest Substring with At Most Two Distinct Characters.

340. Longest Substring with At Most K Distinct Characters.

类似的思路,用字典来保存出现次数,用字典的长度维护K值

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
class Solution(object):
def lengthOfLongestSubstringTwoDistinct(self, s):
"""
:type s: str
:rtype: int
"""
char_dict = {}
start = 0
res = 0

for i in range(len(s)):
if s[i] not in char_dict:
char_dict[s[i]] = 1
else:
char_dict[s[i]] += 1

while len(char_dict)>2:
temp = s[start]
if char_dict[temp] > 1:
char_dict[temp] -= 1
else:
del(char_dict[temp])
start += 1
res = max(res, i -start + 1)
return res
Read more »


NOTE

搬运文章,原创作者:http://joshuablog.herokuapp.com/
Just for study purpose, I don’t hold the copyright, if this is affecting anyone, please let me know.


Time: 2017-05-23~05-25
Travel: Rental Car

北境

平潭清秀的阿卡迪亚是密西西比河以东第一个国家公园,没有黄石的奇幻与优胜美地的 俊俏,这里更像是百科全书:港口,沙滩,悬崖,海岛,灯塔,峡湾,山岭,湖泊–一切的户外活动几乎无所不能。平淡中展现的生活恰似远离了中国游客的旋绕。

Read more »

John Adams
US diplomat & politician (1735 - 1826)

I must study politics and war that my sons may have liberty to study mathematics and philosophy. My sons ought to study mathematics and philosophy, geography, natural history, naval architecture, navigation, commerce, and agriculture, in order to give their children a right to study painting, poetry, music, architecture, statuary, tapestry, and porcelain.


NOTE

搬运文章,原创作者:http://joshuablog.herokuapp.com/
Just for study purpose, I don’t hold the copyright, if this is affecting anyone, please let me know.


生产力工具

编程类

  1. Homebrew
    1
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. JetBrains系列(可以使用学生优惠)

Lesson 1: Find a problem, not a Solution

The first step to building something is determining what you are going to build. But this isn’t as simple as many may think. The idea you choose to pursue will account for a large part of the success or failure of your product.

Right this second, I want everyone to kill any idea they came into this program with. Why? Because starting with an idea is a huge red flag and despite what many people say - having an idea is not the first step.

The first thing that everyone must complete is to think of a problem. By starting with a problem and not a potential solution, you will be much less likely to build something that doesn’t really serve a purpose or that may solve a problem but that problem may be so minuscule that you have trouble getting people to convert.

Thinking of an idea comes later: when you know a problem that you are going to solve and when you know the reasons why that problem is a problem in the first place.

Your assignment for the next four days is simple, I want you to make a list of problems that you are passionate about solving. Use a Google Sheet with two columns, in the first list all of the problems you can think of that you are passionate about solving. In the second column rate each problem on a scale of 1(not that passionate) to 10 (the purpose of my life is to solve this problem).

That’s all for now. Feel free to share your list of problems with me, I would love to see what people are coming up with.

Read more »

部署

Hexo原生配置

1
2
3
4
$ npm install hexo-cli -g
$ hexo init blog
$ cd blog
$ npm install

Next主题

1
2
$ cd your-hexo-site
$ git clone https://github.com/iissnan/hexo-theme-next themes/next

More info: NexT

进阶配置

更新时间

本地搜索

More info: More

1
$ hexo g deploy -d

#Update Procedure
Change into blog directory with package.json file
run npm install hexo

run hexo version to check the version of Hexo.
Now succesfully updated to version 3.3.1 and hexo-cli to 1.0.2

Original Post from Yasser’s Page

Running Parallel Meep:

mpirun -np 16 meep-mpi splitter.ctl > splitter.out
; runs meep-mpi in 16 processors [input.ctl > output.out]

Running Serial Meep:

meep znonw_glass.ctl >& znonw_glass.out

Exporting Image with Epsilon Overlay

h5topng -S4 -Zc dkbluered -a gray:0.5 -A eps-000000.00.h5 ez*.h5
; scales 4 times used dkblured color scheme, places overlay gray with 50% opacity

Exporting 330 images:

h5topng -t 0:329 -R -Zc dkbluered -a yarg -A trans-eps-000000.00.h5 trans-ez.h5

Exporting 2D slices from 3D Structure

h5topng -S4 -0 -x 0 eps-000000.00.h5 ; yz plane
h5topng -S4 -0 -z 0 eps-000000.00.h5 ; xy plane

At every .6 outputs pngs

(run-until 200 (at-every 0.6 (output-png Ez “-Zc bluered”)))

Using grep to get flux data out

grep flux1: ito1_glass.out > ito1_glass.dat

Export vtk files

h5tovtk -t 150 -o test.vtk -d ey test-e.h5

Creating movie from bunch of .png files

mencoder mf://*.png -mf w=800:h=600:fps=4:type=png -ovc copy -oac copy -o output.avi
; you will need mencoder [sudo apt-get install mencoder]

Meep and python-meep on MacOS

This is a compilation procedure that worked for me to setup the python-meep with some utilities on a MacOS-based system.
Last update: 12/15/2016

Note

I created this recipe for a general guide line to install meep and python-meep on MacOS based system. Currently I installed on MacOS Sierra, and meep or meep-mpi does not working correctly, make check failed symmetry test which is failing due to a small numerical error (I guess this is fine). The error message that I have is posted as an issue in meep Github repo. It seems like due to guile library, please let me know if you have any suggestion, I would really appreciate.
This is the error message I have when running examples of meep scripts:

1
2
ERROR: In procedure memoize-variable-access!:
ERROR: Unbound variable: Ez

Python-meep seems working correctly with the given sample examples.

Please take your own resposibility when you follow this recipe.

I followed Glenn’s post on Meep-discuss and made some modification when necessery.

  1. First, install Xcode from the App Store and command line tools using the terminal:

    1
    xcode-select --install
  2. Next, install home-brew

    1
    2
    3
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    brew doctor
    brew update
  3. Install packages needed to build meep:

    1
    2
    3
    4
    5
    6
    7
    brew install guile
    brew install --with-mpi homebrew/science/hdf5
    brew install homebrew/science/openblas fftw h5utils
    brew install pkg-config
    brew install swig
    brew install automake
    brew install autoconf
  4. Log in as a user with admin privileges.

  5. Download harminv library from ab-initio: Unpack that, cd into harminv-1.4 and do the usual

    1
    2
    3
    ./configure
    make
    sudo make install
  6. Download libctl library from ab-initio: Unpack that, cd into libctl-3.2.2 and do the usual

    1
    2
    3
    ./configure
    make
    sudo make install
  7. Get meep from github:

    1
    git clone https://github.com/stevengj/meep
  8. In the cloned code (on 2/1/15), some files needed to be modified to get swig to work properly. Specifically, the cloned libctl/Makefile.am caused broken libctl/meep_swig_bug_workaround.i, libctl/meep_enum_renames.i and libctl/meep_renames.i to be created. To fix that I modified two lines in libctl/Makefile.am:

    1
    2
    3
    4
    5
    6
    7
    8
    the line after “meep_swig_bug_workaround.i: $(LIBHDRS)” was changed from
    -> (echo "// AUTOMATICALLY GENERATED -- DO NOT EDIT"; grep -h friend $(LIBHDRS) | sed 's/^ *friend \+[A-Za-z_0-9:<>]\+[* ]\+\([A-Za-z_0-9:]*\) *(.*$$/%ignore \1;/' | grep "%ignore" | sort -u;) > $@
    to
    -> (echo "// AUTOMATICALLY GENERATED -- DO NOT EDIT"; grep -h friend $(LIBHDRS) | sed 's/^ *friend *[[:alpha:]_][[:alnum:]_]* *\([[:alpha:]_][[:alnum:]_]*\) *(.*/%ignore \1;/' | grep "%ignore" | sort -u;) > $@
    the line after “meep_enum_renames.i: $(LIBHDRS)” was changed from
    -> (echo "// AUTOMATICALLY GENERATED -- DO NOT EDIT"; for f in $(LIBHDRS); do egrep "^enum" $$f | sed 's/enum \+\([A-Za-z_0-9:]\+\).*$$/\1/g' | while read enum; do cat $$f | tr -d '\n' | sed 's/.*enum \+'$${enum}' *{\([^}]*\)}.*/\1/g' | sed 's/= *[0-9]\+//g' |tr -d ' \t' | tr ',' '\n' | sed 's/^.*$$/'"%rename(meep_$${enum}_\0) meep::\0;/g"; echo; done; done;) > $@
    to
    -> (echo "// AUTOMATICALLY GENERATED -- DO NOT EDIT";for f in $(LIBHDRS); do egrep "^enum" $$f | sed 's/enum *\([^}][^}]*\).*};/\1/g' | tr -d "{" | sed 's/, */ /g' | sed 's/ *= *[[:digit:]][[:digit:]]*//g'| while read -a array; do varname=$${array[0]};unset "array[0]";for varvalue in $${array[@]};do echo "%rename(meep_$${varname}_$$varvalue) meep::$$varvalue;"; done;done;done;) > $@

    That resulted in good libctl/meep_swig_bug_workaround.i and libctl/meep_enum_renames.i when make was run, but to fix libctl/meep_renames.i, I punted and just copied that file over from a meep 1.2.1 distribution.

  9. For the instructions that follow, I used this guide as a guide and made modifications to get things to work on OS-X.

cd into meep and execute

1
2
3
4
5
export eFLAGS=" -fPIC"; export CXXFLAGS=" -fPIC"; export FFLAGS="-fPIC"
export CPPFLAGS="-I/usr/local/include"
export LD_RUN_PATH="/usr/local/lib"
./autogen.sh --with-mpi --enable-maintainer-mode --enable-shared --prefix=/usr/local
make && sudo make install
  1. That should take care of the basic meep, but I find it much more convenient to deal with Python than Scheme, so I installed python-meep, which started with a download.The resulting files seemed to require some modification to install in /usr/local directories and to work properly:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    			in setup-mpi.py inserted after line 9: import numpy as np
    in setup-mpi.py changed the last line to:
    include_dirs=includeDir+[np.get_include()]
    in setup-mpi.py changed line 16 to: includeDir = ["/usr/local/include”]
    in setup-mpi.py changed line 17 to: includeDir = ["/usr/local/lib”]
    in make-mpi inserted after line 5: export LD_RUN_PATH=/usr/local/lib
    in meep_mpi.py changed line 4918 to: libmpi = CDLL('libmpi.0.dylib’,
    RTLD_GLOBAL)
    in meep_mpi.py changed line 4921 to: libmpi = CDLL('libmpi.dylib’,
    RTLD_GLOBAL)
    in meep-site-init.py replaced the # in the first line with //

    With those modifications, the installation can proceed:
    cd to python-meep directory
    as a user with admin privileges execute: sudo ./make-mpi -I/usr/local/include -L/usr/local/lib
  2. I find out that python-meep cant read the right libmpi library for file
    meep-mpi.py that generated.
    In order to fix this, you need to modify the /usr/local/bin/meep-mpi.py
    from
    1
    2
    3
    4
    5
    6
    7
    8
    try:
    libmpi = CDLL('libmpi.so.0', RTLD_GLOBAL)
    except:
    try:
    libmpi = CDLL('libmpi.so', RTLD_GLOBAL)
    except Exception,e:
    print "Neither libmpi.so.0 nor libmpi.so found. Fatal error."
    raise e
    to
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    import sys
    if sys.platform == 'darwin': # works on OSX
    try:
    libmpi = CDLL('libmpi.0.dylib', RTLD_GLOBAL)
    except:
    try:
    libmpi = CDLL('libmpi.dylib', RTLD_GLOBAL)
    except Exception,e:
    print "Neither libmpi.0.dylib nor libmpi.dylib found. Fatal error."
    raise e
    else:
    try:
    libmpi = CDLL('libmpi.so.0', RTLD_GLOBAL)
    except:
    try:
    libmpi = CDLL('libmpi.so', RTLD_GLOBAL)
    except Exception,e:
    print "Neither libmpi.so.0 nor libmpi.so found. Fatal error."
    raise e
  3. If no errors or omissions have slipped by me, that should get python-meep running on OS-X.

Vimtex Default Mappings

Vimtex is designed to be controlled by a selection of mappings. Note,
though, that most of the mappings are also available as commands.
[comment]: # (Add link to Vimtex commands)

Many of the mappings utilize the maplocalleader. The right-hand sides are
provided as plug mappings. For any given
<plug> map, the default mapping will only be created if it does not already
exist.
This means that if a user defines a custom mapping, e.g. with
viml nmap <space>li <plug>(vimtex-info)
then the corresponding default left-hand side will not be mapped.

If one prefers, one may disable all default mappings through the option
g:vimtex_mappings_enabled. One must then define custom mappings for all
desired features through the listed RHS <plug> maps or by mapping the
available commands.

In the below list of mappings, LHS is the default mapping, RHS is the
corresponding <plug> maps, and MODE indicates in which vim mode the
mappings
are valid.

LHS        |                   RHS                   | MODE
----------------- | --------------------------------------- | ----
`<localleader>li` | `<plug>(vimtex-info)`                   | n
`<localleader>lI` | `<plug>(vimtex-info-full)`              | n
`<localleader>lt` | `<plug>(vimtex-toc-open)`               | n
`<localleader>lT` | `<plug>(vimtex-toc-toggle)`             | n
`<localleader>ly` | `<plug>(vimtex-labels-open)`            | n
`<localleader>lY` | `<plug>(vimtex-labels-toggle)`          | n
`<localleader>lv` | `<plug>(vimtex-view)`                   | n
`<localleader>lr` | `<plug>(vimtex-reverse-search)`         | n
`<localleader>ll` | `<plug>(vimtex-compile-toggle)`         | n
`<localleader>lk` | `<plug>(vimtex-stop)`                   | n
`<localleader>lK` | `<plug>(vimtex-stop-all)`               | n
`<localleader>le` | `<plug>(vimtex-errors)`                 | n
`<localleader>lo` | `<plug>(vimtex-compile-output)`         | n
`<localleader>lg` | `<plug>(vimtex-status)`                 | n
`<localleader>lG` | `<plug>(vimtex-status-all)`             | n
`<localleader>lc` | `<plug>(vimtex-clean)`                  | n
`<localleader>lC` | `<plug>(vimtex-clean-full)`             | n
`<localleader>lm` | `<plug>(vimtex-imaps-list)`             | n
`<localleader>lx` | `<plug>(vimtex-reload)`                 | n
`<localleader>ls` | `<plug>(vimtex-toggle-main)`            | n
`dse`             | `<plug>(vimtex-env-delete)`             | n
`dsc`             | `<plug>(vimtex-cmd-delete)`             | n
`ds$`             | `<plug>(vimtex-env-delete-math)`        | n
`cse`             | `<plug>(vimtex-env-change)`             | n
`csc`             | `<plug>(vimtex-cmd-change)`             | n
`cs$`             | `<plug>(vimtex-cmd-change-math)`        | n
`tse`             | `<plug>(vimtex-env-toggle-star)`        | n
`tsd`             | `<plug>(vimtex-delim-toggle-modifier)`  | nx
`<F7>`            | `<plug>(vimtex-cmd-create)`             | ni
`]]`              | `<plug>(vimtex-delim-close)`            | i
`ac`              | `<plug>(vimtex-ac)`                     | nxo
`ic`              | `<plug>(vimtex-ic)`                     | nxo
`ad`              | `<plug>(vimtex-ad)`                     | nxo
`id`              | `<plug>(vimtex-id)`                     | nxo
`ae`              | `<plug>(vimtex-ae)`                     | nxo
`ie`              | `<plug>(vimtex-ie)`                     | nxo
`a$`              | `<plug>(vimtex-a$)`                     | nxo
`i$`              | `<plug>(vimtex-i$)`                     | nxo
`%`               | `<plug>(vimtex-%)`                      | nxo
`]]`              | `<plug>(vimtex-]])`                     | nxo
`][`              | `<plug>(vimtex-][)`                     | nxo
`[]`              | `<plug>(vimtex-[])`                     | nxo
`[[`              | `<plug>(vimtex-[[)`                     | nxo `]])` `]]])` `]`

`