Skip to content

Instantly share code, notes, and snippets.

@quawn
quawn / snippet.php
Last active September 15, 2015 20:17
Slack notification with attachment
<?php
// Source: http://blog.eddokloosterman.com/2015/09/useful-slack-notifications-for-developers/
private function _notifySlackChannel($success)
{
$attachment = new stdClass();
$attachment->fallback = "Build tests ". ($success == true? "passed" : "failed") . " for last '" . $this->_testType . "' build";
$attachment->title = "Last '" . $this->_testType . "' build " . ($success == true? "OK" : "failed" );
$attachment->text = "Check <http://tfs_url/tfs/DefaultCollection/RoosterWeb/_build|build log> for more details";
$attachment->color = $success == true? "good" : "danger" ;
$params = array(
@quawn
quawn / slack_notification.php
Last active September 9, 2015 14:03 — forked from alexstone/slack_notification.php
Fire a Slack Notification via CURL
<?php
// (string) $message - message to be passed to Slack
// (string) $room - room in which to write the message, too
// (string) $icon - You can set up custom emoji icons to use with each message
public static function slack($message, $room = "engineering", $icon = ":longbox:") {
$room = ($room) ? $room : "engineering";
$data = "payload=" . json_encode(array(
"channel" => "#{$room}",
"text" => $message,
@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 / 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 / img-resizer.js
Last active January 4, 2016 03:19
JS: Image resizing using jQuery
$(window).bind("load", function() {
// IMAGE RESIZE
$('#product_cat_list img').each(function() {
var maxWidth = 120;
var maxHeight = 120;
var ratio = 0;
var width = $(this).width();
var height = $(this).height();
if(width > maxWidth){
@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>
@quawn
quawn / div-viewport.js
Last active January 4, 2016 03:19
JS: Div full Width/Height of viewport with jQuery
// global vars
var winWidth = $(window).width();
var winHeight = $(window).height();
// set initial div height / width
$('div').css({
'width': winWidth,
'height': winHeight,
});
@quawn
quawn / ext-link-opener.js
Last active January 4, 2016 03:19
JS: Open external links in a new tab/window
@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");
});