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
Array.prototype.binarySearch = function(find, comparator) { | |
var low = 0, high = this.length - 1, | |
i, comparison; | |
while (low <= high) { | |
i = Math.floor((low + high) / 2); | |
comparison = comparator(this[i], find); | |
if (comparison < 0) { low = i + 1; continue; }; | |
if (comparison > 0) { high = i - 1; continue; }; | |
return i; | |
} |
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('Scope.safeApply', []) | |
.run(['$rootScope', function ($rootScope) { | |
$rootScope.$safeApply = function () { | |
var fn, phase = this.$root.$$phase; | |
if (arguments.length == 1) { | |
fn = arguments[0]; | |
} else { |
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
myApp.directive('capitalizeFirst', function($parse) { | |
return { | |
require: 'ngModel', | |
link: function(scope, element, attrs, modelCtrl) { | |
var capitalize = function(inputValue) { | |
if (inputValue === undefined) { inputValue = ''; } | |
var capitalized = inputValue.charAt(0).toUpperCase() + | |
inputValue.substring(1); | |
if(capitalized !== inputValue) { | |
modelCtrl.$setViewValue(capitalized); |
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
(function(global){ | |
var testFunc = function testFunc(func){ | |
var start = new Date(); | |
func(); | |
return new Date() - start; | |
}, | |
speedTest = function speedTest(name, func){ | |
var numOfTimes = 1000, |
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
$scope.loadDependencies = function(arr){ | |
var deferred = $q.defer(); | |
var arrLen = arr.length,i = -1; | |
(function loadNext(){ | |
i++; | |
(i < arrLen) ? arr[i](loadNext) : deferred.resolve(); | |
})(); | |
return deferred.promise; | |
}; |
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
/** | |
* @name orderedInsert | |
* @param {Array} collection | |
* @param {String} key | |
* @param {Object | array} items - array of objects to insert | |
* @returns {promise} | |
* @description will insert an object into a sorted collection using a modified | |
* form of binary searching. it will also insert an array of objects if that is provided | |
* instead. | |
* @example |
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
public class RussianPeasant { | |
public Static int product(int a, int b){ | |
int x = a; | |
int y = b; | |
int z = 0; | |
while(x > 0){ | |
if(x%2 == 1) z += y; | |
x = x >> 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
/* | |
* xorEncryption.c | |
* | |
* Created on: 30 Oct 2015 | |
* Author: Alex | |
*/ | |
#include <stdio.h> | |
#include <string.h> | |
int main(void) |
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
#include <iostream> | |
using namespace std; | |
struct node{ | |
int value; | |
node *left; | |
node *right; | |
}; |
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
/* | |
* linkedList.cpp | |
* | |
* Created on: 3 Nov 2015 | |
* Author: Alex | |
*/ | |
#include <iostream> | |
#include "linkedList.hpp" | |
using namespace std; |
OlderNewer