Skip to content

Instantly share code, notes, and snippets.

View thebitbrine's full-sized avatar

TheBitBrine thebitbrine

View GitHub Profile
public string CleanText(string Input)
{
string res = Input.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace("\b", "");
if (res.StartsWith(' '))
res = res.Remove(0, 1);
if (res.EndsWith(' '))
res = res.Remove(res.Length - 1, 1);
while (res.Contains(" "))
@thebitbrine
thebitbrine / Configurizer.cs
Last active July 22, 2019 22:55
Gets configs.
public List<KeyValuePair<string, string>> Configurizer(string Path = "configs.conf")
{
var Configs = new List<KeyValuePair<string, string>>();
if (System.IO.File.Exists(Path))
{
string[] Lines = System.IO.File.ReadAllLines(Path);
foreach (string Line in Lines)
{
if (Line.Contains("="))
public string[] AddToArray(ref string[] Array, string Value)
{
System.Array.Resize(ref Array, Array.Length + 1);
Array[Array.Length - 1] = Value;
return Array;
}
@thebitbrine
thebitbrine / ParseMagnet.cs
Last active May 1, 2019 14:18
Parses magnet URI into an object.
public TorrentMetadata ParseMagnet(string Magnet)
{
var MD = new TorrentMetadata();
MD.URI = Magnet;
Magnet = Magnet.Replace("magnet:?", "");
var Parts = Magnet.Split('&');
foreach (var RawPart in Parts)
{
var Part = System.Net.WebUtility.UrlDecode(RawPart);
if (Part.StartsWith("xt=")) MD.InfoHash = Part.Split(':').Last().ToUpper();
internal static byte[] EncryptMessage(byte[] pMessage, ProtocolType pProtocolType)
{
List<byte> byteList = new List<byte>();
int num1 = 171;
if (pMessage != null && pMessage.Length != 0)
{
if (pProtocolType == ProtocolType.Tcp)
{
byteList.Add((byte)0);
byteList.Add((byte)0);
@thebitbrine
thebitbrine / GoogleWhatsMyIP.cs
Created April 29, 2019 13:10
Fetches external IP address from google.
public string GoogleWhatsMyIP()
{
var Response = new System.Net.WebClient() { Encoding = System.Text.Encoding.UTF8 }.DownloadString("https://www.google.am/search?q=whats+my+ip&hl=en");
var m = new System.Text.RegularExpressions.Regex("((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?![\\d])").Match(Response);
if (m.Success)
return m.Groups[1].ToString();
return null;
}
public string Base64Encode(string plainText)
{
Dictionary<char, int> Base64Table = new Dictionary<char, int>()
#region Table
{
{'+',62},
{'/',63},
{'0',52},
{'1',53},
{'2',54},
@thebitbrine
thebitbrine / GetChildNodeTexts.cs
Created March 28, 2019 23:16
Gets child nodes' text without removing spaces.
public string[] GetChildNodeTexts(HtmlNode Node)
{
List<string> OutputNodes = new List<string>();
var Nodes = Node.Descendants()
.Where(n => !n.HasChildNodes && n.InnerText != "\n" && !string.IsNullOrWhiteSpace(n.InnerText) &&
n.InnerText != "*")
.Select(n => n.InnerText.Replace("\n", "")).ToArray();
foreach (var InnerNode in Nodes)
{
if (!string.IsNullOrWhiteSpace(InnerNode.Replace("*", "")))
@thebitbrine
thebitbrine / BadRandom.cs
Created March 2, 2019 10:55
Bad random number generator for shuffling lists.
public long BadRandom()
{
List<char> Stack = new List<char>();
char[] Array = DateTime.Now.Ticks.ToString().ToArray();
Stack.Add(Array[int.Parse(Array.Last().ToString())]);
for (int i = 0; i < 17; i++)
{
Array = DateTime.Now.Ticks.ToString().ToArray();
Stack.Add(Array[int.Parse(Stack.ToArray().Last().ToString())]);
}
class IDatabase
{
public DataTable ReadTable(SQLiteConnection Connection, string TableName)
{
List<string> Data = new List<string>();
string Command = $"SELECT * FROM {TableName}";
SQLiteCommand SqliteCommand = new SQLiteCommand(Command, Connection);
SQLiteDataAdapter da = new SQLiteDataAdapter(SqliteCommand);
DataTable dt = new DataTable();
da.Fill(dt);