Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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
.ace_line {
white-space: normal !important;
text-indent: -1em;
padding-left: 1em;
}
@richjenks
richjenks / iframe.css
Created April 16, 2016 07:57
Responsive iframe
.responsive-iframe {
position: relative;
padding-bottom: 56.25%; /* 16:9 */
height: 0;
}
.responsive-iframe iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
function uuid() {
var uuid = "", i, random;
for (i = 0; i < 32; i++) {
random = Math.random() * 16 | 0;
if (i == 8 || i == 12 || i == 16 || i == 20) {
uuid += "-"
}
uuid += (i == 12 ? 4 : (i == 16 ? (random & 3 | 8) : random)).toString(16);
}
return uuid;
@richjenks
richjenks / backup.sh
Created April 16, 2016 07:56
Backup & Restore Linux
# Backup system to /backup.tgz
sudo su
cd /
tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys --exclude=/media /
@richjenks
richjenks / custom-formats.php
Created April 16, 2016 07:55
CKEditor for GetSimple
<?php //Adds the format red to CKEditor with defined styles
define('GSEDITOROPTIONS', "
format_tags: 'p;h2;h3;h4;h5;h6;pre;small;red',
format_small: {
name: 'Small',
element: 'small'
},
format_red: {
name: 'Red',
function toggleFullScreen() {
var doc = window.document;
var docEl = doc.documentElement;
var requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen;
var cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen;
if(!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement) {
requestFullScreen.call(docEl);
}
else {
cancelFullScreen.call(doc);
USE database
SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE '%attachment%'
AND TABLE_TYPE = 'BASE TABLE'