Skip to content

Instantly share code, notes, and snippets.

View h3nryza's full-sized avatar

H3nryza h3nryza

View GitHub Profile
@h3nryza
h3nryza / sqlTableDiskSpace.sql
Created July 17, 2018 17:21
Sql return table disk space
SELECT
t.NAME AS TableName,
s.Name AS SchemaName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,
CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
@h3nryza
h3nryza / returnIPFromInteger.sql
Created July 17, 2018 17:21
SQL Return ip address from integer
CREATE FUNCTION dbo.IntegerToIPAddress (@IP AS bigint)
RETURNS varchar(15)
AS
BEGIN
DECLARE @Octet1 tinyint
@h3nryza
h3nryza / SqlDates.sql
Created July 17, 2018 17:20
Sql Dates
--SQL Round to nearest Minute
select dateadd(mi, datediff(mi, 0, @dt), 0)
--Sql Round to Nearest Hour
select dateadd(hour, datediff(hour, 0, @dt), 0)
--Sql Last day of week
first day - last day
--Sql First Day of Week
@h3nryza
h3nryza / ipAddress.sql
Created July 17, 2018 17:19
Substring of IP Address in Sql
SQL Calculate IP Subnet
(charindex ( '.' , CMP.IPAddress ,charindex( '.' , CMP.IPAddress ,(charindex('.',CMP.IPAddress) +1 ) ) +1)-1)
SQL Spit out SQL Subnet
SUBSTRING(
CMP.IPAddress,
0,
(charindex ( '.' , CMP.IPAddress ,charindex( '.' , CMP.IPAddress ,(charindex('.',CMP.IPAddress) +1 ) ) +1))
)
@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]
@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 / 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 / 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 / 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