Skip to content

Instantly share code, notes, and snippets.

@quawn
quawn / function.php
Last active April 11, 2024 22:22
WP: Check if image attached to the post
<?php
$attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image') );
if ( $attachments ) {
// do conditional stuff here
}
@quawn
quawn / getWorkingDays.php
Last active October 11, 2023 17:04
PHP: GetWorkingDays excluding weekend and holidays
<?php
function getWorkingDays($startDate,$endDate,$holidays) {
// do strtotime calculations just once
$endDate = strtotime($endDate);
$startDate = strtotime($startDate);
//The total number of days between the two dates. We compute the no. of seconds and divide it to 60*60*24
//We add one to inlude both dates in the interval.
$days = ($endDate - $startDate) / 86400 + 1;
@quawn
quawn / load-on-scrolling.js
Last active November 23, 2022 11:58
JS: Automatically load content on scroll
var loading = false;
$(window).scroll(function(){
if((($(window).scrollTop()+$(window).height())+250)>=$(document).height()){
if(loading == false){
loading = true;
$('#loadingbar').css("display","block");
$.get("load.php?start="+$('#loaded_max').val(), function(loaded){
$('body').append(loaded);
$('#loaded_max').val(parseInt($('#loaded_max').val())+50);
$('#loadingbar').css("display","none");
@quawn
quawn / gist:8560663
Last active March 10, 2017 15:03
JS: Preload images
$.preloadImages = function() {
for(var i = 0; i<arguments.length; i++) {
$("<img />").attr("src", arguments[i]);
}
}
$(document).ready(function() {
$.preloadImages("hoverimage1.jpg","hoverimage2.jpg");
});
@quawn
quawn / style.css
Last active March 10, 2017 14:58
CSS: Block text gradient colour
background: -webkit-gradient(linear,left top,left bottom,from(#ff0052),to(#8e2b88));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
@quawn
quawn / zebra.js
Last active January 4, 2016 03:19
JS: Table Stripes (Zebra)
$(document).ready(function(){
$("table tr:even").addClass('stripe');
});
@quawn
quawn / sorter.js
Last active January 4, 2016 03:19
JS: Sort a list alphabetically
$(function() {
$.fn.sortList = function() {
var mylist = $(this);
var listitems = $('li', mylist).get();
listitems.sort(function(a, b) {
var compA = $(a).text().toUpperCase();
var compB = $(b).text().toUpperCase();
return (compA < compB) ? -1 : 1;
});
$.each(listitems, function(i, itm) {
@quawn
quawn / img-loaded-checker.js
Last active January 4, 2016 03:19
JS: Check if an image is loaded
var imgsrc = 'img/image1.png';
$('<img/>').load(function () {
alert('image loaded');
}).error(function () {
alert('error loading image');
}).attr('src', imgsrc);
@quawn
quawn / content-loader.js
Last active January 4, 2016 03:19
JS: Load external content
$("#content").load("somefile.html", function(response, status, xhr) {
// error handling
if(status == "error") {
$("#content").html("An error occured: " + xhr.status + " " + xhr.statusText);
}
});
@quawn
quawn / form.html
Last active January 4, 2016 03:19
JS: Test password strength
<input type="password" name="pass" id="pass" />
<span id="passstrength"></span>