Skip to content

Instantly share code, notes, and snippets.

// 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 / 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;
}
@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) {
/* 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 / gist:3a53bda42974ec23368f
Created June 2, 2014 11:58
Remove folders from git cache when adding them to .gitignore
git rm --cached -r src/dependencies/
$ setxkbmap -option apple:badmap
# Place that command into ~/.bashrc file to have it run automatically when you log in.
@SubZane
SubZane / Asset.php
Created August 23, 2012 14:38
WordPress: Image Custom Meta Property
add_action( 'add_meta_boxes', 'custom_meta_boxes' );
add_action( 'save_post', 'ExtraImageProperty_save' );
function custom_meta_boxes() {
add_meta_box('ExtraImageProperty', 'Extra Image Property', 'ExtraImageProperty', 'page');
}
function ExtraImageProperty() {
global $post;
$extra_image_url = get_post_meta($post->ID, 'extra_image_url', true);
@SubZane
SubZane / Asset.php
Created August 27, 2012 14:55
WordPress: get_attachment_id_from_src
function get_attachment_id_from_src ($src) {
global $wpdb;
$reg = "/-[0-9]+x[0-9]+?.(jpg|jpeg|png|gif)$/i";
$src1 = preg_replace($reg,'',$src);
if($src1 != $src){
$ext = pathinfo($src, PATHINFO_EXTENSION);
$src = $src1 . '.' .$ext;
}
$query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$src'";
$id = $wpdb->get_var($query);
@SubZane
SubZane / Detect Windows Tablet or Laptop
Created October 13, 2015 13:42
Detect Windows Tablet or Laptop
window.PointerEvent ? "pointer" : "ontouchstart" in window ? "touch" : "mouse";
@SubZane
SubZane / gist:5896271
Created June 30, 2013 18:23
tar and bzip a folder and its subfolders
tar -c --bzip2 -f foo.tar.bz1 foo/