Skip to content

Instantly share code, notes, and snippets.

View csharpforevermore's full-sized avatar
💭
Developing

Randle csharpforevermore

💭
Developing
View GitHub Profile
@csharpforevermore
csharpforevermore / IsPangram.js
Created April 3, 2020 10:23
JavaScript - checks string is a pangram (contains every letter of the alphabet at least once)
function isPangram(string){
return (string.match(/([a-z])(?!.*\1)/ig) || []).length === 26;
}
@csharpforevermore
csharpforevermore / Rename-Files.ps1
Created February 27, 2020 18:28 — forked from auberginehill/Rename-Files.ps1
A Windows PowerShell script for renaming files.
<#
Rename-Files.ps1
#>
# Find all wmv-files with a string "oldstring" and replace "oldstring" with "newstring" in the filename
Get-ChildItem *.wmv -Filter "*oldstring*" | ForEach { Rename-Item $_ -NewName $_.Name.Replace("oldstring","newstring") }
# Change the file extension of all .jpeg files to .jpg
@csharpforevermore
csharpforevermore / youtube-hidewatchedvideos.js
Created February 26, 2020 15:42
Hide watched YouTube videos
// example data
var selector = '.ytd-thumbnail-overlay-resume-playback-renderer'; // CSS selector for red bar indicating video has been watched
var exampleUrl = 'https://www.youtube.com/channel/UCN64HIrZNqFQYZ2BuyY-4zg'; // example URL for text
var jQueryInjectorExtension = 'https://chrome.google.com/webstore/detail/jquery-injector/ekkjohcjbjcjjifokpingdbdlfekjcgi?hl=en'; // url for chrome extension to inject jQuery into page for code below to run
$(selector)
.parent() // ytd-thumbnail-overlay-resume-playback-renderer.style-scope.ytd-thumbnail
.parent() // div#overlays.style-scope.ytd-thumbnail
.parent() // a#thumbnail.yt-simple-endpoint.inline-block.style-scope.ytd-thumbnail
.parent() // ytd-thumbnail.style-scope.ytd-grid-video-renderer
@csharpforevermore
csharpforevermore / SetOwnerPermission.ps1
Created February 21, 2020 13:07
Powershell - set all rights to administrator
# Define the owner account/group
$Account = New-Object -TypeName System.Security.Principal.NTAccount -ArgumentList 'BUILTIN\Administrators';
# Get a list of folders and files
$ItemList = Get-ChildItem -Path D:\Applications\Leafletdrop.Q4CmsChange\Media\Default -Recurse;
# Iterate over files/folders
foreach ($Item in $ItemList) {
$Acl = $null; # Reset the $Acl variable to $null
$Acl = Get-Acl -Path $Item.FullName; # Get the ACL from the item
@csharpforevermore
csharpforevermore / AddUserPermissionsForIIS.ps1
Created February 21, 2020 13:06
Powershell script to add 3 roles to files and folders in a set location
cls
# Define the owner account/group
$Account = New-Object -TypeName System.Security.Principal.NTAccount -ArgumentList 'Everyone';
$Source = 'D:\Applications\Leafletdrop.Q4CmsChange'
# Get a list of folders and files
$ItemList = Get-ChildItem -Path $Source -Recurse;
@csharpforevermore
csharpforevermore / TruncateToSentence.cs
Created December 16, 2019 17:16
Truncate a paragraph back to last full sentence
var s = "An example. Another example. This is omitted";
s = s?.Substring(0, s.LastIndexOf(". ")+2); // cuts back to last full sentence
@csharpforevermore
csharpforevermore / TruncateToSentence.cs
Created December 16, 2019 17:16
Truncate a paragraph back to last full sentence
var s = "An example. Another example. This is omitted";
s = s?.Substring(0, Math.Min(s.Length, Model.NewsMaxChars));
s = s?.Substring(0, s.LastIndexOf(". ")+2); // cuts back to last full sentence
@csharpforevermore
csharpforevermore / Controller.js
Created December 6, 2019 12:10
Why is this Property Value Converter still having Umbraco v8.3.0 ModelsBuilder output type of 'object' rather than 'bool'
angular.module('umbraco').directive('switch', function () {
return {
restrict: 'AE',
replace: true,
transclude: true,
template: function (element, attrs) {
var html = '';
html += '<span';
html += ' class="switcher' + (attrs.class ? ' ' + attrs.class : '') + '"';
html += attrs.ngModel ? ' ng-click="' + attrs.ngModel + '=!' + attrs.ngModel + '"' : '';
@csharpforevermore
csharpforevermore / GetMouseClickDifference.js
Created October 13, 2019 21:15
Get which mouse button was clicked (left, middle or right) using jQuery
$('#element').mousedown(function(event) {
switch (event.which) {
case 1:
alert('Left Mouse button pressed.');
break;
case 2:
alert('Middle Mouse button pressed.');
break;
case 3:
alert('Right Mouse button pressed.');
HttpContextBase wrapper = new HttpContextWrapper(HttpContext.Current);
UmbracoBackOfficeIdentity user = wrapper.GetCurrentIdentity(true);
bool isLoggedIn = user != null;