Skip to content

Instantly share code, notes, and snippets.

View u01jmg3's full-sized avatar
🔷
Coding Hard

Jonathan Goode u01jmg3

🔷
Coding Hard
View GitHub Profile
@u01jmg3
u01jmg3 / bluetooth.ps
Created May 17, 2020 09:52
Windows Powershell Script to Toggle Bluetooth On or Off
[CmdletBinding()] Param (
[Parameter()][ValidateSet('On', 'Off')][string]$BluetoothStatus
)
If ((Get-Service bthserv).Status -eq 'Stopped') { Start-Service bthserv }
Add-Type -AssemblyName System.Runtime.WindowsRuntime
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
Function Await($WinRtTask, $ResultType) {
$asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
$netTask = $asTask.Invoke($null, @($WinRtTask))
$netTask.Wait(-1) | Out-Null
@u01jmg3
u01jmg3 / alias.cmd
Last active November 8, 2023 10:30
Pimp up the Windows command prompt
@echo off
:: Clear Microsoft version notice displayed by an
:: Administrator CMD & shells opened by Fork
cls
:: Enable unicode support
chcp 65001 >NUL
if exist .\laravel cd laravel
@u01jmg3
u01jmg3 / rector-codeigniter.php
Last active April 14, 2023 12:29
Rector configs
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Php53\Rector\Ternary\TernaryToElvisRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@u01jmg3
u01jmg3 / .htaccess
Last active March 30, 2023 13:28
Maintenance Mode
<IfModule mod_rewrite.c>
RewriteEngine On
<IfModule mod_env.c>
# Scheduled Maintenance
RewriteRule ^ - [E=MAINTENANCE_DATE:False]
RewriteCond %{TIME_YEAR}%{TIME_MON}%{TIME_DAY} 20230509 [OR]
RewriteCond %{TIME_YEAR}%{TIME_MON}%{TIME_DAY} 20230523 [OR]
RewriteCond %{TIME_YEAR}%{TIME_MON}%{TIME_DAY} 20230613 [OR]
RewriteCond %{TIME_YEAR}%{TIME_MON}%{TIME_DAY} 20230627 [OR]
  • Exclude dirs: .git|node_modules|vendor|storage|framework7|laravel-framework|cache|database|third_party|wedding
  • File Names match: *.ahk|*env*|*.js|*.md|*.php*|*css|*.xml|*.html|*.json|artisan|*.vue|*config|*access|*.bat|*.yml|*.ics|*.csv|*.xml|*.log|-*lock.*|*.svg|*.yaml|*.ini|*.tpl
@u01jmg3
u01jmg3 / stylelint.txt
Created February 21, 2023 15:17
Stylelint v15 Deprecation Warnings - Switch to Prettier
block-closing-brace-empty-line-before
block-closing-brace-newline-after
block-closing-brace-newline-before
block-closing-brace-space-after
block-closing-brace-space-before
block-opening-brace-newline-after
block-opening-brace-newline-before
block-opening-brace-space-after
block-opening-brace-space-before
color-hex-case
@u01jmg3
u01jmg3 / session-readonly.php
Created October 21, 2016 12:14
Session locking - non-blocking read-only sessions in PHP
<?php
function session_readonly(){
if(version_compare(PHP_VERSION, '7.0.0') >= 0){
session_start(array('read_and_close' => true));
} else {
$session_name = preg_replace('/[^\da-z]/i', '', $_COOKIE[session_name()]);
$session_data = file_get_contents(session_save_path() . '/sess_' . $session_name);
$return_data = array();
$offset = 0;
@u01jmg3
u01jmg3 / rgb-to-rgba.js
Created October 7, 2015 11:58
Convert RGB to RGBA over white
function RGBtoRGBA(r, g, b){
if((g==void 0) && (typeof r == 'string')){
r = r.replace(/^\s*#|\s*$/g, '');
if(r.length == 3){
r = r.replace(/(.)/g, '$1$1');
}
g = parseInt(r.substr(2, 2), 16);
b = parseInt(r.substr(4, 2), 16);
r = parseInt(r.substr(0, 2), 16);
}
@u01jmg3
u01jmg3 / n++_killer.bat
Created April 30, 2021 08:38
On Windows kill hung background Notepad++ processes
@ECHO off
FOR /F "tokens=2" %%K IN ('
tasklist /FI "ImageName eq notepad++.exe" /FI "Status eq Not Responding" /FO LIST ^| findstr /B "PID:"
') DO (
:: Check for number
SET "var="&for /f "delims=0123456789" %%i in ("%%K") do set var=%%i
IF NOT DEFINED var (
:: https://processhacker.sourceforge.io/
@u01jmg3
u01jmg3 / is-numeric.js
Created November 22, 2016 11:09
JavaScript equivalent of PHP's `is_numeric()`
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}