Skip to content

Instantly share code, notes, and snippets.

@bradleykronson
bradleykronson / find-nodes-of-alias.sql
Created August 19, 2013 09:55
SQL to Find Nodes using a Certain Document Type.cs
SELECT * FROM cmsContent C
INNER JOIN cmsContentType CT ON C.contentType = CT.nodeId
INNER JOIN umbracoNode N ON C.nodeId = N.id
WHERE CT.alias = ‘yourDocumentTypeAliasHere’
@bradleykronson
bradleykronson / Get-month-name.cs
Last active July 17, 2017 06:22
Get month name from month value
string monthName = new DateTime(2010, monthValue, 1) .ToString("MMM", CultureInfo.InvariantCulture);
@bradleykronson
bradleykronson / gitignore for Umbraco
Created August 19, 2013 09:58
.gitignore for Umbraco Place this in the root of your project directory. It is a direct clone of VisualStudio.gitignore available in the github/gitignore repository, with some Umbraco-specific ignores.
# Umbraco stuff
# Data folders/files
*/ExamineIndexes/*
www/App_Data/umbraco.config
*/App_Browsers/*
*/App_Data/TEMP/*
*/_systemUmbracoIndexDontDelete/*
*/App_Data/Logs/*
# ImageGen
@bradleykronson
bradleykronson / function-chaining-pattern.js
Created August 19, 2013 13:54
Function Chaining Pattern This pattern is a nice way to organize the public interface of your module. It saves time and improves readability:
var User = {
profile: {},
name: function(value) {
this.profile.name = value;
return this;
},
job: function(value) {
this.profile.job = value;
return this;
},
@bradleykronson
bradleykronson / constructor-pattern.js
Created August 19, 2013 13:55
Constructor Pattern
function Class(param1, param2) {
this.var1 = param1;
this.var2 = param2;
this.method = function() {
alert(param1 + "/" + param2);
};
};
var instance = new Class("value1", "value2");
@bradleykronson
bradleykronson / module-pattern.js
Created August 19, 2013 13:55
Module Pattern The module pattern gives us the ability to create private and public methods. For example, in the code below, the variable _index and the method privateMethod are private. increment and getIndex are public.
var Module = (function() {
var _index = 0;
var privateMethod = function() {
return _index * 10;
}
return {
increment: function() {
_index += 1;
},
getIndex: function() {
@bradleykronson
bradleykronson / observer-pattern.js
Created August 19, 2013 13:56
Observer Pattern Wherever you see subscription or dispatching of events, you'll likely see this pattern. There are observers which are interested in something related to a specific object. Once the action occurs, the object notifies the observers. The example below shows how we can add an observer to the Users object:
var Users = {
list: [],
listeners: {},
add: function(name) {
this.list.push({name: name});
this.dispatch("user-added");
},
on: function(eventName, listener) {
if(!this.listeners[eventName]) this.listeners[eventName] = [];
this.listeners[eventName].push(listener);
@bradleykronson
bradleykronson / equalize-div-height.js
Created August 19, 2013 13:57
Equalize height for Div Elements
var maxHeight = 0;
$("div").each(function(){
if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
});
$("div").height(maxHeight);
@bradleykronson
bradleykronson / clear-form-data.js
Created August 19, 2013 13:57
Clear Form Data
function clearForm(form) {
// iterate over all of the inputs for the form
// element that was passed in
$(':input', form).each(function() {
var type = this.type;
var tag = this.tagName.toLowerCase(); // normalize case
// it's ok to reset the value attr of text inputs,
// password inputs, and textareas
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = "";
@bradleykronson
bradleykronson / preload-images.js
Created August 19, 2013 13:57
Preloading Images
(function($) {
var cache = [];
// Arguments are image paths relative to the current page.
$.preLoadImages = function() {
var args_len = arguments.length;
for (var i = args_len; i--;) {
var cacheImage = document.createElement('img');
cacheImage.src = arguments[i];
cache.push(cacheImage);
}