Last active
April 22, 2020 03:18
-
-
Save snowman/3a7b2e39f278b7768e25c1f6ee0b6af1 to your computer and use it in GitHub Desktop.
scripts
This file contains 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
COLUMNS = 5 | |
// requires lodash | |
a = Array.from(document.querySelectorAll("table th, table td")).map(th => th.innerText.trim()) | |
r = _.chunk(a, COLUMNS).map(([c1, c2, c3, c4, c5]) => `|${c1}|${c2}|${c3}|`).join("\n") | |
copy(r) |
This file contains 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
_copy = copy | |
SEARCH_PATTERN = 'java' | |
chrome.storage.local.get(null, (pages) => process(pages)) | |
byAscTime = (a, b) => a.time - b.time | |
byDescTime = (a, b) => b.time - a.time | |
uniq = lst => [...new Set(lst)] | |
process = (pages) => { | |
keys = Object.keys(pages) | |
found_pages = keys | |
.filter((key) => { | |
page = pages[key] | |
return new RegExp(SEARCH_PATTERN, "ig").test(page.text) | |
}) | |
.map(key => pages[key]) | |
.sort(byAscTime) | |
report = uniq(found_pages.map(format_page)).join('\n') | |
console.log(report) | |
_copy(report) | |
} | |
format_page = ({ title, url }) => `[[${url}][${title}]]` |
This file contains 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 getSelectionText() { | |
var text = ""; | |
if (window.getSelection) { | |
text = window.getSelection().toString(); | |
} else if (document.selection && document.selection.type != "Control") { | |
text = document.selection.createRange().text; | |
} | |
return text; | |
} |
This file contains 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
#include <stdio.h> | |
// | |
// o n | |
// ----------------------> | |
// | . . . . . | |
// | . . . . . | |
// | . . . . . | |
// | . . . . . | |
// | . . . . . | |
// | n | |
// > n | |
// | |
// | |
// condition: | |
// 1. the outer loop: step <= n*n | |
// 2. the inner loop (direction loop): | |
// 1. element location should be inside matrix | |
// row, col >= 0 && row, col < n | |
// 2. next element "matrix[row][col]" on current direction is empty | |
// row+1 < n --> row<n-1 | |
// col+1 < n --> col<n-1 | |
// row-1 >= 0 --> row>=1 --> row>0 | |
// col-1 >= 0 --> col>=1 --> col>0 | |
int main() { | |
int n, row = 0, col = 0, matrix[15][15] = {0}, step = 1; | |
printf("Enter n (n<=15): "); | |
scanf("%d", &n); | |
while (step <= n*n) { | |
// right | |
while(matrix[row][col] == 0) { | |
matrix[row][col] = step++; | |
col < n-1 && matrix[row][col+1] == 0 && ++col; | |
} | |
row++; // down one | |
// down | |
while(matrix[row][col] == 0) { | |
matrix[row][col] = step++; | |
row < n-1 && matrix[row+1][col] == 0 && ++row; | |
} | |
col--; // left one | |
// left | |
while(matrix[row][col] == 0) { | |
matrix[row][col] = step++; | |
col > 0 && matrix[row][col-1] == 0 && col--; | |
} | |
row--; // up one | |
// up | |
while(matrix[row][col] == 0) { | |
matrix[row][col] = step++; | |
row > 0 && matrix[row-1][col] == 0 && row--; | |
} | |
col++; // right one | |
} | |
for (row = 0; row < n; row++) { | |
for (col = 0; col < n; col++) { | |
printf("%5d", matrix[row][col]); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
This file contains 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
(setq url-proxy-services | |
'( | |
("http" . "127.0.0.1:7890") | |
("https" . "127.0.0.1:7890") | |
)) |
This file contains 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
import random | |
import string | |
"".join(random.sample(list(string.ascii_uppercase), 26)) |
This file contains 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
shuff = lambda s, steps: s[steps:] + s[0:steps] | |
if __name__ == '__main__': | |
import string | |
print(shuff(string.ascii_uppercase, 19)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment