File tree Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 7
7
Add your useful method here if you are contributing. Remember to add unit tests in tests.py :)
8
8
"""
9
9
10
+ if __name__ == "__main__" :
11
+ import setup_script
12
+ else :
13
+ from . import setup_script
14
+
15
+ setup_script .SETUP () # If you need any setup scripts, write them in setup_script.py.
16
+
10
17
def reverse_string (string ):
11
18
""" @hamdivazim - Reverses a string. """
12
19
@@ -79,4 +86,36 @@ def filter_by_condition(lst, condition: str):
79
86
for i in lst :
80
87
exec (f"if({ condition } ):result+=i" )
81
88
82
- return result
89
+ return result
90
+
91
+ def generate_random_string (word_length ):
92
+ components = [string .ascii_letters , string .digits , "!@#$%&" ]
93
+
94
+ chars = []
95
+
96
+ for clist in components :
97
+ for item in clist :
98
+ chars .append (item )
99
+
100
+ result = []
101
+
102
+ for i in range (word_length ):
103
+ rchar = random .choice (chars )
104
+ result .append (rchar )
105
+
106
+ return "" .join (result )
107
+
108
+ def generateUUID (version = 4 ):
109
+ if version < 1 or version > 5 :
110
+ raise ValueError (f"{ version } is not a valid UUID version number (valid values are 1-5)." )
111
+ else :
112
+ if version == 1 :
113
+ return uuid .uuid1 ()
114
+ elif version == 2 :
115
+ return uuid .uuid2 ()
116
+ elif version == 3 :
117
+ return uuid .uuid3 ()
118
+ elif version == 4 :
119
+ return uuid .uuid4 ()
120
+ elif version == 5 :
121
+ return uuid .uuid5 ()
Original file line number Diff line number Diff line change
1
+ """
2
+ usefulib v1.0
3
+ Copyright Hamd Waseem (https://github.com/hamdivazim) under the GNU Public License 3.0.
4
+
5
+ https://github.com/hamdivazim/usefulib
6
+
7
+ In case your script needs any form of setup (e.g. imports) write them here.
8
+ """
9
+
10
+ def SETUP ():
11
+ """ @hamdivazim - Import libs for generate_random_string() and generateUUID() """
12
+ import random
13
+ import string
14
+ import uuid
You can’t perform that action at this time.
0 commit comments