Skip to content

Instantly share code, notes, and snippets.

@SubZane
SubZane / guid.js
Last active August 17, 2016 11:31
create a guid using javascript
function guid() {
var strguid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
return strguid;
}
@SubZane
SubZane / gist:3a53bda42974ec23368f
Created June 2, 2014 11:58
Remove folders from git cache when adding them to .gitignore
git rm --cached -r src/dependencies/
/* Based on
* - EGM Mathematical Finance class by Enrique Garcia M. <egarcia@egm.co>
* - A Guide to the PMT, FV, IPMT and PPMT Functions by Kevin (aka MWVisa1)
*/
var ExcelFormulas = {
PVIF: function(rate, nper) {
return Math.pow(1 + rate, nper);
},
@SubZane
SubZane / IE Detection Script
Created April 23, 2014 11:46
IE Detection Script
<script>
if (/\bMSIE 6/.test(navigator.userAgent) && !window.opera) {
document.documentElement.className+=' ie6';
} else if (navigator.appVersion.indexOf("MSIE 7.") != -1) {
document.documentElement.className+=' ie7';
} else if (navigator.appVersion.indexOf("MSIE 8.") != -1) {
document.documentElement.className+=' ie8';
} else if (navigator.appVersion.indexOf("MSIE 9.") != -1) {
document.documentElement.className+=' ie9';
} else if (/*@cc_on!@*/false && document.documentMode === 10) {
@SubZane
SubZane / input:number
Created April 23, 2014 11:45
Allow only numbers on input:number
$("input[type=number]").keydown(function(event) {
// Allow: backspace, delete, tab, escape, enter and .
if ( $.inArray(event.keyCode,[46,8,9,27,13,190]) !== -1 ||
// Allow: Ctrl+A
(event.keyCode == 65 && event.ctrlKey === true) ||
// Allow: home, end, left, right
(event.keyCode >= 35 && event.keyCode <= 39)) {
// let it happen, don't do anything
return;
}
// there is a solution for jQuery < 1.9.0, where you can use `$.browser`:
// https://gist.github.com/nathansmith/950767
// but jQuery removed `$.browser` in version 1.9.0, so you have to get another way:
function last_child() {
if (/msie [1-8]{1}[^0-9]/.test(navigator.userAgent.toLowerCase())) {
$('*:last-child').addClass('last-child');
}
}
@SubZane
SubZane / functions.php
Last active March 22, 2020 09:35
How to prevent WordPress to add image dimensions
<?php
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
add_filter( 'the_content', 'remove_thumbnail_dimensions', 10 );
function remove_thumbnail_dimensions( $html ) {
$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
return $html;
}
?>
@SubZane
SubZane / gist:7806413
Created December 5, 2013 14:58
regex find tags
/<\s*\/?\s*[p,span]\s*.*?>/g
git tag -a v0.2.1 12edf74 -m "First internal release"
git push origin v0.2.1
split -d -b 4300m backup.tar.bz2 backup.tar.bz2.
cat backup.tar.bz2.* > backup.tar.bz2