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 math | |
# 1, 2, 3, .. 26, 27, ... -> 'a', 'b', 'c', .. 'z', 'aa', ... | |
def to_row_code(row_index): | |
prefix = '' | |
if row_index > 26: | |
prefix = to_row_code(math.ceil((row_index - 26) / 26)) | |
return prefix + chr(ord('a') + (row_index - 1) % 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
import math | |
import itertools | |
# Tested with dictionary from github.com/dwyl/english-words | |
WORDS_DICT_FILENAME = 'words_dictionary.json' | |
__dict = None | |
def get_valid_words(): | |
global __dict | |
if __dict: |
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
// matrix -- a 1D array, that stores matrix A[rows,columns] by rows | |
// i.e. [A[0,0],A[0,1],..,A[0,columns-1],A[1,0],A[1,1],..,A[1,columns-1],..] | |
// rows -- number of rows in A | |
// columns -- number of columns in A | |
function transpose(matrix, rows, columns) { | |
// Let's write down some index conversion functions. | |
// You can convert 1D array index to | |
// (rows*columns) matrix index like that | |
const C = k => [Math.floor(k / columns), k % columns] | |
// You can do the reverse this way: |
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
# Create a new bare repo. | |
cd origin-parh | |
mkdir repo.git | |
cd repo.git | |
git --bare init | |
# Make an already existing repo bare. | |
cd origin-parh | |
mkdir repo | |
cd repo |
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
# count lines in all inner js files of a project | |
cat `find . | grep -v 'node_modules' | grep '.*.js$'` | wc -l | |
# list all the js files that contain a word | |
grep -v 'node_modules' | grep '.*.js$' | xargs grep 'SEARCHWORD' -l |
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
const LINE_WIDTH = 80 // 150 | |
const CONTINUATION_PROBABILITY = 0.9 | |
const FRAMERATE = 100 | |
console.log('\x1b[32m') // green text | |
console.log('\x1b[40m') // black bg | |
let line = [] | |
for (let i = 0; i < LINE_WIDTH / 2; ++i) { | |
line.push(false) |
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
// Indentation unit: predicate components are indented with this string, | |
// repeated several times, depending on their nesting level. | |
// Use '' for no identation. | |
const DEFAULT_INDENT_STR = ' ' | |
// All lines end with this string; predicates on the top level | |
// are separated with twice this string. | |
// Use ' ' for a one-line output ('' won't lead to valid predicates). | |
const DEFAULT_LINE_ENDING = '\n' | |
// An s-list shorter than this would be a one-liner. | |
// This number is not exact, though (see `estimatedLength`). |
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
#!/bin/bash | |
mkdir results | |
for image in *.jpg | |
do | |
convert -colorspace Gray -interlace Plane -gaussian-blur 0.05 -quality 50% $image ./results/$image | |
done |
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
let oneWayCapacity a = | |
let mutable max = 0 | |
a |> List.map (fun e -> if e > max then max <- e; 0 else max - e) | |
let totalCapacity a = | |
let aL = a |> oneWayCapacity | |
let aR = a |> List.rev |> oneWayCapacity |> List.rev | |
List.map2 min aL aR |> List.sum | |