This file contains 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
1. Define local variables | |
When a variable is referenced, Javascript hunts it down by looping through the different members of the scope chain. This scope chain is the set of variables available within the current scope, and across all major browsers it has at least two items: a set of local variables and a set of global variables. | |
Simply put, the deeper the engine has to dig into this scope chain, the longer the operation will take. It first goes through the local variables starting with this, the function arguments, then any locally defined variables, and afterwards iterates through any global variables. | |
Since local variables are first in this chain, they’re always faster than globals. So anytime you use a global variable more than once you should redefine it locally, for instance change: | |
var blah = document.getElementById('myID'), | |
blah2 = document.getElementById('myID2'); | |
to: | |
var doc = document, | |
blah = doc.getElementById('myID'), | |
blah2 = doc.getElementById('myID2'); |
This file contains 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
angular | |
.module('uuidApp', ['lvl.services']) | |
.controller('uuidCtl', ['$scope', 'uuid', function($scope, uuid){ | |
$scope.generateUuid = function() { | |
$scope.new = uuid.new(); | |
$scope.nInfo = new Date(); | |
}; | |
$scope.showEmpty = function() { | |
$scope.empty = uuid.empty(); |
This file contains 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
controllers.controller('MainCtrl', function($scope, $location, Facebook, $rootScope, $http, $location, Upload, Auth, User, Question, Category, Serie, Record, Location, Popup, Process, Card, Question) { | |
$scope.$on('authLoaded', function() { | |
$scope.isExpert($scope.main.serieId); | |
$scope.isMember($scope.main.serieId); | |
}); | |
$scope.loadAuth = function() { | |
Auth.load().success(function(data) { | |
$scope.main.user = data.user; | |
$scope.$broadcast("authLoaded"); |
This file contains 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
controllers.controller('MainCtrl', function($scope, $location, Facebook, $rootScope, $http, $location, Upload, Auth, User, Question, Category, Serie, Record, Location, Popup, Process, Card, Question) { | |
$scope.$on('authLoaded', function() { | |
$scope.isExpert($scope.main.serieId); | |
$scope.isMember($scope.main.serieId); | |
}); | |
$scope.loadAuth = function() { | |
Auth.load().success(function(data) { | |
$scope.main.user = data.user; | |
$scope.$broadcast("authLoaded"); |
This file contains 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
t1 = Thread.new do | |
i = 0 | |
1_000_000.times do | |
i += 1 | |
end | |
end | |
t2 = Thread.new do | |
j = 0 | |
1_000_000.times do | |
j += 1 |
This file contains 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
.directive('whenActive', | |
[ | |
'$location', | |
($location)-> | |
scope: true, | |
link: (scope, element, attr)-> | |
scope.$on '$routeChangeSuccess', | |
() -> | |
loc = "#"+$location.path() | |
href = element.attr('href') |
This file contains 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
Calculate the distance between two coordinates | |
When we need to measure the distance between two points, we may use one of the following formulas: Haversine formula or Vincenty’s formula. There are two appropriately named functions: | |
01 | |
function haversineGreatCircleDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000) { | |
02 | |
// convert from degrees to radians | |
03 | |
$latFrom = deg2rad($latitudeFrom); |
This file contains 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
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Clean-Markup Line Numbers™</title> | |
<style> | |
body { | |
width: 800px; | |
margin: 0 auto; | |
} |
This file contains 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
$http.post("http://example.appspot.com/rest/app", {"foo":"bar"}) | |
.success(function(data, status, headers, config) { | |
$scope.data = data; | |
}).error(function(data, status, headers, config) { | |
$scope.status = status; | |
}); |
This file contains 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
$http({ | |
url: "http://example.appspot.com/rest/app", | |
method: "POST", | |
data: {"foo":"bar"} | |
}).success(function(data, status, headers, config) { | |
$scope.data = data; | |
}).error(function(data, status, headers, config) { | |
$scope.status = status; | |
}); |
NewerOlder