Skip to content

Instantly share code, notes, and snippets.

@oslego
oslego / versionCheck.js
Created March 5, 2011 14:05
Check two string representations of versions and return true if the testVersion is equal or greater than the testVersion.
/**
check two string respresentations of versions.
returns true if the version to test is equal or greater than the required minimum version
returns false if the test version is lower than the minimum version
@param {String} minVersion Minimum required version to test against
@param {String} testVersion Version to test
@return {Boolean}
@oslego
oslego / loadStyles.js
Created March 8, 2011 13:56
Load any number of CSS files to the current document's head.
//Loads CSS files into the head of the current document
//using arguments to reference any number of styles
function loadStyles(){
var i = 0,
d = document,
s = d.createElement("link"),
h = d.getElementsByTagName('head')[0],
createStyle = function(src){
s = s.cloneNode(false);
s.rel ="stylesheet";
@oslego
oslego / replaceURLWithHTMLLinks.js
Created March 11, 2011 15:38
replace URL-like strings with HTML link elements
@oslego
oslego / makeSearchInput.js
Created March 30, 2011 13:29
Convert a plain text field into a search field with focus/blur behavior
/**
Turn a text input into a search input with added behavior
On focus, if input value is the same as defaultValue, replace with blank
On blur, if input value is empty or full of whitespace replace with defaultValue
@param input {HTMLInputElement} element to behave as search input
@param defaultValue {String} string to be default value of the input
**/
function makeSearchInput(input, defaultValue){
input.setAttribute("data-default", defaultValue);
@oslego
oslego / javascript_multiton.js
Created June 3, 2011 10:57
JavaScript Multiton Example
/*
Use, reuse but don't abuse!
Author: Razvan Caliman (razvan.caliman@gmail.com)
This is an example of a "Multiton" pattern;
Create a fixed number of instances of a class.
Use "lazy instantiation" to create objects only if needed.
If the maximum number of instances has been reached, return a random one from the ones created.
*/
@oslego
oslego / mkhost.sh
Created June 28, 2011 18:15
Create localhost website folder and add virtualhost
#!/bin/sh
# USE AT YOUR OWN RISK. Tested on Ubuntu 11.04 with apache2.
# CHECK COMMENTS BEFORE RUNNING
# this script creates localhost website folder and adds virtualhost
# website name - it will append .lh for the path
# ex.: 'example' will be accessed as example.lh in the browser
website="$@"
if [ -z "$website" ]; then
echo "No website, no fun."
@oslego
oslego / globalScope.js
Created July 19, 2011 11:31
Global scoping of JavaScript variables
<script type="text/javascript">
function fn(){
//missing var declaration exposes 'x' to global scope
x = "surprise!"
//by using var 'y' remains private inside the instance of 'fn'
var y = "really private!"
}
@oslego
oslego / myadobe-hiring-tweaks.js
Created December 8, 2011 11:46
MyAdobe Hiring Tweaks
(function($){
$(function(){$("#r_sidebar, #l_sidebar").remove(); $("#contentleft").css("width","960px") });
})(jQuery)
@oslego
oslego / regions-grid.css
Created December 13, 2011 18:10
CSS Regions and Grid Template
/* Region related style for redirecting content flows */
#article {
flow-into: article_flow;
}
#region1, #region2, #region3, #region4 {
flow-from: article_flow;
}
/* positioning and sizing of the region elements */
@oslego
oslego / arrayfy.js
Created January 4, 2012 12:43
Convert object to array
// idea from https://github.com/bartaz/impress.js
var arrayify = function ( a ) {
return Array.prototype.slice.call( a );
};