Skip to content

Instantly share code, notes, and snippets.

View richjenks's full-sized avatar
🏍️

Rich Jenkins richjenks

🏍️
View GitHub Profile
@richjenks
richjenks / snippets.ps1
Created April 16, 2016 07:59
PowerShell snippets
# Batch rename files (underscores to hyphens)
Dir | Rename-Item –NewName { $_.name –replace "_","-" }
# Get full path of all files
gci -r | where {$_.extension -match ".html|.htm|.php|.asp"} | select FullName
# Delete all files except...
gci -r | ? {$_.extension -notmatch ".html|.htm|.php|.asp"} | ? {-not $_.PsIsContainer } | remove-item
# Delete SVN folders
@richjenks
richjenks / angular-animate-fade.css
Last active May 3, 2016 11:40
Simple fade transitions for Angular Animate
.ng-enter { opacity: 0; transition: .3s opacity ease; height: 0; }
.ng-enter-active { opacity: 1; }
@richjenks
richjenks / normalize.php
Created June 11, 2016 21:12
Normalizes a number to within a desired range
<?php
/**
* Normalizes a number to within a desired range
*
* @param int|float $input Number to be normalized
* @param int|float $inputMin Lowest number that $input can possibly be
* @param int|float $inputMax Highest number that $input can possibly be
* @param int|float $outputMin Lower range for desired output
* @param int|float $outputMax Upper range for desired output
@richjenks
richjenks / determine.php
Last active June 12, 2016 09:17
Deterministically generates an unpredictable number from the input within a given range
<?php
/**
* Deterministically generates an unpredictable number from the input within a given range
* Intended for int|float but will accept anything
*
* Uses MD5 to generate a number between 0–268435455 then "scales" that number into the desired range
*
* @param mixed $input Variable to use as seed
* @param int|float $min Lower range for desired output
@richjenks
richjenks / current-url.php
Created June 13, 2016 11:58
Attempt at providing the current URL in the cleanest possible manner
<?php
function url() {
$url = @( $_SERVER['HTTPS'] != 'on' ) ? 'http://' : 'https://'; // Protocol
$url .= $_SERVER['SERVER_NAME']; // Host
if ($_SERVER['SERVER_PORT'] != 80) $url .= ':'.$_SERVER['SERVER_PORT']; // Port
if ($_SERVER['REQUEST_URI'] !== '/') $url .= $_SERVER['REQUEST_URI']; // Request
return $url;
}
@richjenks
richjenks / bootstrap-well-inverse.css
Created June 22, 2016 12:36
Well that is embossed rather than depressed
.well-inverse {
box-shadow:
0 1px 1px rgba(0, 0, 0, .05),
0 1px 1px white inset;
}
@richjenks
richjenks / bootstrap-collapse-toggles.css
Last active June 22, 2016 12:59
Bootstrap style to have hide/show content of collapse toggle based on current state
[aria-expanded="false"] .collapse-opened,
[aria-expanded="true"] .collapse-closed {
display: none;
}
@richjenks
richjenks / native-fonts.css
Last active March 29, 2018 14:23
Font stacks for system fonts
.sans { font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; }
.serif { font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; }
.monospace { font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; }
@richjenks
richjenks / wp_remove_menu.php
Created December 15, 2016 16:52
Remove an item from the Admin menu
<?php
/**
* remove_menu
*
* Remove an item from the Admin menu
* If top-level menu item, pass the slug as a string
* If submenu item, pass an array of parent and submenu slugs
*
* @param string|array $item Slug or parent slug & slug to be removed
@richjenks
richjenks / wp_compact_post_types.php
Last active December 15, 2016 16:54
Moves all pages of a CPT (Custom Post Type) into one menu item
<?php
/**
* Moves all pages of a CPT (Custom Post Type) into one menu item
* Useful when a CPT is a submenu & the Add New page goes walkies
*
* Example: You have added a new CPT under an existing CPT or
* menu item. When you click "Add New" for the new CPT, the URL
* doesn't match a menu item so nothing is selected as the
* current page. This function makes such pages show as the main