Skip to content

Instantly share code, notes, and snippets.

@chancyk
Last active August 12, 2017 01:27
Show Gist options
  • Save chancyk/4a0440897b5875cd3c2c84c9d2094454 to your computer and use it in GitHub Desktop.
Save chancyk/4a0440897b5875cd3c2c84c9d2094454 to your computer and use it in GitHub Desktop.
ponylang: Glob
use "time"
use "files"
use "glob"
actor Main
new create(env: Env) =>
let caps = recover val FileCaps.>set(FileRead).>set(FileStat).>set(FileLookup) end
try
let search_path = env.args(1)?
let search_pattern = env.args(2)?
let file_path = FilePath(env.root as AmbientAuth, search_path, caps)?
env.out.print("Searching: " + search_path + "/" + search_pattern)
let files = recover Glob.glob(file_path, search_pattern) end
LineCounter(consume files)
else
env.out.print("Failed to initialize search.")
end
actor LineCounter
let _files: Array[FilePath] iso
new create(files: Array[FilePath] iso) =>
_files = consume files
be count_all_files() =>
var total_line_count: U32 = 0
var file_count: U32 = 0
var total_time: U64 = 0
for fp in _files.values() do
var line_count: U32 = 0
let t0: U64 = Time.millis()
with file = OpenFile(fp) as File do
for line in file.lines() do
line_count = line_count + 1
end
end
let t1: U64 = Time.millis()
total_time = total_time + (t1 - t0)
total_line_count = total_line_count + line_count
file_count = file_count + 1
end
// env.out.print("File count: " + file_count.string())
// env.out.print("Total lines: " + total_line_count.string())
// env.out.print("Elapsed: " + total_time.string())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment