Skip to content

Instantly share code, notes, and snippets.

💭
🧘‍♂️

Ahmed Fasih fasiha

View GitHub Profile
@fasiha
fasiha / holdem.md
Last active Feb 3, 2019
Several four-player hands of hold ’em via https://github.com/fasiha/hold-em-tools
View holdem.md

1

Player 1

Percents rf sf qu fh fl st tr 2p pa hi
9c10c = hi <1 <1 <1 2 6 9 4 22 41 16
10c 9c× 5h Kc 6d = hi 0×0 <1×<1 0×<1 0×2 4×<1 3×5 1×4 8×21 47×47 36×21
10c 9c× 5h Kc 6d 6s = pa 0×0 0×0 0×<1 0×6 0×0 0×2 4×9 26×42 70×42 0×0
10c 9c× 5h Kc 6d 6s Jc = pa ×0 ×0 ×<1 ×3 ×0 ×0 ×7 ×39 ×52 ×0
@fasiha
fasiha / Ebisu-Java-Bare.ipynb
Created Nov 11, 2018
Very barebones Java implementation of Ebisu https://fasiha.github.io/ebisu/
View Ebisu-Java-Bare.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fasiha
fasiha / logSumExp.java
Last active Nov 9, 2018
LogSumExp, first cut in Java with Collections and lambdas. Port of https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.logsumexp.html
View logSumExp.java
//
// SUPPORT FUNCTIONS
// Via https://stackoverflow.com/a/32342172/500207
//
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import java.util.function.BiFunction;
<T> Stream<T> iteratorToFiniteStream(Iterator<T> iterator, boolean parallel) {
final Iterable<T> iterable = () -> iterator;
return StreamSupport.stream(iterable.spliterator(), parallel);
@fasiha
fasiha / enumerate.ts
Created Sep 23, 2018
TypeScript (and, for ES2015 and above, JavaScript) port of Python's `enumerate` to make index-value pairs.
View enumerate.ts
/**
* Generates `[index, value]` 2-tuples, so you can `for (let [index, value] of enumerate(v) {...})`.
* @param v array or iterable iterator to enumerate
* @param n starting number (defaults to 0)
*
* Hat tip: https://docs.python.org/3/library/functions.html#enumerate
*/
export function* enumerate<T>(v: T[]|IterableIterator<T>, n: number = 0): IterableIterator<[number, T]> {
for (let x of v) { yield [n++, x]; }
}
@fasiha
fasiha / bestGroupBy.ts
Last active Sep 21, 2018
bestGroupBy.ts
View bestGroupBy.ts
/**
* Like "groupBy", but only track the "best" group.
* @param arr Array of values
* @param grouper Mapper from elements of array to some group. Should be pure (it'll be called on first element twice).
* @param compare Compare two groups: if `compare(x, y) > 0`, then `x > y`, and similarly `=` and `<`.
* @return array containing the best group as first element, then the array of entries in that group.
*
* I only care about `compare`'s output's sign/zero, so it doesn't need to be a true distance.
*/
export function bestGroupBy<T, U>(arr: T[], grouper: (x: T) => U, compare: (x: U, y: U) => number): [U, T[]] {
@fasiha
fasiha / polly.sh
Created Sep 17, 2018
AWS Polly-aided text-to-speech, like, literally: a text file to numbered MP3 files.
View polly.sh
counter=1
cat input.txt | while read line; do
echo $counter $line
aws polly synthesize-speech --output-format mp3 --voice-id Takumi --text "$line" "$counter $line.mp3"
counter=$((counter+1))
sleep 0.5
done
@fasiha
fasiha / .gitignore
Last active Apr 16, 2019
Ahmed's Markdown data for Curtiz!
View .gitignore
node_modules/
*.bak
package-lock.json
@fasiha
fasiha / index.csv
Created Sep 14, 2018
WIP: Computer-parsable version of Masha Bell's "4,219 unpredictably spelt common words" http://englishspellingproblems.blogspot.com/2014/10/4219-unpredictably-spelt-common-words.html
View index.csv
CURRENT RESPELLING
have hav
meringue merang
plaid plad
plait plat
aunt ant/ahnt
draught draft/drahft
laugh laf/lahf
ale/ail ale
bale/bail bale
@fasiha
fasiha / xargsDemo.py
Last active Aug 24, 2018
Python demo for xargs-based command-line parallelization
View xargsDemo.py
USAGE = """
Python demo for `xargs`-based command-line parallelization.
Run this script as:
$ python [thisscript.py] [number]
for serial, single-argument execution. Then try:
$ seq -1 0.25 1 | xargs -I% -P2 -n1 python argsDemo.py % 100
@fasiha
fasiha / README.md
Created Aug 16, 2018
J.DepP usage and output example
View README.md

Example output

➜ echo あの壁にかかっている絵はきれいですね | mecab -d /usr/local/lib/mecab/dic/unidic | jdepp 2> /dev/null | to_tree.py
# S-ID: 1; J.DepP
  0:         あの━━┓
  1:   壁に━━┓     ┃
  2:  かかっている━━┓  ┃
  3:         絵は━━┫
  4:        きれいですねEOS
➜ echo あの壁にかかっている絵はきれいですね | mecab -d /usr/local/lib/mecab/dic/unidic | jdepp 2> /dev/null | to_chunk.py
You can’t perform that action at this time.