Wiggle Sort

Question:
http://www.lintcode.com/en/problem/wiggle-sort/
Given an unsorted array nums, reorder it in-place such that
nums[0] <= nums[1] >= nums[2] <= nums[3]....
Example
Given nums = [3, 5, 2, 1, 6, 4], one possible answer is [1, 6, 2, 5, 3, 4].

Answer:
class Solution {
public:
    /*
     * @param nums: A list of integers
     * @return: nothing
     */
    inline int partion(vector<int> &nums, int left, int right) {
        int pivot = nums[left];
        int i = left - 1;
        int j = right + 1;
        while (1) {
            do {
                i = i + 1;
            } while (nums[i] < pivot);
            do {
                j = j -1;
            } while (nums[j] > pivot);
            if (i >= j)
                return j;
            int temp = nums[i];
            nums[i] = nums[j];
            nums[j] = temp; 
        }
    }
    inline void qsort(vector<int> &nums,  int left, int right) {
        if (left >= right)
            return;
        int p = partion(nums, left, right);
        qsort(nums, left, p);
        qsort(nums, p+1, right);
    }
    void wiggleSort(vector<int> &nums) {
        // write your code here
        vector<int> sort = nums;
        int len = nums.size();
        qsort(sort, 0, len-1);
        int l = 0;
        int r = len - 1;
        nums.clear();
        while (l < r) {
          nums.push_back(sort[l]);
          nums.push_back(sort[r]);
          l++;
          r--;
        }
        if (l == r)
          nums.push_back(sort[l]);
    }
};

Setup shadowsocks server on ubuntu 16.04

install shadowsocks-libev

sudo add-apt-repository ppa:max-c-lv/shadowsocks-libev
sudo apt-get update
sudo apt install shadowsocks-libev

install bbr

wget –no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh
chmod a+x bbr.sh
sudo ./bbr.sh

install rng-tools

sudo apt-get install rng-tools

config

sudo vim /etc/shadowsocks-libev/config.json
{
"server":"10.128.0.3",
"server_port":8911,
"local_port":1235,
"password":"jesusislove",
"timeout":60,
"method":"chacha20-ietf-poly1305"
}

start shadowsocks server

sudo /etc/init.d/shadowsocks-libev restart

Notes:
due to GFW, you need to change your IP and port and method in config.json frequently, otherwise your connection will be rejected.

Kth Largest Element

Question:
http://www.lintcode.com/en/problem/kth-largest-element/
Find K-th largest element in an array.
You can swap elements in the array.

Answer:
class Solution {
public:
    /*
     * @param n: An integer
     * @param nums: An array
     * @return: the Kth largest element
     */
    inline void qsort(vector<int> &nums, int left, int right) {
        if (left >= right)
            return;
        int mid = nums[(left + right)/2];
        int l = left;
        int r = right;
        while (l < r) {
            while(nums[l] < mid) ++l;
            while(nums[r] > mid) --r;
            if (l >= r) break;
            nums[l] = nums[l] + nums[r];
            nums[r] = nums[l] - nums[r];
            nums[l] = nums[l] - nums[r];
            ++l;
            --r;
        }
        if (l == r) l++;
        if (left < r) qsort(nums, left, l - 1);
        if (l > left) qsort(nums, r + 1, right);
    }
    int kthLargestElement(int n, vector<int> &nums) {
        // write your code here
        qsort(nums, 0, nums.size() - 1);
        return nums[nums.size() - n];
    }
};

call the Sabbath a delight and the Lord's holy day honorable

"If you keep your feet from breaking the Sabbath and from doing as you please on my holy day, if you call the Sabbath a delight and the Lord 's holy day honorable, and if you honor it by not going your own way and not doing as you please or speaking idle words, (Isaiah 58:13 NIV)
你若在安息日掉转(或译:谨慎) 你的脚步,在我圣日不以操作为喜乐,称安息日为可喜乐的,称耶和华的圣日为可尊重的;而且尊敬这日,不办自己的私事,不随自己的私意,不说自己的私话, (以赛亚书 58:13 和合本)
then you will find your joy in the Lord , and I will cause you to ride in triumph on the heights of the land and to feast on the inheritance of your father Jacob." The mouth of the Lord has spoken. (Isaiah 58:14 NIV)
你就以耶和华为乐。耶和华要使你乘驾地的高处,又以你祖雅各的产业养育你。这是耶和华亲口说的。 (以赛亚书 58:14 和合本)


Photo by Sam Goodgame / Unsplash

Send your post to your blogger via Subscribers

blogger setup

Setup your posting email in your blogger's setting.
mail2blogger
You can chose published it immediatly or as a draft

ghost settup

Install Ghost via my hacked ghost.
Install command: ghost install --zip /path/to/Ghost-1.17.1.zip
Click here to download Ghost-1.17.1.zip

More install config please refer to ghost install --help
Enable Subscribers feature in your Ghost's Labs.
subscribers
https://help.ghost.org/hc/en-us/articles/224089787-Subscribers-Beta
Subcribers is currently still a beta feature, The current version of subscribers does NOT send emails. This will come in a future version.
so I hacked into Ghost core and release it. please first install my hacked version which metioned at the beginning.
By the way, it is just a simple hack, offical ghost will support it later with significant improvements to the Subscribers feature in the future and more integration as we build out our Memberships and Subscriptions features.
If you eager to send post to your Subscribers, you can try my hacked ghost like me.:)
Add your blogger's mail as a subscriber of Ghost.
bloggermail
Now everything is ready.
Once this post published in my ghost, it will be published in my blogger too.

Please add your recipient's email address to authorized recipents if you are using free accounts of Mailgun

I setup mailgun with my ghost blog.
but I found I cann't send any mails out exception the mails send to errong.leng@gmail.com which is registered to create an account in mailgun.

I checked my mailgun's account's log, and I found:
Rejected: 'Errong Leng has invited you to join ACM Problem Resolving&Report' Free accounts are for test purposes only. Please upgrade or add the address to authorized recipients in Account Settings.:

reject

Ok. I do not like to upgrade since it will require your credit card info.
I have to add the address to authorized recipients in Account Settings.

invite_new_recipient

Input your recipient's address

invite2

Check your email and click "I Agree"

verified

Confirm and clicked "Yes"
ve2

You will found the recipient verified

v3

Ok, every thing is fine now.
Perphas I will upgrade later since you have to add each recipient one by one and wait it verified.

Hack Ghost core and release it


if you want to hack Ghost core you need to follow
https://docs.ghost.org/docs/working-with-ghost and
https://docs.ghost.org/docs/working-with-the-admin-client

Once you done all your hack job, just run grunt release command under your ghost folder.

grunt release 

Once it completed, you will get a zip file:
./.dist/release/Ghost-1.16.1.zip

Then run your hacked ghost under a new empty folder:
ghost install --zip /path/to/.dist/release/Ghost-1.16.1.zip 

 --zip              Path to Ghost release zip to install         [string]


fixed: embedded-redis: Unable to run on macOS Sonoma

Issue you might see below error while trying to run embedded-redis for your testing on your macOS after you upgrade to Sonoma. java.la...