Skip to content

Commit 0261720

Browse files
committed
add interactive shell helpers
1 parent 05af191 commit 0261720

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

interactive

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/bash
2+
# run the library in an interactive mode for doing analysis
3+
php -a -d auto_prepend_file=./vendor/autoload.php
4+

src/helpers/helpers.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,36 @@ function array_searchi(string $needle, array $haystack)
155155
return array_search($needle, $localCopy);
156156
}
157157

158+
159+
/**
160+
* Load a book into memory
161+
* @param string $filename
162+
* @return string
163+
*/
164+
function gutenberg(string $filename) : string
165+
{
166+
return file_get_contents(get_storage_path("corpora/gutenberg").$filename);
167+
}
168+
169+
/**
170+
* Return a list of books available
171+
* @return array
172+
*/
173+
function gutenberg_list() : array
174+
{
175+
return scan_dir(get_storage_path("corpora/gutenberg/"));
176+
}
177+
178+
/**
179+
* Shortcut function for getting contents of directory
180+
* @param string $dir
181+
* @return array
182+
*/
183+
function scan_dir(string $dir) : array
184+
{
185+
return array_diff(scandir($dir), ['..', '.']);
186+
}
187+
188+
189+
190+

0 commit comments

Comments
 (0)