This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fruits = [ | |
{name:'apple', color:'red'}, | |
{name:'orange', color:'orange'}, | |
{name:'grape', color:'purple'} | |
]; | |
var hasFruit = function(fruitToCheck) { | |
return fruits.some(function(fruit) { | |
return fruit.name === fruitToCheck; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return function(scope, element, attrs) { | |
attrs.$observe('key', function(value) { | |
console.log('key=', value); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myClosure(name) { | |
var x = 0; | |
//private method | |
function doCount() { | |
console.log("Count " + name + ", count: " + x++); | |
} | |
//public | |
return { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def out = System.out.&println | |
out "Haaa!" //Haa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var result = navigator.userAgent.match(/(opera|chrome|safari|firefox|msie|trident)\/?\s*(\.?\d+(\.\d+)*)/i); | |
//output: ["Chrome/41.0.2272.76", "Chrome", "41.0.2272.76", ".76"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Intercepting HTTP calls with AngularJS. | |
angular.module('MyApp', []) | |
.config(function ($provide, $httpProvider) { | |
// Intercept http calls. | |
$provide.factory('MyHttpInterceptor', function ($q) { | |
return { | |
// On request success | |
request: function (config) { | |
// console.log(config); // Contains the data about the request before it is sent. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find | |
^(\s+)?< | |
replace | |
$1'< | |
find | |
>$ | |
replace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.no-selection { | |
-webkit-user-select: none; | |
-moz-user-select: none; | |
-ms-user-select: none; | |
user-select: none; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function random(seed) { | |
if (!seed) | |
seed = new Date().getTime(); | |
seed = (seed*9301+49297) % 233280; | |
return seed/(233280.0) * 100; | |
} | |
function seed() { | |
var seedNumber = (Math.random() * Math.pow(10, 17) + Math.random() * Math.pow(10, 17) + Math.random() * Math.pow(10, 17) + Math.random() * Math.pow(10, 17)); | |
return seedNumber; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MathService = { | |
add: function() { | |
var amount = arguments.length; | |
var total = 0; | |
if(amount > 0) { | |
for(var i=0; i<amount; i++) { | |
var currentNumber = parseInt(arguments[i], 10); | |
if(isNaN(currentNumber)) return null; |