This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function insertionSort(data) | |
| { | |
| for(let i = 1; i < data.length; ++i) { | |
| let j = i | |
| while(j > 0 && data[j] < data[j - 1]) { | |
| let tmp = data[j] | |
| data[j] = data[j - 1] | |
| data[j - 1] = tmp | |
| j -- | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = Array.from({length: 15}).map((_,i) => i) | |
| function binarySearch(arr, needle) | |
| { | |
| let begin = 0, end = arr.length - 1 | |
| while (begin <= end) { | |
| let mid = Math.floor((end - begin) / 2) + begin | |
| if (arr[mid] === needle) { | |
| return mid | |
| } else if (arr[mid] > needle) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def vector_rotation(str, pos): | |
| '''Transpose concept: (A.T B.T).T = (BA) ''' | |
| l_half = str[:pos][::-1] | |
| r_half = str[pos:][::-1] | |
| new_str = l_half + r_half | |
| return new_str[::-1] | |
| s = 'abcdefgh' | |
| print(vector_rotation(s, 2)) | |
| print(vector_rotation(s, 3)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def insertion_sort(data): | |
| length = len(data) | |
| for i in range(1, length): | |
| j = i | |
| while j > 0 and data[j] < data[j-1]: | |
| tmp = data[j-1] | |
| data[j - 1] = data[j] | |
| data[j] = tmp | |
| j -= 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| quicksort :: (Ord a) => [a] -> [a] | |
| quicksort [] = [] | |
| quicksort (x:xs) = | |
| let smallerSorted = quicksort [a | a <- xs, a <= x] | |
| biggerSorted = quicksort [a | a <- xs, a > x] | |
| in smallerSorted ++ [x] ++ biggerSorted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if [ -f .bashrc ] ; then | |
| echo "bashrc exists" | |
| else | |
| echo "bashrc does not exist" | |
| fi | |
| if [[ -r .bashrc ]] | |
| then | |
| echo ".bashrc exists and have permission granted." | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| str = 'hello {name}, say {msg}. {name} is a handsome boy, {age}!' | |
| reg = /{([^{}]+)}/g | |
| data = { | |
| name: 'eason', | |
| msg: 'hi' | |
| } | |
| str.replace(reg, function (_, key) { | |
| return data[key] || `{${key}}` | |
| }) | |
| // "hello eason, say hi. eason is a handsome boy, {age}!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 参考 https://github.com/janl/mustache.js/blob/b283da5c8c26dbf78c357a1f67bfed26d18f5e32/mustache.js#L60 | |
| */ | |
| var entityMap = { | |
| '&': '&', | |
| '<': '<', | |
| '>': '>', | |
| '"': '"', | |
| "'": ''', | |
| '/': '/', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "configurations": [ | |
| { | |
| "name": "Mac", | |
| "includePath": [ | |
| "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1", | |
| "/usr/local/include", | |
| "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include", | |
| "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include", | |
| "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const adder = new Function('a', 'b', 'return a + b') | |
| adder(2, 3) |
OlderNewer