Skip to content

Instantly share code, notes, and snippets.

@AntMooreWebDev
AntMooreWebDev / StripHtml.cs
Last active August 2, 2016 08:25
[C#] Strip HTML From String
///////// Function implementation //////////
////////////////////////////////////////////
/// <summary>
/// This strips HTML from a string using regular expressions
/// </summary>
/// <param name="inputHtml">The string to be parsed</param>
/// <returns>text string void of HTML markup</returns>
private string StripHtml(string inputHtml)
{
@AntMooreWebDev
AntMooreWebDev / HideGoogleMapElementsForScreenshot.js
Last active November 2, 2016 13:58
This hides all elements on the Google Maps page with a class of "noprint". It also hides the Minimap and Popular Times sections, which are undesirable for screenshots.
// Run this in the browser console window to prep Google Maps for screenshotting.
javascript: (function(e, s) {
e.src = s;
e.onload = function() {
jQuery.noConflict();
jQuery('.noprint,#minimap,.section-popular-times').hide();
};
document.head.appendChild(e);
})(document.createElement('script'), '//code.jquery.com/jquery-latest.min.js')
@AntMooreWebDev
AntMooreWebDev / DebugCodeFirstMigration.cs
Created November 3, 2016 14:36
Throw this in the constructor of the configuration class for EF Code First migrations and the seed method can be debugged.
if (System.Diagnostics.Debugger.IsAttached == false)
{
System.Diagnostics.Debugger.Launch();
}
@AntMooreWebDev
AntMooreWebDev / CreateDynamicElement.js
Created February 8, 2017 16:44
A function to dynamically create a HTML element, with the ability to specify an on-click function.
function createEl (elType, elId, elClass, onClik, elText) {
return $('<' + elType + '>', {
id: elId,
'class': elClass,
text: elText,
on: {
click: onClik
}
});
}
@AntMooreWebDev
AntMooreWebDev / FadeVisibility.js
Last active February 21, 2017 17:15
Fades the visibility of a given element. Used to fade element on and off screen whilst maintaining element position and spacing.
// Fade In
$(myElem).css({opacity: 0.0, visibility: "visible"}).animate({opacity: 1.0});
// Fade Out
$(myElem).css({opacity: 1.0, visibility: "visible"}).animate({opacity: 0.0});
@AntMooreWebDev
AntMooreWebDev / UsefulStringLists.cs
Created March 30, 2017 10:55
A few handy lists of strings
List<char> a = "abcdefghijklmnopqrstuvwxyz".ToList(); // lowercase alphabet
List<char> b = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToList(); // uppercase alphabet
List<char> c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".ToList(); // both cases alphabet
List<char> d = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToList(); // both cases alphabet and integers
List<char> e = "abcdefghijklmnopqrstuvwxyz0123456789".ToList(); // lowercase alphabet and integers
List<char> f = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToList(); // uppercase alphabet and integers
@AntMooreWebDev
AntMooreWebDev / DuplicateVisualStudioExtensions.md
Last active May 9, 2017 13:21
Blog article on how to remove duplicate VS extensions
@AntMooreWebDev
AntMooreWebDev / SentenceExtractor.cs
Created May 23, 2017 10:08
This returns a list of sentences that contain a specified string.
public static List<String> SentenceExtractor(this string text, string word)
{
var sentences = text.Split(new[] { ". " }, StringSplitOptions.RemoveEmptyEntries);
var matches = from sentence in sentences
where sentence.ToLower().Contains(word.ToLower())
select sentence;
return matches.ToList();
}
@AntMooreWebDev
AntMooreWebDev / PreventWebConfigInheritance.config
Last active May 23, 2017 10:16
Wrap the location tag around the necessary Web.Config sections.
<!-- Path = "." denotes all paths -->
<!-- inheritInChildApplications = "false" prevents the inheritance -->
<location path="." inheritInChildApplications="false">
<!-- other elements here -->
</location>
@AntMooreWebDev
AntMooreWebDev / ExecuteSqlQuery.cs
Created July 20, 2017 13:46
How to execute a simple SQL query in C#
using(SqlConnection conn = new SqlConnection(connString))
using(SqlCommand command = new SqlCommand(query, conn))
using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
dataAdapter.Fill(results);
using (SqlConnection conn = new SqlConnection(connString))
{
conn.open();
using (SqlCommand command = new SqlCommand(query, conn))