Skip to content

Instantly share code, notes, and snippets.

View duncanmcdougall's full-sized avatar

Duncan McDougall duncanmcdougall

View GitHub Profile
@duncanmcdougall
duncanmcdougall / Corona-Infinite-Scroll-Background.lua
Created January 9, 2012 08:18
Corona Infinite Scroll Background Tile
-- I'm using this code in an survival game similar to one of those high speed motor way games
local backgroundTiles = {}
-- drawBackground()
-- The same 480x320 image is used twice
local drawBackground = function()
backgroundTiles[0] = display.newImageRect( "images/background.jpg", display.contentWidth, display.contentHeight)
backgroundTiles[0].x = display.contentCenterX
backgroundTiles[0].y = display.contentCenterY
@duncanmcdougall
duncanmcdougall / ios-switch-checkbox.html
Created July 1, 2012 19:16
iOS switch styled check boxes
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<style>
body
{
margin:40px;
}
@duncanmcdougall
duncanmcdougall / pushStart.js
Created August 1, 2012 22:42
Insert item to start of JavaScript array
var fruit = ["apple", "banana", "coconut"];
fruit.reverse().push("melon");
fruit.reverse();
//fruit array should now be ["melon", "apple", "banana", "coconut"];
@duncanmcdougall
duncanmcdougall / jquery.backgroundcover.js
Last active December 10, 2015 23:38
Crossbrowser alternative to background-size:cover; Now maintained here https://github.com/duncanmcdougall/jQuery-Background-Cover
/*!
* jquery.backgroundcover.js
* https://github.com/duncanmcdougall/jQuery-Background-Cover
* Copyright 2013 Duncan McDougall and other contributors; Licensed MIT
*/
; (function ($) {
'use strict';
$.fn.backgroundCover = function () {
@duncanmcdougall
duncanmcdougall / matchHeights.js
Created January 15, 2013 14:21
Very simple match heights function. Sets all elements height to the largest of its kind.
function matchHeights(selector) {
$(selector).height('');
var maxHeight = 0;
$(selector).each(function (idx, item) {
if ($(item).outerHeight() > maxHeight) {
maxHeight = $(item).outerHeight();
}
});
if (maxHeight > 0) {
$(selector).outerHeight(maxHeight);
#element{
background-image: url('/images/sprite.png');
background-repeat: no-repeat;
background-position: -3px 0;
}
@media (min--moz-device-pixel-ratio: 1.25),
(-webkit-min-device-pixel-ratio: 1.25),
(min-device-pixel-ratio: 1.25),
(min-resolution: 1.25dppx) {
@duncanmcdougall
duncanmcdougall / jquery.update.js
Created July 30, 2013 22:26
When saving DOM elements to variables there may come a time when these need to update.
(function ($) {
$.fn.update = function () {
var newElements = $(this.selector, this.context), i, oldLength = this.length;
this.length = newElements.length;
for (i = 0; i < this.length; i++) {
this[i] = newElements[i];
}
for (; i < oldLength; i++) {
this[i] = undefined;
}
@duncanmcdougall
duncanmcdougall / box-sizing.css
Created September 19, 2013 10:33
Favourite CSS Snippets
/* http://www.paulirish.com/2012/box-sizing-border-box-ftw/ */
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
*behavior: url(/css/boxsizing.htc); /* IE6/7 Fix - Get from http://github.com/Schepp/box-sizing-polyfill */
}
@duncanmcdougall
duncanmcdougall / change_all_owners.sql
Created October 2, 2013 15:22
Change all database owners on a SQL Server to another on a server in one swoop. Scary but it works.
USE master
GO
DECLARE @sqlBase nvarchar(300) = 'ALTER AUTHORIZATION ON database::XXXXX TO sa'+char(13)+char(10)
DECLARE @sql nvarchar(max)=''
SELECT @sql = @sql + REPLACE(@sqlBase,'XXXXX',name) from sys.databases
where name not in ('master', 'model', 'tempdb', 'distribution', 'msdb')
EXECUTE(@sql)
@duncanmcdougall
duncanmcdougall / 1-too-much-nesting.less
Last active December 25, 2015 10:39
Code for a new blog post
.main-header {
.nav {
background-color: black;
ul {
li {
display: inline-block;
a {