Posts

Showing posts from November, 2017

A Sabbath-rest for the people of God

Image
我们既蒙留下,有进入他安息的应许,就当畏惧,免得我们(原文是你们) 中间或有人似乎是赶不上了。 (希伯来书 4:1 和合本) Therefore, since the promise of entering his rest still stands, let us be careful that none of you be found to have fallen short of it. (Hebrews 4:1 NIV) 因为有福音传给我们,像传给他们一样;只是所听见的道与他们无益,因为他们没有信心与所听见的道调和。 (希伯来书 4:2 和合本) For we also have had the good news proclaimed to us, just as they did; but the message they heard was of no value to them, because they did not share the faith of those who obeyed. (Hebrews 4:2 NIV) 但我们已经相信的人得以进入那安息,正如 神所说:"我在怒中起誓说:'他们断不可进入我的安息!'"其实造物之工,从创世以来已经成全了。 (希伯来书 4:3 和合本) Now we who have believed enter that rest, just as God has said, "So I declared on oath in my anger, 'They shall never enter my rest.' " And yet his works have been finished since the creation of the world. (Hebrews 4:3 NIV) 论到第七日,有一处说:"到第七日, 神就歇了他一切的工。" (希伯来书 4:4 和合本) For somewhere he has spoken about the seventh day in these words: "On the seventh day God rested from al

bring good news

Image
那报佳音,传平安,报好信,传救恩的,对锡安说:你的 神作王了!这人的脚登山何等佳美! (以赛亚书 52:7 和合本) How beautiful on the mountains are the feet of those who bring good news, who proclaim peace, who bring good tidings, who proclaim salvation, who say to Zion, "Your God reigns!" (Isaiah 52:7 NIV) Photo by Flo Dahm / Unsplash

Correct usage of tzset(), TZ env

https://knowledgebase.progress.com/articles/Article/000044163 TZ variable can be set on on for a session, user profile or use it in the Database start-up script to start the database for the specific timezone or country or city. Following are some examples can be tested in a terminal session of UNIX. For China is UTC+8:00 or GMT+8:00 TZ needs to set it with opposite sign as follows: TZ=UTC-8:00; export TZ or, TZ=GMT-8:00; export TZ or, TZ=Asia/Shanghai;export TZ setenv("TZ", "GMT-8:00", 1) tzset(); For US EST (GMT-5:00, New York): TZ=UTC+5:00; export TZ Or, TZ=GMT+5:00; export TZ Or, TZ=America/New_York;export TZ setenv("TZ", "UTC+5:00", 1) tzset();

Trapping Rain Water

Image
Question: http://www.lintcode.com/en/problem/trapping-rain-water/ Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. Example Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. Answer RunTime : 1272ms class Solution { public: /* * @param heights: a list of integers * @return: a integer */ int trapRainWater(vector<int> &heights) { // write your code here if (heights.size() < 3) return 0; int result = 0; size_t l, r; l = 0; r = heights.size() - 1; while (l < r) { while (l < r && heights[l] == 0) l++; while (l < r && heights[r] == 0) r--; int min = heights[l] < heights[r] ?  heights[l] : heights[r]; for (size_t i = l; i <= r; i++) { if (heights[i] >= min) heights[i] -= min; else { result += min - heights[i]; heights[i] = 0; } } } return res

Earn Money from YunFile

Image
Join Now

RIGHT ACTIONS FROM WRONG MOTIVES

Image
"你们祷告的时候,不可像那假冒为善的人,爱站在会堂里和十字路口上祷告,故意叫人看见。我实在告诉你们,他们已经得了他们的赏赐。 (马太福音 6:5 和合本) "And when you pray, do not be like the hypocrites, for they love to pray standing in the synagogues and on the street corners to be seen by others. Truly I tell you, they have received their reward in full. (Matthew 6:5 NIV) 你祷告的时候,要进你的内屋,关上门,祷告你在暗中的父;你父在暗中察看,必然报答你。 (马太福音 6:6 和合本) But when you pray, go into your room, close the door and pray to your Father, who is unseen. Then your Father, who sees what is done in secret, will reward you. (Matthew 6:6 NIV) 你们祷告,不可像外邦人,用许多重复话,他们以为话多了必蒙垂听。 (马太福音 6:7 和合本) And when you pray, do not keep on babbling like pagans, for they think they will be heard because of their many words. (Matthew 6:7 NIV) 你们不可效法他们;因为你们没有祈求以先,你们所需用的,你们的父早已知道了。 (马太福音 6:8 和合本) Do not be like them, for your Father knows what you need before you ask him. (Matthew 6:8 NIV) 所以,你们祷告要这样说:我们在天上的父:愿人都尊你的名为圣。 (马太福音 6:9 和合本) "This, then, is how you should pray: " 'Our Fa

Welcome to use Magoosh coupon code: CNAMBLER

Image
I am Ambassador of Magoosh . http://magoosh.com/ Welcome to use my Magoosh coupon code: CNAMBLER You can get more discount and save your money.

AT THE BETHESDA POOL IN JERUSALEM

Image
这事以后,到了犹太人的一个节期,耶稣就上耶路撒冷去。 (约翰福音 5:1 和合本) Some time later, Jesus went up to Jerusalem for one of the Jewish festivals. (John 5:1 NIV) 在耶路撒冷,靠近羊门有一个池子,希伯来话叫作毕士大,旁边有五个廊子; (约翰福音 5:2 和合本) Now there is in Jerusalem near the Sheep Gate a pool, which in Aramaic is called Bethesda and which is surrounded by five covered colonnades. (John 5:2 NIV) 里面躺着瞎眼的、瘸腿的、血气枯干的许多病人。(有古卷加:等候水动;4因为有天使按时下池子搅动那水,水动之后,谁先下去,无论害什么病就痊愈了。) (约翰福音 5:3 和合本) Here a great number of disabled people used to lie—the blind, the lame, the paralyzed. (John 5:3 NIV) (John 5:4 NIV) 在那里有一个人,病了三十八年。 (约翰福音 5:5 和合本) One who was there had been an invalid for thirty-eight years. (John 5:5 NIV) 耶稣看见他躺着,知道他病了许久,就问他说:"你要痊愈吗?" (约翰福音 5:6 和合本) When Jesus saw him lying there and learned that he had been in this condition for a long time, he asked him, "Do you want to get well?" (John 5:6 NIV) 病人回答说:"先生,水动的时候,没有人把我放在池子里;我正去的时候,就有别人比我先下去。" (约翰福音 5:7 和合本) "Sir," the invalid replied,

Word Break III

Question http://www.lintcode.com/en/problem/word-break-iii/ Give a dictionary of words and a sentence with all whitespace removed, return the number of sentences you can form by inserting whitespaces to the sentence so that each word can be found in the dictionary. Example Given a String CatMat Given a dictionary ["Cat", "Mat", "Ca", "tM", "at", "C", "Dog", "og", "Do"] return 3 we can form 3 sentences, as follows: CatMat = Cat Mat CatMat = Ca tM at CatMat = C at Mat Answer RunTime : 288ms class Solution { public: /* * @param s: A string * @param dict: A dictionary of words dict * @return: A boolean */ int wordBreak3(string &s, unordered_set<string> &dict) { // write your code here if (s.length() <= 0) return 0; bool found = true; for (auto c : s) { bool in = false; for (auto d : dict) { if (in) break; for (auto e : d) { if

Word Break II

Question Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. Example Gieve s = lintcode, dict = ["de", "ding", "co", "code", "lint"]. A solution is ["lint code", "lint co de"]. Answer RunTime : 902ms class Solution { public: /* * @param s: A string * @param dict: A dictionary of words dict * @return: A boolean */ vector<string> wordBreak(string &s, unordered_set<string> &dict) { // write your code here result.clear(); if (s.length() <= 0) return result; bool found = true; for (auto c : s) { bool in = false; for (auto d : dict) { if (in) break; for (auto e : d) { if (e == c) { in = true; break; } } } if (!in) { found = false; break; } } if (!found) return result; Trie trie; for

Word Break

Question http://www.lintcode.com/en/problem/word-break/ Given a string s and a dictionary of words dict, determine if s can be break into a space-separated sequence of one or more dictionary words. Example Given s = "lintcode", dict = ["lint", "code"]. Return true because "lintcode" can be break as "lint code". Answer Run Time : 582ms  class Solution { public: /* * @param s: A string * @param dict: A dictionary of words dict * @return: A boolean */ bool wordBreak(string &s, unordered_set<string> &dict) { // write your code here if (dict.size() <= 0) { if (s.length() <= 0) return true; return false; } Trie trie; for (auto d : dict) trie.insert(d); return wordBreakHelp(s, trie, 0); } private: struct TrieNode { TrieNode() { for (int i = 0; i < 26; i++) { next[i] = 0; } s = 0; } int s; TrieNode* next[26]; }; class Trie { public: Trie() { ro

Lord's will

Image
其实明天如何,你们还不知道。你们的生命是什么呢?你们原来是一片云雾,出现少时就不见了。 (雅各书 4:14 和合本) Why, you do not even know what will happen tomorrow. What is your life? You are a mist that appears for a little while and then vanishes. (James 4:14 NIV) 你们只当说:"主若愿意,我们就可以活着,也可以做这事,或做那事。" (雅各书 4:15 和合本) Instead, you ought to say, "If it is the Lord's will, we will live and do this or that." (James 4:15 NIV) Photo by James Chou / Unsplash

Unique Paths III

Question http://www.lintcode.com/en/problem/unique-paths-iii/ Follow up for "Unique Paths II": https://acm.errong.win/uniquepathsii/ Now each grid contains a value, so each path also has a value. Find the sum of all the unique values paths. Example For example, [ [1,1,2], [1,2,3], [3,2,4] ] There are 2 unique value path: [1,1,2,3,4] = 11 [1,1,2,2,4] = 10 return 21 Answer class Solution { public: /* * @param : an array of arrays * @return: the sum of all unique weighted paths */ int uniqueWeightedPaths(vector<vector<int>> &obstacleGrid) { int m = obstacleGrid.size(); if (m <= 0) return 0; int n = obstacleGrid[0].size(); if (n <= 0) return 0; struct Up { int step; int sum; Up(int st, int su) : step(st), sum(su) {} }; map<int, vector<Up>> sum_paths; sum_paths[0] = vector<Up>(); sum_paths[0].push_back(Up(0, obstacleGrid[0][0])); for (int i = 1; i < m + n - 1; i++) { map<in

JESUS THE SOUL WINNER

Image
在那里有雅各井;耶稣因走路困乏,就坐在井旁。那时约有午正。 (约翰福音 4:6 和合本) Jacob's well was there, and Jesus, tired as he was from the journey, sat down by the well. It was about noon. (John 4:6 NIV) 有一个撒玛利亚的妇人来打水。耶稣对她说:"请你给我水喝。"( (约翰福音 4:7 和合本) When a Samaritan woman came to draw water, Jesus said to her, "Will you give me a drink?" (John 4:7 NIV) 那时门徒进城买食物去了。) (约翰福音 4:8 和合本) (His disciples had gone into the town to buy food.) (John 4:8 NIV) 撒玛利亚的妇人对他说:"你既是犹太人,怎么向我一个撒玛利亚妇人要水喝呢?"原来犹太人和撒玛利亚人没有来往。 (约翰福音 4:9 和合本) The Samaritan woman said to him, "You are a Jew and I am a Samaritan woman. How can you ask me for a drink?" (For Jews do not associate with Samaritans. ) (John 4:9 NIV) 耶稣回答说:"你若知道 神的恩赐,和对你说'给我水喝'的是谁,你必早求他,他也必早给了你活水。" (约翰福音 4:10 和合本) Jesus answered her, "If you knew the gift of God and who it is that asks you for a drink, you would have asked him and he would have given you living water." (John 4:10 NIV) Photo by Gerrie

Unique Paths II

Question http://www.lintcode.com/en/problem/unique-paths-ii/ Follow up for "Unique Paths" : Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the grid. Example For example, There is one obstacle in the middle of a 3x3 grid as illustrated below. [ [0,0,0], [0,1,0], [0,0,0] ] The total number of unique paths is 2. Answer class Solution { public: /* * @param obstacleGrid: A list of lists of integers * @return: An integer */ int uniquePathsWithObstacles(vector<vector<int>> &obstacleGrid) { int m = obstacleGrid.size(); if (m <= 0) return 0; int n = obstacleGrid[0].size(); if (obstacleGrid[0][0] == 1 || obstacleGrid[m-1][n-1] == 1) return 0; vector<vector<int>> res(m, vector<int>(n, 0)); res[0][0] = 1; for (int j = 1; j

Unique Paths

Question http://www.lintcode.com/en/problem/unique-paths/ A robot is located at the top-left corner of a m x n grid. The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid. How many possible unique paths are there? Example Given m = 3 and n = 3, return 6. Given m = 4 and n = 5, return 35. Given m = 6 end = 63, return 9657648 Answer // brute force solution, Time Limit Exceeded // help us get dp formula pattern // res[i][j] = res[i-1][j] + res[i][j-1]; public int uniquePaths(int m, int n) { return helper(1, 1, m, n); } private int helper(int row, int col, int m, int n) { if(row == m && col == n) return 1; if( row > m || col > n) return 0; return helper(row+1, col, m, n) + helper(row, col+1, m, n); } // dp solution class Solution { public: /* * @param m: positive integer (1 <= m <= 100) * @param n: positive integer (1 <= n &l

Next Sparse Number

Question http://www.lintcode.com/en/problem/next-sparse-number/ A number is Sparse if there are no two adjacent 1s in its binary representation. Given a number n, find the smallest Sparse number which greater than or equal to n. eg. 5 (binary representation: 101) is sparse, but 6 (binary representation: 110) is not sparse. Example Given n = 6, return 8 Next Sparse Number is 8 Given n = 4, return 4 Next Sparse Number is 4 Given n = 38, return 40 Next Sparse Number is 40 Given n = 44, return 64 Next Sparse Number is 64 Given n = 341381939, return 343932928 Next Sparse Number is 343932928 Answer class Solution { public: /* * @param : a number * @return: return the next sparse number behind x */ int nextSparseNum(int x) { // write your code here if (x == 0 || x == 1) return x; string binary; int n = x; while (n) { if (n&1) binary.append("1"); else

How to verify your ownership of the web server powered by Ghost via Search Console

Image
Since I want to do Verify my ownership of http://www.errong.win/ via Search Console . I tried to upload the file google9aedadfa5be8a815.html under my site's working directory where I installed via ghost instal command. but only get 404 error while visiting http://www.errong.win/google9aedadfa5be8a815.html Solution Thanks to Nistor Cristian, kevin, vikas.potluri, they replied my thread quickly in ghost.slack.org and I got the issue fixed. Nistor Cristian simply include it in your theme and should work kevin @Errong add the file to the root of your theme vikas.potluri If you're not sure which theme to use, go to the ghost admin panel, download the current theme, drop in your google verification and upload it back to the admin interface For my case: I use the default casper theme, its path is : blog/content/themes/casper/ I moved google9aedadfa5be8a815.html there and then it works. You do not even need to restart your ghost( ghost restart ). You can use below

CHRIST’S DEATH MEANS OUR LIFE

Image
有一个法利赛人,名叫尼哥底母,是犹太人的官。 (约翰福音 3:1 和合本) Now there was a Pharisee, a man named Nicodemus who was a member of the Jewish ruling council. (John 3:1 NIV) 这人夜里来见耶稣,说:"拉比,我们知道你是由 神那里来作师傅的;因为你所行的神迹,若没有 神同在,无人能行。" (约翰福音 3:2 和合本) He came to Jesus at night and said, "Rabbi, we know that you are a teacher who has come from God. For no one could perform the signs you are doing if God were not with him." (John 3:2 NIV) 耶稣回答说:"我实实在在地告诉你,人若不重生,就不能见 神的国。" (约翰福音 3:3 和合本) Jesus replied, "Very truly I tell you, no one can see the kingdom of God unless they are born again. " (John 3:3 NIV) 尼哥底母说:"人已经老了,如何能重生呢?岂能再进母腹生出来吗?" (约翰福音 3:4 和合本) "How can someone be born when they are old?" Nicodemus asked. "Surely they cannot enter a second time into their mother's womb to be born!" (John 3:4 NIV) 耶稣说:"我实实在在地告诉你,人若不是从水和圣灵生的,就不能进 神的国。 (约翰福音 3:5 和合本) Jesus answered, "Very truly I tell you, no one can enter the kingdom

Maximum Subarray VI

Question Given an array of integers. find the maximum XOR subarray value in given array. What's the XOR: https://en.wikipedia.org/wiki/Exclusive_or Notice Expected time complexity O(n). Answer https://threads-iiith.quora.com/Tutorial-on-Trie-and-example-problems Let's say F(L,R) is XOR of subarray from L to R. Here we use the property that F(L,R)=F(1,R) XOR F(1,L-1). How? Let's say our subarray with maximum XOR ended at position i. Now, we need to maximise F(L,i) ie. F(1,i) XOR F(1,L-1) where L<=i. Suppose, we inserted F(1,L-1) in our trie for all L<=i, then it's just problem1. class Solution { public: /* * @param : the array * @return: the max xor sum of the subarray in a given array */ int maxXorSubarray(vector<int> &nums) { // write code here int ans = INT_MIN; int pre = 0; Trie trie; for (auto n : nums) { pre = pre ^ n; trie.insert(pre);

Maximum Subarray III

Question: http://www.lintcode.com/en/problem/maximum-subarray-iii/ Given an array of integers and a number k, find k non-overlapping subarrays which have the largest sum. The number in each subarray should be contiguous. Return the largest sum. Answer localMax[i][j], means the maximum sum we can get while select j subarrays  from first i elements, including element i  globalMax[i][j], means the maximum sum we can get while select j subarrays  from first i elements, may not including element i  // state transfer  localMax[i][j] = max(localMax[i - 1][j] + nums[i - 1], globalMax[i - 1][j - 1] + nums[i - 1])  globalMax[i][j] = max(globalMax[i - 1][j], localMax[i][j])      class Solution { public: /* * @param nums: A list of integers * @param k: An integer denote to find k non-overlapping subarrays * @return: An integer denote the sum of max k non-overlapping subarrays */ int maxSubArray(vector<int> &nums, int k) { // write you

Maximum Subarray II

Question Given an array of integers, find two non-overlapping subarrays which have the largest sum. The number in each subarray should be contiguous. Return the largest sum. Notice The subarray should contain at least one number Answer class Solution { public: /* * @param nums: A list of integers * @return: An integer denotes the sum of max two non-overlapping subarrays */ int maxTwoSubArrays(vector<int> &nums) { // write your code here int len = nums.size(); vector<int> suml(len); int cur_max = nums[0]; int max = cur_max; suml[0] = max; for (int i = 1; i < len; i++) { if (cur_max <= 0) { cur_max = nums[i]; } else { cur_max += nums[i]; } if (max < cur_max) max = cur_max; suml[i] = max; } vector<int> sumr(len); cur_max = nums[len-1];

Look at the new growth in the valley

Image
那向外观看、如晨光发现、美丽如月亮、皎洁如日头、威武如展开旌旗军队的是谁呢? (雅歌 6:10 和合本) Who is this that appears like the dawn, fair as the moon, bright as the sun, majestic as the stars in procession? He (Song of Songs 6:10 NIV) 我下入核桃园,要看谷中青绿的植物,要看葡萄发芽没有,石榴开花没有。 (雅歌 6:11 和合本) I went down to the grove of nut trees to look at the new growth in the valley, to see if the vines had budded or the pomegranates were in bloom. (Song of Songs 6:11 NIV) 不知不觉,我的心将我安置在我尊长的车中。〔耶路撒冷的众女子〕 (雅歌 6:12 和合本) Before I realized it, my desire set me among the royal chariots of my people. Friends (Song of Songs 6:12 NIV) Photo by 贝莉儿 NG / Unsplash

Candy

Question: http://www.lintcode.com/en/problem/candy/ There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy.  Children with a higher rating get more candies than their neighbors.    What is the minimum candies you must give? Answer: class Solution { public: /* * @param ratings: Children's ratings * @return: the minimum candies you must give */ int candy(vector<int> &ratings) { // write your code here vector<int> candys(ratings.size(), 1); for (int i = 0; i < ratings.size() - 1; i++) { if (ratings[i+1] > ratings[i]) candys[i+1] = candys[i] + 1; } for (int i = ratings.size() - 1; i > 0; i--) { if (ratings[i-1] > ratings[i]) candys[i-1] = max(candys[i] + 1, candys[i-1]); }

Course Schedule III

Question: http://www.lintcode.com/en/problem/course-schedule-iii/ There are ·n· different online courses numbered from 1 to n. Each course has some duration(course length) t and closed on dth day. A course should be taken continuously for t days and must be finished before or on the dth day. You will start at the 1st day. Given n online courses represented by pairs (t,d), your task is to find the maximal number of courses that can be taken. Notice The integer 1 <= d, t, n <= 10,000. You can't take two courses simultaneously. Example Given [[100, 200], [200, 1300], [1000, 1250], [2000, 3200]] return 3 There're totally 4 courses, but you can take 3 courses at most: First, take the 1st course, it costs 100 days so you will finish it on the 100th day, and ready to take the next course on the 101st day. Second, take the 3rd course, it costs 1000 days so you will finish it on the 1100th day, and ready to take the next course on the 1101st day. Third, take the 2n

Course Schedule II

Question: http://www.lintcode.com/en/problem/course-schedule-ii/ There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1] Given the total number of courses and a list of prerequisite pairs, return the ordering of courses you should take to finish all courses. There may be multiple correct orders, you just need to return one of them. If it is impossible to finish all courses, return an empty array. Example Given n = 2, prerequisites = [[1,0]] Return [0,1] Given n = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]] Return [0,1,2,3] or [0,2,1,3] Answer: class Solution { public: /* * @param numCourses: a total of n courses * @param prerequisites: a list of prerequisite pairs * @return: the course order */ vector<int> findOrder(int numCourses, vector<pair<int, int>> &prerequisites)

Topological Sorting

Question: http://www.lintcode.com/en/problem/topological-sorting/ Given an directed graph, a topological order of the graph nodes is defined as follow: For each directed edge A -> B in graph, A must before B in the order list. The first node in the order can be any node in the graph with no nodes direct to it. Find any topological order for the given graph. Answer: class Solution { public: /* * @param ratings: Children's ratings * @return: the minimum candies you must give */ int candy(vector<int> &ratings) { // write your code here vector<int> candys(ratings.size(), 1); for (int i = 0; i < ratings.size() - 1; i++) { if (ratings[i+1] > ratings[i]) candys[i+1] = candys[i] + 1; } for (int i = ratings.size() - 1; i > 0; i--) { if (ratings[i-1] > ratings[i]) candys[i-1] = max(candys[i] + 1, candys[i-1]); } int co

Course Schedule

Question: http://www.lintcode.com/en/problem/course-schedule/ There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1] Given the total number of courses and a list of prerequisite pairs, is it possible for you to finish all courses? Answer: class Solution { public: /* * @param numCourses: a total of n courses * @param prerequisites: a list of prerequisite pairs * @return: true if can finish all courses or false */ bool canFinish(int numCourses, vector<pair<int, int>>& prerequisites) { // Write your code here vector<vector<int>> adj(numCourses); vector<int> indegree(numCourses); for (int i = 0; i < numCourses; i++) indegree[i] = 0; for (auto pq : prerequisites) { adj[pq.first].push_back(pq.second);

How to be Jesus's disciples

Image
我是葡萄树,你们是枝子。常在我里面的,我也常在他里面,这人就多结果子;因为离了我,你们就不能作什么。 (约翰福音 15:5 和合本) "I am the vine; you are the branches. If you remain in me and I in you, you will bear much fruit; apart from me you can do nothing. (John 15:5 NIV) 人若不常在我里面,就像枝子丢在外面枯干,人拾起来,扔在火里烧了。 (约翰福音 15:6 和合本) If you do not remain in me, you are like a branch that is thrown away and withers; such branches are picked up, thrown into the fire and burned. (John 15:6 NIV) 你们若常在我里面,我的话也常在你们里面,凡你们所愿意的,祈求,就给你们成就。 (约翰福音 15:7 和合本) If you remain in me and my words remain in you, ask whatever you wish, and it will be done for you. (John 15:7 NIV) 你们多结果子,我父就因此得荣耀,你们也就是我的门徒了。 (约翰福音 15:8 和合本) This is to my Father's glory, that you bear much fruit, showing yourselves to be my disciples. (John 15:8 NIV) Photo by Bill Williams / Unsplash

Wildcard Matching

Question: http://www.lintcode.com/en/problem/wildcard-matching/ Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character.  '*' Matches any sequence of characters (including the empty sequence).    The matching should cover the entire input string (not partial). Answer:   class Solution { public: /* * @param s: A string * @param p: A string includes "?" and "*" * @return: is Match? */ bool isMatch(string &s, string &p) { if (p.empty()) return false; int n = s.length(); int m = p.length(); bool f[n + 1][m + 1]; memset(f, false, sizeof(f)); f[0][0] = true; for (int i = 1; i <= n; i++) f[i][0] = false; for (int i = 1; i <= m; i++) f[0][i] = f[0][i - 1] && p[i - 1] == '*'; for (int i = 1; i <= n; i++) {

Maximum Gap

Question: http://www.lintcode.com/en/problem/maximum-gap/ Given an unsorted array, find the maximum difference between the successive elements in its sorted form. Return 0 if the array contains less than 2 elements. Sort is easy but will cost O(nlogn) time. Try to solve it in linear time and space. Answer: class Solution { public: int maximumGap(vector<int> &num) { if (num.size() < 2) return 0; int maxNum = num[0]; int minNum = num[0]; for (int x : num) { maxNum = max(maxNum, x); minNum = min(minNum, x); } int len = (maxNum - minNum) / num.size() + 1; vector<vector<int>> buckets((maxNum - minNum) / len + 1); for (int x : num) { int i = (x - minNum) / len; if (buckets[i].empty()) { buckets[i].reserve(2); buckets[i].push_back(x); buckets[i].push_back(x);

HOW CHRIST MET A REAL NEED

Image
第三日,在加利利的迦拿有娶亲的筵席,耶稣的母亲在那里。 (约翰福音 2:1 和合本) On the third day a wedding took place at Cana in Galilee. Jesus' mother was there, (John 2:1 NIV) 耶稣和他的门徒也被请去赴席。 (约翰福音 2:2 和合本) and Jesus and his disciples had also been invited to the wedding. (John 2:2 NIV) 酒用尽了,耶稣的母亲对他说:"他们没有酒了。" (约翰福音 2:3 和合本) When the wine was gone, Jesus' mother said to him, "They have no more wine." (John 2:3 NIV) 耶稣说:"母亲(原文是妇人) ,我与你有什么相干?我的时候还没有到。" (约翰福音 2:4 和合本) "Woman, why do you involve me?"Jesus replied. "My hour has not yet come." (John 2:4 NIV) 他母亲对用人说:"他告诉你们什么,你们就做什么。" (约翰福音 2:5 和合本) His mother said to the servants, "Do whatever he tells you." (John 2:5 NIV) 照犹太人洁净的规矩,有六口石缸摆在那里,每口可以盛两三桶水。 (约翰福音 2:6 和合本) Nearby stood six stone water jars, the kind used by the Jews for ceremonial washing, each holding from twenty to thirty gallons. (John 2:6 NIV) 耶稣对用人说:"把缸倒满了水。"他们就倒满了,直到缸口。 (约翰福音 2:7 和合本) Jesus said to

The LORD is great

Image
愿一切寻求你的,因你高兴欢喜;愿那些喜爱你救恩的,常说:当尊 神为大! (诗篇 70:4 和合本) But may all who seek you rejoice and be glad in you; may those who long for your saving help always say, "The Lord is great!" (Psalms 70:4 NIV) 但我是困苦穷乏的; 神啊,求你速速到我这里来!你是帮助我的,搭救我的。耶和华啊,求你不要耽延! (诗篇 70:5 和合本) But as for me, I am poor and needy; come quickly to me, O God. You are my help and my deliverer; Lord , do not delay. (Psalms 70:5 NIV) Photo by Justin Kauffman / Unsplash

Recommend text editor : Sublime Text

A sophisticated text editor for code, markup and prose

been tempted, yet he did not sin

Image
当时,耶稣被圣灵引到旷野,受魔鬼的试探。 (马太福音 4:1 和合本) Then Jesus was led by the Spirit into the wilderness to be tempted by the devil. (Matthew 4:1 NIV) 他禁食四十昼夜,后来就饿了。 (马太福音 4:2 和合本) After fasting forty days and forty nights, he was hungry. (Matthew 4:2 NIV) 那试探人的进前来,对他说:"你若是 神的儿子,可以吩咐这些石头变成食物。" (马太福音 4:3 和合本) The tempter came to him and said, "If you are the Son of God, tell these stones to become bread." (Matthew 4:3 NIV) 耶稣却回答说:"经上记着说:人活着,不是单靠食物,乃是靠 神口里所出的一切话。" (马太福音 4:4 和合本) Jesus answered, "It is written: 'Man shall not live on bread alone, but on every word that comes from the mouth of God.' " (Matthew 4:4 NIV) 魔鬼就带他进了圣城,叫他站在殿顶(顶:原文是翅) 上, (马太福音 4:5 和合本) Then the devil took him to the holy city and had him stand on the highest point of the temple. (Matthew 4:5 NIV) 对他说:"你若是 神的儿子,可以跳下去,因为经上记着说:主要为你吩咐他的使者用手托着你,免得你的脚碰在石头上。" (马太福音 4:6 和合本) "If you are the Son of God," he said, "throw yourself down. For it is wri

Christ Begins His Ministry

Image
当下,耶稣从加利利来到约旦河,见了约翰,要受他的洗。 (马太福音 3:13 和合本) Then Jesus came from Galilee to the Jordan to be baptized by John. (Matthew 3:13 NIV) 约翰想要拦住他,说:"我当受你的洗,你反倒上我这里来吗?" (马太福音 3:14 和合本) But John tried to deter him, saying, "I need to be baptized by you, and do you come to me?" (Matthew 3:14 NIV) 耶稣回答说:"你暂且许我,因为我们理当这样尽诸般的义(或译:礼) 。"于是约翰许了他。 (马太福音 3:15 和合本) Jesus replied, "Let it be so now; it is proper for us to do this to fulfill all righteousness."Then John consented. (Matthew 3:15 NIV) 耶稣受了洗,随即从水里上来。天忽然为他开了,他就看见 神的灵仿佛鸽子降下,落在他身上。 (马太福音 3:16 和合本) As soon as Jesus was baptized, he went up out of the water. At that moment heaven was opened, and he saw the Spirit of God descending like a dove and alighting on him. (Matthew 3:16 NIV) 从天上有声音说:"这是我的爱子,我所喜悦的。" (马太福音 3:17 和合本) And a voice from heaven said, "This is my Son, whom I love; with him I am well pleased." (Matthew 3:17 NIV) Photo by Simon Matzinger / Unsplash

Listen

Image
"只是我告诉你们这听道的人,你们的仇敌,要爱他!恨你们的,要待他好! (路加福音 6:27 和合本) "But to you who are listening I say: Love your enemies, do good to those who hate you, (Luke 6:27 NIV) 咒诅你们的,要为他祝福!凌辱你们的,要为他祷告! (路加福音 6:28 和合本) bless those who curse you, pray for those who mistreat you. (Luke 6:28 NIV) 有人打你这边的脸,连那边的脸也由他打。有人夺你的外衣,连里衣也由他拿去。 (路加福音 6:29 和合本) If someone slaps you on one cheek, turn to them the other also. If someone takes your coat, do not withhold your shirt from them. (Luke 6:29 NIV) 凡求你的,就给他。有人夺你的东西去,不用再要回来。 (路加福音 6:30 和合本) Give to everyone who asks you, and if anyone takes what belongs to you, do not demand it back. (Luke 6:30 NIV) 你们愿意人怎样待你们,你们也要怎样待人。 (路加福音 6:31 和合本) Do to others as you would have them do to you. (Luke 6:31 NIV) Photo by Artem Sapegin / Unsplash

Terror Judgement at the last day

Image
想望耶和华日子来到的有祸了!你们为何想望耶和华的日子呢?那日黑暗没有光明, (阿摩司书 5:18 和合本) Woe to you who long for the day of the Lord ! Why do you long for the day of the Lord ? That day will be darkness, not light. (Amos 5:18 NIV) 景况好像人躲避狮子又遇见熊,或是进房屋以手靠墙,就被蛇咬。 (阿摩司书 5:19 和合本) It will be as though a man fled from a lion only to meet a bear, as though he entered his house and rested his hand on the wall only to have a snake bite him. (Amos 5:19 NIV) 耶和华的日子不是黑暗没有光明吗?不是幽暗毫无光辉吗? (阿摩司书 5:20 和合本) Will not the day of the Lord be darkness, not light— pitch-dark, without a ray of brightness? (Amos 5:20 NIV) Photo by Anton Romanov / Unsplash

The Vison Of The River

Image
他带我回到殿门,见殿的门槛下有水往东流出(原来殿面朝东)。这水从槛下,由殿的右边,在祭坛的南边往下流。 (以西结书 47:1 和合本) The man brought me back to the entrance to the temple, and I saw water coming out from under the threshold of the temple toward the east (for the temple faced east). The water was coming down from under the south side of the temple, south of the altar. (Ezekiel 47:1 NIV) 他带我出北门,又领我从外边转到朝东的外门,见水从右边流出。 (以西结书 47:2 和合本) He then brought me out through the north gate and led me around the outside to the outer gate facing east, and the water was trickling from the south side. (Ezekiel 47:2 NIV) 他手拿准绳往东出去的时候,量了一千肘,使我趟过水,水到踝子骨。 (以西结书 47:3 和合本) As the man went eastward with a measuring line in his hand, he measured off a thousand cubits and then led me through water that was ankle-deep. (Ezekiel 47:3 NIV) 他又量了一千肘,使我趟过水,水就到膝;再量了一千肘,使我趟过水,水便到腰; (以西结书 47:4 和合本) He measured off another thousand cubits and led me through water that was knee-deep. He measured off another thousand and led me through water that was up to th

Wiggle Sort II

Question: http://www.lintcode.com/en/problem/wiggle-sort-ii/ Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3].... 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);

VISION VALLEY

Image
耶和华的灵(原文是手) 降在我身上。耶和华藉他的灵带我出去,将我放在平原中;这平原遍满骸骨。 (以西结书 37:1 和合本) The hand of the Lord was on me, and he brought me out by the Spirit of the Lord and set me in the middle of a valley; it was full of bones. (Ezekiel 37:1 NIV) 他使我从骸骨的四围经过,谁知在平原的骸骨甚多,而且极其枯干。 (以西结书 37:2 和合本) He led me back and forth among them, and I saw a great many bones on the floor of the valley, bones that were very dry. (Ezekiel 37:2 NIV) 他对我说:"人子啊,这些骸骨能复活吗?"我说:"主耶和华啊,你是知道的。" (以西结书 37:3 和合本) He asked me, "Son of man, can these bones live?" I said, "Sovereign Lord , you alone know." (Ezekiel 37:3 NIV) 他又对我说:"你向这些骸骨发预言说:枯干的骸骨啊,要听耶和华的话。 (以西结书 37:4 和合本) Then he said to me, "Prophesy to these bones and say to them, 'Dry bones, hear the word of the Lord ! (Ezekiel 37:4 NIV) 主耶和华对这些骸骨如此说:'我必使气息进入你们里面,你们就要活了。 (以西结书 37:5 和合本) This is what the Sovereign Lord says to these bones: I will make breath enter you, and you will come to life. (Ezekiel 37:5 NIV)

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)

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>

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

Image
"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

Image
blogger setup Setup your posting email in your blogger's setting. 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. 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, yo

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

Image
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.: 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. Input your recipient's address Check your email and click "I Agree" Confirm and clicked "Yes" You will found the recipient verified 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]

House Robber III

Question: http://www.lintcode.com/en/problem/house-robber-iii/ The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that "all houses in this place forms a binary tree". It will automatically contact the police if two directly-linked houses were broken into on the same night. Determine the maximum amount of money the thief can rob tonight without alerting the police. Answer: ~~~c++ class Solution { public:     int houseRobber3(TreeNode* root) {         unordered_map<TreeNode*, int> m;         return dfs(root, m);     }     int dfs(TreeNode *root, unordered_map<TreeNode*, int> &m) {         if (!root) return 0;         if (m.count(root)) return m[root];         int val = 0;         if (root->left) {             val += dfs(root->left->left, m) + dfs(root->left->right,

House Robber II

Question: http://www.lintcode.com/en/problem/house-robber-ii/ After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, the security system for these houses remain the same as for those in the previous street. Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police. Answer: ~~~c++ class Solution { public:      /*      * @param nums: An array of non-negative integers.      * @return: The maximum amount of money you can rob tonight      */     int houseRobber2(vector<int> nums) {         if (nums.size() <= 1)             return nums.empty() ? 0 : nums[0];         vector<int> nums_inf = nums;         vector<int> nums_inl = nums;         nu

House Robber

Question: http://www.lintcode.com/en/problem/house-robber You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night. Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police. Answer: time:O(N) ~~~c++ class Solution { public:     /*      * @param A: An array of non-negative integers      * @return: The maximum amount of money you can rob tonight      */     long long houseRobber(vector<int> &A) {         size_t as = A.size();         if (as == 0)           return 0;         if (as == 1)           return A[0];         if (as == 2)           return max(A[0], A[1]);         vector<long long&

Developer install & setup with Ghost, step by step

# Install Pre-requisites: node.js yarn grunt install node.js lts version wget https://nodejs.org/dist/v8.9.0/node-v8.9.0-linux-x64.tar.xz tar -xvf node-v8.9.0-linux-x64.tar.xz vim ~/.bashrc export PATH="$HOME/node-v8.9.0-linux-x64/bin:$PATH" source ~/.bashrc check node version node -v v8.9.0 install yarn curl -o- -L https://yarnpkg.com/install.sh | bash install grunt npm install -g grunt-cli # Initial Setup git clone https://github.com/TryGhost/Ghost.git  && cd Ghost yarn run init Could not start watchman Visit https://ember-cli.com/user-guide/#watchman for more info. $ git clone https://github.com/facebook/watchman.git $ cd watchman $ git checkout v4.9.0  # the latest stable release $ ./autogen.sh $ ./configure $ make $ sudo make install knex-migrator init # Develop Ghost grunt dev grunt dev --server grunt prod ..... # Refers https://docs.ghost.org/v1/docs/working-with-ghost

Fix up watchman issue with Ghost

# Issue >>     >>     at BunserBuf.<anonymous> (/home/errong_leng/Ghost/core/client/node_modules/fb-watchman/index.js:95:23) >>     at emitOne (events.js:116:13) >>     at BunserBuf.emit (events.js:211:7) >>     at BunserBuf.process (/home/errong_leng/Ghost/core/client/node_modules/bser/index.js:292:10) >>     at /home/errong_leng/Ghost/core/client/node_modules/bser/index.js:247:12 >>     at _combinedTickCallback (internal/process/next_tick.js:131:7) >>     at process._tickCallback (internal/process/next_tick.js:180:9) >> A non-recoverable condition has triggered.  Watchman needs your help! >> The triggering condition was at timestamp=1509698956: inotify-add-watch(/home/errong_leng/Ghost/core/client/node_modules/ember-cli-node-assets/node_modules/broccoli-funnel/node_modules/.bin) -> The user limit on the total number of inotify watches was reached; increase the fs.inotify.max_user_watches sysctl >> All requests