Skip to content

Commit 2ff999e

Browse files
committed
update NSC to v2.3
1 parent 199846e commit 2ff999e

File tree

11 files changed

+37
-29
lines changed

11 files changed

+37
-29
lines changed
185 Bytes
Binary file not shown.

Sources/Workflows/nsc/README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# NSC
22
*Number System Converter -- an [Alfred](http://www.alfredapp.com/) extension*
3-
* * *
3+
* * *
44

55
**Author:** [Hans-Helge Bürger](http://www.hanshelgebuerger.de "Hans-Helge Bürger - Webpage")
6-
**Date:** 07. May 2013
7-
**Version:** v2.1
6+
**Date:** 04. December 2015
7+
**Version:** v2.3
88
**Licence:** [Attribution 3.0 Unported (CC BY 3.0)](http://creativecommons.org/licenses/by/3.0/ "Attribution 3.0 Unported (CC BY 3.0)")
99

1010
## Quick Installation
11-
### Download [NSC v2.1](https://github.com/obstschale/NSC/raw/alfredextension/nsc-v2.1.alfredworkflow)
11+
### Download [NSC v2.3](https://github.com/obstschale/NSC/raw/alfredextension/nsc-v2.3.alfredworkflow)
1212

1313

1414
---
@@ -63,23 +63,29 @@ Another cool feature of Alfred 2 is that you can pass arguments to other parts o
6363

6464
* `hex FF2` → result: D: 4082 // B: 111111110010 // O: 7762
6565

66-
* `convert 119 11 3` → result: D: 141 // Base 3: 12020
66+
* `convert 119 11 3` → result: D: 141 // Base 3: 12020
6767

6868
---
6969

7070
## Changelog
71+
### v2.3
72+
* add: `+` and `/` to alphabeth for converting up to base 64. Props to @sycrat #4
73+
74+
### v2.2
75+
* add: display binary numbers w/ at least 8 digits
76+
* add: display hex in uppercase
77+
thx to [akupila](https://github.com/akupila)
78+
7179
### v.2.1
7280
* add: conversion upto base 62 (case-sensitive letters if base is greater than 35)
7381
* add: add info.plist to repo
74-
* add: all scripts uses now [alp](https://github.com/phyllisstein/alp) to generate XML feedback
82+
* add: all scripts uses now [alp](https://github.com/phyllisstein/alp) to generate XML feedback
7583

7684
### v2.01
7785
* bug: base 1 led into an infinite loop (thx to [@kevinlsw](https://github.com/kevinlsw) | [#2](https://github.com/obstschale/NSC/issues/2))
7886
* add: new int2base function which uses now letters as input/output within `convert`
7987
* add: NSC uses [alp](https://github.com/phyllisstein/alp) to generate XML feedback
8088

81-
82-
8389
### v2.0
8490
* NSC is now an Alfred Workflow and works with Alfred 2
8591
* add: convert from/into decimal, binary, octal, hex
591 Bytes
Binary file not shown.

Sources/Workflows/nsc/alp/core.pyc

4.44 KB
Binary file not shown.

Sources/Workflows/nsc/alp/item.pyc

3.02 KB
Binary file not shown.

Sources/Workflows/nsc/convertBinary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
# calculate hex number
21-
hexadec = hex(decimal)[2:]
21+
hexadec = hex(decimal)[2:].upper()
2222
# create associative array and create xml from it
2323
hexDic = dict(title=str(hexadec), subtitle="Hexadecimal", uid="hex", valid=True, arg=str(hexadec), icon="icons/hex.png")
2424
h = alp.Item(**hexDic)

Sources/Workflows/nsc/convertDecimal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import alp
55

66
# calculate binary number
7-
binary = bin(int(sys.argv[1]))[2:]
7+
binary = bin(int(sys.argv[1]))[2:].zfill(8)
88
# create associative array and create xml from it
99
binaryDic = dict(title=str(binary), subtitle="Binary", uid="binary", valid=True, arg=str(binary), icon="icons/binary.png")
1010
b = alp.Item(**binaryDic)
@@ -17,7 +17,7 @@
1717

1818

1919
# calculate hex number
20-
hexadec = hex(int(sys.argv[1]))[2:]
20+
hexadec = hex(int(sys.argv[1]))[2:].upper()
2121
# create associative array and create xml from it
2222
hexDic = dict(title=str(hexadec), subtitle="Hexadecimal", uid="hex", valid=True, arg=str(hexadec), icon="icons/hex.png")
2323
h = alp.Item(**hexDic)

Sources/Workflows/nsc/convertHex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
# calculate binary number
14-
binary = bin(decimal)[2:]
14+
binary = bin(decimal)[2:].zfill(8)
1515
# create associative array and create xml from it
1616
binaryDic = dict(title=str(binary), subtitle="Binary", uid="binary", valid=True, arg=str(binary), icon="icons/binary.png")
1717
b = alp.Item(**binaryDic)

Sources/Workflows/nsc/convertNumber.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import sys
1111
import alp
1212
import string
13-
ALPHA = string.digits + string.uppercase + string.lowercase
13+
ALPHA = string.digits + string.uppercase + string.lowercase + '+' + '/'
1414

15-
def base62_encode(num, base, alphabet=ALPHA):
15+
def base64_encode(num, base, alphabet=ALPHA):
1616
"""Encode a number in Base X
1717
1818
`num`: The number to encode
@@ -29,7 +29,7 @@ def base62_encode(num, base, alphabet=ALPHA):
2929
arr.reverse()
3030
return ''.join(arr)
3131

32-
def base62_decode(string, base, alphabet=ALPHA):
32+
def base64_decode(string, base, alphabet=ALPHA):
3333
"""Decode a Base X encoded string into the number
3434
3535
Arguments:
@@ -52,12 +52,14 @@ def base62_decode(string, base, alphabet=ALPHA):
5252
if (len(sys.argv) == 4 and sys.argv[3] != "1"):
5353
# calculate integer first
5454
if (int(sys.argv[2]) <= 36):
55+
# use built in python conversion if possible
5556
decimal = int(sys.argv[1], int(sys.argv[2]))
56-
elif (int(sys.argv[2]) > 36 and int(sys.argv[2]) <= 62):
57-
decimal = base62_decode(sys.argv[1], int(sys.argv[2]))
57+
elif (int(sys.argv[2]) > 36 and int(sys.argv[2]) <= 64):
58+
# otherwise, use base64_decode
59+
decimal = base64_decode(sys.argv[1], int(sys.argv[2]))
5860
else:
5961
# create dictionary to create xml from it
60-
errorDic = dict(title="Ohoh, your number couldn't be converted", subtitle="make sure your base is between 2 and 62", uid="error", valid=False)
62+
errorDic = dict(title="Ohoh, your number couldn't be converted", subtitle="make sure your base is between 2 and 64", uid="error", valid=False)
6163
e = alp.Item(**errorDic)
6264
alp.feedback(e)
6365
sys.exit()
@@ -67,11 +69,11 @@ def base62_decode(string, base, alphabet=ALPHA):
6769
d = alp.Item(**decimalDic)
6870

6971
# calculate new number
70-
if (int(sys.argv[3]) >= 2 and int(sys.argv[3]) <= 62):
71-
conv = base62_encode(decimal, int(sys.argv[3]))
72+
if (int(sys.argv[3]) >= 2 and int(sys.argv[3]) <= 64):
73+
conv = base64_encode(decimal, int(sys.argv[3]))
7274
else:
7375
# create dictionary to create xml from it
74-
errorDic = dict(title="Ohoh, your number couldn't be converted", subtitle="make sure your base is between 2 and 62", uid="error", valid=False)
76+
errorDic = dict(title="Ohoh, your number couldn't be converted", subtitle="make sure your base is between 2 and 64", uid="error", valid=False)
7577
e = alp.Item(**errorDic)
7678
itemsList = [d, e]
7779
alp.feedback(itemsList)
@@ -92,11 +94,11 @@ def base62_decode(string, base, alphabet=ALPHA):
9294
alp.feedback(itemsList)
9395

9496
else:
95-
if (int(sys.argv[3]) == 1):
96-
errorDic = dict(title="Base 1 makes no sense", subtitle="", uid="error", valid=False, arg="error")
97+
if (len(sys.argv) != 4):
98+
errorDic = dict(title="Make sure to pass 3 numbers", subtitle="convert `number` `base of original` `base to convert to`", uid="error", valid=False, arg="error")
9799
error = alp.Item(**errorDic)
98100
alp.feedback(error)
99-
else:
100-
errorDic = dict(title="Make sure to pass 3 numbers", subtitle="for help type \"nsc help\"", uid="error", valid=False, arg="error")
101+
elif (int(sys.argv[3]) == 1):
102+
errorDic = dict(title="Base 1 makes no sense", subtitle="", uid="error", valid=False, arg="error")
101103
error = alp.Item(**errorDic)
102104
alp.feedback(error)

Sources/Workflows/nsc/convertOctal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212

1313
# calculate binary number
14-
binary = bin(decimal)[2:]
14+
binary = bin(decimal)[2:].zfill(8)
1515
# create associative array and create xml from it
1616
binaryDic = dict(title=str(binary), subtitle="Binary", uid="binary", valid=True, arg=str(binary), icon="icons/binary.png")
1717
b = alp.Item(**binaryDic)
1818

1919

2020
# calculate hex number
21-
hexadec = hex(decimal)[2:]
21+
hexadec = hex(decimal)[2:].upper()
2222
# create associative array and create xml from it
2323
hexDic = dict(title=str(hexadec), subtitle="Hexadecimal", uid="hex", valid=True, arg=str(hexadec), icon="icons/hex.png")
2424
h = alp.Item(**hexDic)

0 commit comments

Comments
 (0)