Skip to content

Instantly share code, notes, and snippets.

View jamiehowarth0's full-sized avatar

Jamie Howarth jamiehowarth0

View GitHub Profile
@jamiehowarth0
jamiehowarth0 / StringExtensions.cs
Created September 14, 2021 00:17
String to boolean conversion
public static class StringExtensions {
public static bool ToBoolean(this string str, bool bDefault = false) {
var BooleanStringOff = new[] { "0", "off", "no" };
if (string.IsNullOrEmpty(str)) return bDefault;
else if (BooleanStringOff.Contains(str, StringComparer.InvariantCultureIgnoreCase)) return false;
bool result;
if (!bool.TryParse(str, out result)) result = true;
return result;
}
}
# A crontab to turn pi-hole groups on and off at set times of day, Mon-Fri
# Replace <work group> and <personal group> with the names of your own groups that you've established.
# Both my groups are pinned to my laptop's IP, so enabling the "Work" list, which whitelists Google Analytics,
# only affects one device.
* 18 * * 1-5 root sqlite3 -line /etc/pihole/gravity.db "UPDATE [group] SET [enabled] = 0 WHERE [name] = '<work group>'; UPDATE [group] SET [enabled] = 1 WHERE [name] = '<personal group>';" && pihole restartdns reload-lists
* 9 * * 1-5 root sqlite3 -line /etc/pihole/gravity.db "UPDATE [group] SET [enabled] = 1 WHERE [name] = '<work group>'; UPDATE [group] SET [enabled] = 0 WHERE [name] = '<personal group>';" && pihole restartdns reload-lists
@jamiehowarth0
jamiehowarth0 / azure-pipelines.yml
Last active April 9, 2020 16:01
Umbraco Azure Pipelines web deploy template. Add to your git repository, updated variable placeholders, and off you go!
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- master
- develop
pool:
@jamiehowarth0
jamiehowarth0 / PiControls.psm1
Last active February 17, 2020 19:14
Turn on/off DHCP to re-route traffic via your router, instead of your Pi-Hole
function PiOn() {
$conn = Get-NetAdapter -physical | Where-Object Status -eq "Up"
Set-DnsClientServerAddress -InterfaceIndex $conn.InterfaceIndex -ResetServerAddresses
}
function PiOff() {
$conn = Get-NetAdapter -physical | Where-Object Status -eq "Up"
$gateway = Get-NetIpConfiguration | Foreach IPv4DefaultGateway | Select-Object NextHop
# This assumes the current gateway is your home router & your router still issues DHCP (instead of Pi-Hole).
# If it's not, then uncomment the following line and specify your router's IP address.
@jamiehowarth0
jamiehowarth0 / FixNvarcharContentInstallTask.cs
Created September 24, 2019 17:40
Potential fix for nvarchar/ntext Umbraco bug for Teacommerce
public class FixNvarcharContentInstallTask : AUmbracoDbInstallTask
{
public override void Install()
{
// Get all property types using the datatype
var datatype = ApplicationContext.Current.Services.DataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(
"TeaCommerce.VariantEditor").FirstOrDefault();
var allContentTypes = ApplicationContext.Current.Services.ContentTypeService.GetAllContentTypes();
var hasVariantPicker = allContentTypes.Where(ct => ct.PropertyTypes.Any(prop => prop.DataTypeDefinitionId == datatype.Id));
var propIds = hasVariantPicker.SelectMany(ct => ct.PropertyTypes)
@jamiehowarth0
jamiehowarth0 / wpt-post-reboot.ps1
Last active March 9, 2019 20:21
WPT agent installer for Windows using Powershell
pip install dnspython monotonic pillow psutil pypiwin32 requests ujson tornado marionette_driver selenium
cd $env:USERPROFILE
git clone https://github.com/WPO-Foundation/browser-install.git .\browser-install
git clone https://github.com/WPO-Foundation/wptagent.git .\wptagent
python .\browser-install\browser-install.py --all -vvvv
schtasks /delete /tn WPTPostInstall /f

Keybase proof

I hereby claim:

  • I am jamiehowarth0 on github.
  • I am jamiehowarth0 (https://keybase.io/jamiehowarth0) on keybase.
  • I have a public key ASC3Uo_2h4jCSkRsHZE1Gc4u4-pcQXGSiY3aSv5vemKujAo

To claim this, I am signing this object:

@jamiehowarth0
jamiehowarth0 / Find-RazorFilesWithAllJSFiles.ps1
Created August 16, 2018 02:49
Finds all the JS files in your ASP.NET project ready to then bundle them up using a tool like Webpack.
gci -Include "*.cshtml" -recurse | select -expand FullName | where { -not [string]::IsNullOrEmpty($_) } | foreach { Select-String -Path $_ -Pattern '~(.*\.js)' -AllMatches } | foreach {$_.Matches.Groups[1].Value} | Sort-Object | Get-Unique -AsString > .\alljs.txt
@jamiehowarth0
jamiehowarth0 / Sitemap-crawler.jmx
Created March 12, 2016 04:59
JMeter test plan
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.6" jmeter="2.11 r1554548">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
public static class IMediaServiceExtensions {
private const string UmbFile = "umbracoFile";
public static IMedia Copy(this IMediaService mediaService, IMedia media, IMedia newLocation, string newName = "") {
var properNewName = string.IsNullOrEmpty(newName) ? media.Name : newName;
var newMedia = (newLocation == null) ? mediaService.CreateMedia(properNewName, -1, media.ContentType.Alias)
: mediaService.CreateMedia(properNewName, newLocation, media.ContentType.Alias);
if (media.HasProperty(UmbFile)) {