Skip to content

Instantly share code, notes, and snippets.

View asquigglytwist's full-sized avatar
💭
Here we go, again!!!

ASquigglyTwist asquigglytwist

💭
Here we go, again!!!
  • Devil's WorkShop
View GitHub Profile
@asquigglytwist
asquigglytwist / FileLocker.hpp
Last active April 25, 2020 10:02
File locking in Windows
#pragma once
#ifndef FILELOCKER_H
#define FILELOCKER_H
#include <Windows.h>
#include <string>
#include <tchar.h>
#include <iostream>
#if UNICODE
@asquigglytwist
asquigglytwist / PreFlightCheck.hpp
Last active April 25, 2020 09:52
Perform PreFlight Checks (like Min OS, Min RAM, Min FreeDiskSpace) on Windows - typically performed before any business logic.
#pragma once
#ifndef PREFLIGHTCHECK_HPP
#define PREFLIGHTCHECK_HPP
/* References for this implementation:
https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-globalmemorystatusex
https://stackoverflow.com/questions/20119643/stringizing-operator-in-c-c
https://stackoverflow.com/questions/46794133/how-to-perform-arthemetic-with-ularge-integer
*/
#include "stdafx.h"
#include <Windows.h>
@asquigglytwist
asquigglytwist / InferenceEngine.js
Last active April 22, 2018 19:45
An independent library for parsing and inferring from content within a web-page. (https://asquigglytwist.github.io/JSUtils/InferenceEngine/)
class InferenceTest {
matches(nodeContent) {
throw new TypeError('This method should be overridden by inheriting classes.');
}
get parsedValue() {
throw new TypeError('This method should be overridden by inheriting classes.');
}
}
class IsEmpty extends InferenceTest {
@asquigglytwist
asquigglytwist / DirInfo.cs
Last active April 4, 2018 09:12
A few helper functions for assisting with operations on a Directory.
public static List<string> GetFileNamesWithoutExtensionAsList(string dir, string pattern)
{
if (Directory.Exists(dir))
{
return new DirectoryInfo(dir).GetFiles(pattern, SearchOption.TopDirectoryOnly)
.Select(file => Path.GetFileNameWithoutExtension(file.Name)).ToList();
}
return new List<string>();
}
@asquigglytwist
asquigglytwist / SaveToXML.cs
Last active April 4, 2018 09:13
Save info to an XML doc.
var xDoc = new XmlDocument();
var declarationNode = xDoc.CreateXmlDeclaration("1.0", "", "");
xDoc.AppendChild(declarationNode);
var comment = xDoc.CreateComment(string.Format("This file contains information about {0} - {1}", BookName, BookName));
xDoc.AppendChild(comment);
var docRoot = xDoc.CreateElement("Books");
XmlNode ndBookISBN = xDoc.CreateElement("BookISBNCode"),
ndBookName = xDoc.CreateElement("BookName"),
ndAuthorName = xDoc.CreateElement("AuthorName"),
ndReleaseDate = xDoc.CreateElement("ReleaseDate");
@asquigglytwist
asquigglytwist / LINQParseXMLDoc.cs
Created April 4, 2018 08:32
Parse XML Document using LINQ
var xDoc = XDocument.Load(filePath);
string bookISBN = xDoc.Descendants("BookISBNCode").First().Value,
bookName = xDoc.Descendants("BookName").First().Value,
authorName = xDoc.Descendants("AuthorName").First().Value,
releaseDate = xDoc.Descendants("ReleaseDate").First().Value;
@asquigglytwist
asquigglytwist / CSV2HTMLTable.cs
Last active April 4, 2018 09:13
A gazillionth implementation of a CSV Parser in C#...
public string ToHTMLTable(string CSVFilePath, string tableCaption)
{
if (!File.Exists(CSVFilePath))
{
return "<div>--CSV file not found--</div>";
}
var sbHTable = new StringBuilder();
var curLine = string.Empty;
sbHTable.AppendFormat("<table><caption>{0}</caption>", tableCaption);
foreach (var line in File.ReadLines(CSVFilePath))
@asquigglytwist
asquigglytwist / PublicTweetsRetriever.js
Last active April 4, 2018 09:14
Retrieve public tweets from user's timeline page
document.querySelectorAll("#timeline .stream ol#stream-items-id li div.content div.js-tweet-text-container")