Skip to content

Instantly share code, notes, and snippets.

View h3nryza's full-sized avatar

H3nryza h3nryza

View GitHub Profile
@h3nryza
h3nryza / hardDelete.py
Created July 17, 2018 16:39
Python Windows Permanently remove files
import os
filepath = r("c:\temp")
os.remove(filePath) # This just removes to recyclebin
os.unlink(filePath) # This removes without recyclebin
@h3nryza
h3nryza / temaplteClass.py
Created July 17, 2018 16:40
Simple python template for myself
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
try:
import platform_specific_module
except ImportError:
platform_specific_module = None
class NameOfClass(object):
@h3nryza
h3nryza / unicodeToString.py
Created July 17, 2018 16:41
Unicode to string (fix to coercing unicode to string error
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
uni = u'some unicode'
string = uni.encode("utf-8")
@h3nryza
h3nryza / argparse.py
Created July 17, 2018 16:41
Argparse example
#!/usr/bin/python
# -*- coding: <utf-8> -*-
from __future__ import print_function
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Description of what this does')
parser.add_argument("-c", "--configfile", dest="conf", help="Config file for something")
parser.add_argument("-f", "--flag", dest="bolFlag", action="store_true", help="Marks True if flag is used")
args = parser.parse_args()
@h3nryza
h3nryza / JsonSerializeDeserialize.py
Created July 17, 2018 16:42
Easy Json serialize / Deserialize in Python
#!/usr/bin/python
# -*- coding: <utf-8> -*-
from __future__ import print_function
import json
try:
from types import SimpleNamespace as Namespace
except ImportError:
# Python 2.x fallback
from argparse import Namespace
@h3nryza
h3nryza / hashesWithHashLib.py
Created July 17, 2018 16:45
Python hashes with Hashlib
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import hashlib
md = hashlib.md5(r"some text").hexdigest()
sha1 = hashlib.sha1(r"some text").hexdigest()
sha256 = hashlib.sha256(r"some text").hexdigest()
sha512 = hashlib.sha512(r"some text").hexdigest()
@h3nryza
h3nryza / aes.py
Created July 17, 2018 17:14
Python aes cryptography with pycryptodome or pycrypto
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
from Crypto.Cipher import AES
from Crypto import Random
from pkcs7 import PKCS7Encoder
import base64
#Encrypt Aes
#Get the key, iv from random, generate aes for encryption
@h3nryza
h3nryza / RSAgenkeys.py
Created July 17, 2018 17:17
RSA with pycryptodome
from Crypto.PublicKey import RSA
key = RSA.generate(2048)
private_key = key.export_key()
file_out = open("private.pem", "wb")
file_out.write(private_key)
public_key = key.publickey().export_key()
file_out = open("receiver.pem", "wb")
file_out.write(public_key)
@h3nryza
h3nryza / SqlQueryEverything.sql
Created July 17, 2018 17:18
Query all data in Sql with ease
-- SQL Script to capture the database table structure
select
[table_name] as [Table Name],
[column_name] as [Column Name],
case [data_type]
when 'varchar' then [data_type] + '(' + cast([character_maximum_length] as varchar) + ')'
when 'nvarchar' then [data_type] + '(' + cast([character_maximum_length] as nvarchar) + ')'
else [data_type]
end as [Data Type],
case [is_nullable]
@h3nryza
h3nryza / SqlQueryEverything.sql
Created July 17, 2018 17:18
Query all data in Sql with ease
-- SQL Script to capture the database table structure
select
[table_name] as [Table Name],
[column_name] as [Column Name],
case [data_type]
when 'varchar' then [data_type] + '(' + cast([character_maximum_length] as varchar) + ')'
when 'nvarchar' then [data_type] + '(' + cast([character_maximum_length] as nvarchar) + ')'
else [data_type]
end as [Data Type],
case [is_nullable]