Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
VitorGoatman committed Mar 16, 2022
0 parents commit f2fd061
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 0 deletions.
24 changes: 24 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>
15 changes: 15 additions & 0 deletions aqcalc.nimble
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Package

version = "0.1.0"
author = "VitorGoatman"
description = "Calculate gematria values for Alphanumeric Qabbala"
license = "Unlicense"
srcDir = "src"
installExt = @["nim"]
bin = @["aqcalc"]


# Dependencies

requires "nim >= 1.6.4"
requires "docopt >= 0.6.7"
52 changes: 52 additions & 0 deletions src/aqcalc.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import strutils, docopt, db_sqlite, os, aqcalcpkg/aq

const doc = """
Aqqabala Calculator
Usage:
aqcalc <word>...
aqcalc --aqqa <word>...
aqcalc --revaq <number>...
Options:
-h, --help Show this message
--aqqa Save AQ result to local database. (~/.local/share/aqcalc)
--revaq Show all database entries that have this result.
"""

let
dbpath = getHomeDir() & ".local/share/aqcalc/"
db = open(dbpath & "entries.db", "", "", "")
args = docopt doc

discard existsOrCreateDir dbpath

proc writeDB(entry: string, aqres: int) =
let dbname = "aq" & $aqres
db.exec(sql("CREATE TABLE IF NOT EXISTS $# (id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, entry VARCHAR(250) UNIQUE);".format dbname))
db.exec(sql("INSERT OR IGNORE INTO $# (entry) VALUES ('$#');".format(dbname, entry)))

if isMainModule:
if args["--aqqa"]:
for word in @(args["<word>"]):
let aqres = word.aq
writeDB($word, aqres)
echo "AQ ", $aqres, " ="
for r in db.fastRows(sql("SELECT entry FROM $# ORDER BY entry".format("aq" & $aqres))):
echo " ", r[0]
elif args["--revaq"]:
for number in @(args["<number>"]):
try:
discard number.parseInt
except:
quit("Error: \"--revaq\" only accepts integers.", 1)

db.exec(sql("CREATE TABLE IF NOT EXISTS $# (id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, entry VARCHAR(250) UNIQUE);".format("aq" & $number)))
echo "AQ ", $number, " ="
for r in db.fastRows(sql("SELECT entry FROM $# ORDER BY entry".format("aq" & $number))):
echo " ", r[0]
else:
for word in @(args["<word>"]):
echo "AQ ",$word.aq, " = ", $word

db.close()
36 changes: 36 additions & 0 deletions src/aqcalcpkg/aq.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from strutils import Digits, parseInt

func aq*(input: string): int =
for c in input:
case c:
of Digits:
let cr: string = $c
result += cr.parseInt
of 'A','a': result += 10
of 'B','b': result += 11
of 'C','c': result += 12
of 'D','d': result += 13
of 'E','e': result += 14
of 'F','f': result += 15
of 'G','g': result += 16
of 'H','h': result += 17
of 'I','i': result += 18
of 'J','j': result += 19
of 'K','k': result += 20
of 'L','l': result += 21
of 'M','m': result += 22
of 'N','n': result += 23
of 'O','o': result += 24
of 'P','p': result += 25
of 'Q','q': result += 26
of 'R','r': result += 27
of 'S','s': result += 28
of 'T','t': result += 29
of 'U','u': result += 30
of 'V','v': result += 31
of 'W','w': result += 32
of 'X','x': result += 33
of 'Y','y': result += 34
of 'Z','z': result += 35
else: result += 0

1 change: 1 addition & 0 deletions tests/config.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
switch("path", "$projectDir/../src")
15 changes: 15 additions & 0 deletions tests/test1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This is just an example to get you started. You may wish to put all of your
# tests into a single file, or separate them into multiple `test1`, `test2`
# etc. files (better names are recommended, just make sure the name starts with
# the letter 't').
#
# To run these tests, simply execute `nimble test`.

import unittest

import aqcalcpkg/aq
test "hello":
check aq("Hello, World!") == 214

test "Zero":
check aq("###") == 0

0 comments on commit f2fd061

Please sign in to comment.