Skip to content

Instantly share code, notes, and snippets.

View nmoliveira's full-sized avatar

Nuno Oliveira nmoliveira

View GitHub Profile
@nmoliveira
nmoliveira / hello-world.js
Created April 25, 2013 06:48
Hello World!
var greetings = function (){
alert('Hello World!');
}();
@nmoliveira
nmoliveira / foreach.js
Created May 18, 2013 10:54
A javascript ForEach implementation
function forEach(list,callback) {
for (var n = 0; n < list.length; n++) {
callback.call(list[n]);
}
}
var myArray = ['hello','world'];
forEach(
myArray,
@nmoliveira
nmoliveira / duplicate-array.js
Created May 18, 2013 11:03
function that duplicates an array
// function that duplicates an array
function duplicateArray(arr) {
// create clone of original array using slice
var cloneArr = arr.slice();
// concat original array and clone array in one new array (the objective!!)
var dupArr = arr.concat(cloneArr);
//return the new array
return dupArr;
}
@nmoliveira
nmoliveira / revealing-module-pattern.js
Created May 18, 2013 23:00
A example of the javascript Revealing Module Pattern
var Calculator = function() {
// private members goes here
var privateLog = false;
var privateConfig = function(shouldLog) {
privateLog = shouldLog;
};
var privateAdd = function (x,y) {
var result = x + y;
if (privateLog) {
console.log(result);
@nmoliveira
nmoliveira / backbone-view-template.html
Created May 30, 2013 22:10
Simple Html page using Backbone View to render a template.
<html>
<head>
<title>Backbone Trainning</title>
</head>
<body>
<script src="scripts/jquery-1.10.0.js"></script>
<script src="scripts/underscore.js"></script>
<script src="scripts/backbone.js"></script>
@nmoliveira
nmoliveira / Div-100-height-minus-fixed-size.html
Last active December 17, 2015 22:39
Html example with a top with specific height and the rest of the content with width 100%
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style type="text/css">
html,
body{
padding: 0px;
margin: 0px;
height: 100%;
@nmoliveira
nmoliveira / simple-handlebarsjs.html
Last active December 18, 2015 04:19
A very simple example using Handlebars.js
<html>
<head>
<title>Simple Handlebars Example</title>
</head>
<body>
<!-- Template -->
<script id="name-tmpl" type="text/x-handlebars-template">
<p>Title: {{ name }} </p>
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
@nmoliveira
nmoliveira / backbonejs-collection-handlebarsjs.html
Created June 7, 2013 20:39
Example for rendering a Backbone.js collection using Handlebars.js
<html>
<head>
<title>Backbone Trainning</title>
</head>
<body>
<!-- Template -->
<script id="todos-tmpl" type="text/x-handlebars-template">
{{#each todos}}
<div class='todo-item'>
@nmoliveira
nmoliveira / jquery-get-js-script.js
Created June 26, 2013 11:04
Get javascript file with jQuery. Also let that the file be cached.
jQuery.cachedScript = function(url, options) {
// allow user to set any option except for dataType, cache, and url
options = $.extend(options || {}, {
dataType: "script",
cache: true ,
url: url
});
// Use $.ajax() since it is more flexible than $.getScript
@nmoliveira
nmoliveira / jquery-custom-events.js
Created July 21, 2013 01:37
jQuery Custom Events
<!DOCTYPE html>
<html>
<head>
<title>jQuery Custum Events</title>
<script src="jquery.js"></script>
<style type="text/css">
#light{
width: 100px;
height: 100px;
background-color: black;