## 6. ZigZag Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

And then read line by line: "PAHNAPLSIIGYIR"

Write the code that will take a string and make this conversion given a number of rows:

string convert(string s, int numRows);

## 5. Longest Palindromic Substring

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

Example 1:

Output: "bab"
Note: "aba" is also a valid answer.
Example 2:

Input: "cbbd"
Output: "bb"

## 4. Median of Two Sorted Arrays

There are two sorted arrays nums1 and nums2 of size m and n respectively.

Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).

You may assume nums1 and nums2 cannot be both empty.

Example 1:

nums1 = [1, 3]
nums2 = [2]

The median is 2.0
Example 2:

nums1 = [1, 2]
nums2 = [3, 4]

The median is (2 + 3)/2 = 2.5

## 3. Longest Substring Without Repeating

Given a string, find the length of the longest substring without repeating characters.

Example 1:

Input: "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:

Input: "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
Example 3:

Input: "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Note that the answer must be a substring, "pwke" is a subsequence and not a substring.

## Getting started with eBay API Tokens (Oauth) with PHP

Official Guide: http://developer.ebay.com/devzone/rest/ebay-rest/content/oauth-gen-user-token.html

I’ll also cover some mistakes I made.

1.  Signup at https://developer.ebay.com
2. Create an App and get the App ID (Client ID) and Cert ID (Client Secret)
3. Click ‘User Tokens‘ (either from sandbox or production, depend on you)
4. Click “Get a Token from eBay via Your Application” then “Add eBay Redirect URL
5. Fill in the form, the only important thing is the “Your auth accepted URL“, it should be under your domain. (You should able to extract the auth code from the call back later, for example \$_GET[‘code’] in PHP),  let’s assume this  https://yourdomain.com/accept.php
6. Take down the value of “RuName (eBay Redirect URL name)” and “Your branded eBay Production Sign In (OAuth)

So far, we’ve done our preparation at developer.ebay.com

Then, on you local developing environment or you production server,:

1. Set user login you own website
3. visitor click on that link, and login with their ebay account.
4. ebay will make a callback redirect to “Your auth accepted URL” if success.

On the “Your auth accepted URL“, prepare a PHP script that get the value of \$_GET[‘code’] and save it in sessions. It starts with ‘v%5E1’. this is called “Authorization Code

Craft a HTTP Request with whatever you like with PHP.

Content-Type = application/x-www-form-urlencoded
Authorization = Basic <B64-encoded-oauth-credentials>

HTTP method: POST

URL: https://api.sandbox.ebay.com/identity/v1/oauth2/token

grant_type=authorization_code&
code=<authorization-code-value>&
redirect_uri=<redirect_URI>

We have three ‘Variables’ here.

<B64-encoded-oauth-credentials>: Use a Chrome Browser, Right click, Inspect, Console
Then type: btoa(‘APP_ID:CERT_ID‘);
We did take down these two values earlier. and there is a : between.
Hit ENTER, the value inside the double quotes is <B64-encoded-oauth-credentials>

<authorization-code>: the ‘Authorization Code‘ we got in the callback redirect.

<redirect_URI>: This is the tricky part. This can’t be ignored or filled with random things, it’s the value of “RuName (eBay Redirect URL name)

Send the request, and you’ll get the access token and the refresh token.
Follow the official guide to refresh the token if expired.

We are basically finished here, If you wanna call an API, ‘List orders as a seller’ for instance:

GET https://api.ebay.com/sell/fulfillment/v1/order

Authorization: Bearer <YOUR_ACCESS_TOKEN>
It’s Bearer this time :), don’t use Basic by mistake.

## Remove the Loop Icon for VOX

VOX is the best music players on OSX I’ve ever used.

The Loop becomes one of it’s features to store unlimited music on it’s platform. It’s a good feature, and the only way for the developer to get some pay back for the wonderful applet.

I just don’t need it, and try to save some space for my menu bar.

On the VOX’s preference page, uncheck “Keep Loop Agent Running when” just doesn’t make any sense. Neither for “launchctl remove com.coppertino.VOXCloud” as the developer mentioned.

My way to close that:

Finder – Application – VOX – right click – Show package contents – Contents – Library – LoginItems

You can find the Loop.app here, but things like deleting/renaming/[removing permission] will all prevent VOX from launching.

Loop.app – Show package contents – Contents – Resources – Base.lproj

Quit Loop and restart VOX, Done.

## Important:

Double check your operate system: ONLY  Debian 8 (Jessie) works with this instruction

Apache version: 2.4 which is the default version comes with Debian 8 (Not working with Apache 2.2 or lower)

## Install Apache2:

Update package list and upgrade outdated packages:

Install Apache2:

## Install PHP7:

Since PHP7 is not included in any Debian official source list, we gonna use the version compiled by Dotdeb.org, which is pretty widely used.

Add the following two lines to the end of the file:

If you server is far from US, try find the nearest mirror: https://www.dotdeb.org/mirrors/

Get and Install GnuPG key:

Update packages again

Install PHP7:

here is a list of available packages currently: (By the way, Swoole also work with php7, use ‘pecl install swoole to install’)

Choose your list of mod, install with php

Install mod_php7 for Apache 2.4 and restart apache:

That’s it! Done!

## What’s sshd_config?

It’s “OpenSSH SSH daemon configuration file”

Simply means the config file for OpenSSH Server.

Located at /etc/ssh/sshd_config

## My reference

http://www.freebsd.org/cgi/man.cgi?query=sshd_config

By default, OpenSSH will listen on port 22 for all address(0.0.0.0 and ::)

There can be multiple Port defined, for example:

OpenSSH will listen on both ports

You may also add an optional port number, for example:

OpenSSH will listen on 192.168.1.120 and ddns.example.com at port 22, plus 1.2.3.4 port 922

If there are multiple “Port” specified:

Then 192.168.1.120:22   192.168.1.120:622   1.2.3.4:922  ddns.example.com:22  ddns.example.com:622 are listened

If port is not specified, sshd will listen on the address and all prior Port options specified.

## Access Control:

Process order: DenyUsers, AllowUsers, DenyGroups, and finally AllowGroups.

If none of the four is defined, login is allowed fro all users.

If Allow* is defined, login is only allowed to declared users and groups.

Only username and groupname are accepted, UID and GID are NOT.

In the following example, only ‘root’ and ‘user’ are allowed

In the following example, only ‘user2’ is denied.

## Limit user to specified destination address and port

Supposed the OpenSSH server is listening to multiple IPs (1.1.1.1 and 2.2.2.2)

At the end of sshd_config file: add:

You may also specify port

You may also specify address and port

Note:

Match Introduces a conditional block. If all of the criteria on the Match line are satisfied, the keywords on the following lines override those set in the global section of the config file, until either another Match line or the end of the file. If a keyword appears in multiple Match blocks that are satisfied, only the first instance of the keyword is applied.

## Limit user from specified source address

More details on HOST:

Host: Restricts the following declarations (up to the next Host or Match keyword) to be only for those hosts that match one of the patterns given after the keyword. If more than one pattern is provided, they should be separated by whitespace. A single `*’ as a pattern can be used to provide global defaults for all hosts. The host is the hostname argument given on the command line (i.e. the name is not converted to a canonicalized host name before matching). A pattern entry may be negated by prefixing it with an exclama- tion mark (`!’). If a negated entry is matched, then the Host entry is ignored, regardless of whether any other patterns on the line match. Negated matches are therefore useful to provide exceptions for wildcard matches.

### Here is another approach using Match:

At the end of sshd_config file: add: