-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from Jonak-Adipta-Kalita/main
surprise surprise (the c pr)
- Loading branch information
Showing
7 changed files
with
97 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,13 +13,17 @@ jobs: | |
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.12.3" | ||
- name: Install GCC | ||
uses: egor-tensin/[email protected] | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools wheel twine | ||
- name: Build and Publish | ||
env: | ||
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} | ||
run: | | ||
gcc -fPIC -shared -o flomo\session_id.so flomo\session_id.c | ||
python setup.py sdist bdist_wheel | ||
twine upload dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
include docs/README.md | ||
include LICENSE | ||
include flomo/beep.mp3 | ||
include flomo/session_id.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <limits.h> | ||
|
||
const char ALPHANUMERIC[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ||
const int BASE = 62; | ||
|
||
char *encode_timestamp(unsigned long long timestamp) | ||
{ | ||
char *encoded = (char *)malloc((sizeof(timestamp) * CHAR_BIT + 5) / 6 + 1); | ||
int index = 0; | ||
|
||
if (timestamp == 0) | ||
{ | ||
encoded[index++] = ALPHANUMERIC[0]; | ||
} | ||
|
||
do | ||
{ | ||
int rem = timestamp % BASE; | ||
encoded[index++] = ALPHANUMERIC[rem]; | ||
timestamp /= BASE; | ||
} while (timestamp > 0); | ||
|
||
for (int i = 0; i < index / 2; i++) | ||
{ | ||
char temp = encoded[i]; | ||
encoded[i] = encoded[index - i - 1]; | ||
encoded[index - i - 1] = temp; | ||
} | ||
|
||
encoded[index] = '\0'; | ||
return encoded; | ||
} | ||
|
||
unsigned long long decode_timestamp(const char *encoded) | ||
{ | ||
unsigned long long timestamp = 0; | ||
size_t length = strlen(encoded); | ||
|
||
for (size_t i = 0; i < length; i++) | ||
{ | ||
char *ptr = strchr(ALPHANUMERIC, encoded[i]); | ||
if (ptr) | ||
{ | ||
int index = ptr - ALPHANUMERIC; | ||
timestamp = timestamp * BASE + index; | ||
} | ||
else | ||
{ | ||
fprintf(stderr, "Error: Invalid character '%c' in encoded string.\n", encoded[i]); | ||
return 0; | ||
} | ||
} | ||
|
||
return timestamp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters