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
var app = angular.module('yourApp', []); | |
// No olvide inyectar el servicio $compile a su controlador | |
app.controller('yourCtrl', ['$scope', '$compile', function($scope, $compile) { | |
//Trae el template crudo del servidor | |
var template = "<div ng-repeat='item in items'>{{item.name}}</div>"; | |
//Por simplicidad del ejemplo vamos a insertar el template con jquery | |
$('#sucontainer').html(template); | |
//Hasta este momento lo que inserto en el DOM es inerte, | |
//Angular no conoce de su existencia. | |
//Para lograrlo tenemos que compilar el template y |
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
def search(array, number) #array must be sorted | |
pivot = array.size / 2 | |
return pivot if array[pivot] == number | |
if array[pivot] > number #Search on the left | |
return search array.slice 0, pivot, number | |
else #Search on the right | |
return search array.slice pivot, array.size - pivot | |
end | |
end |
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
def factorial(n) # For n >= 1 | |
return n if n == 1 #Base case, recursion ends here | |
return n * factorial(n - 1) #Recursive solution, multiply the current number by the factorial of the previous number | |
end |
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
map = [ | |
[8, 8, 4, 4, 5], | |
[4, 9, 6, 4, 8], | |
[8, 6, 4, 1, 2], | |
[4, 8, 2, 6, 3], | |
[0, 6, 8, 8, 4] | |
] | |
look = lambda { |position, visited, coins, path| | |
if visited.include? position |
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
var move = function(array, element, delta) { | |
var index = array.indexOf(element); | |
var newIndex = index + delta; | |
if (newIndex < 0 || newIndex == array.length) return; //Already at the top or bottom. | |
var indexes = [index, newIndex].sort(); //Sort the indixes | |
array.splice(indexes[0], 2, array[indexes[1]], array[indexes[0]]); //Replace from lowest index, two elements, reverting the order | |
}; | |
var moveUp = function(array, element) { | |
move(array, element, -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
function getSelectedText(){ | |
if(window.getSelection){ | |
return window.getSelection().toString(); | |
} | |
else if(document.getSelection){ | |
return document.getSelection(); | |
} | |
else if(document.selection){ | |
return document.selection.createRange().text; | |
} |
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
$dbh->beginTransaction(); | |
$statement = $dbh->prepare("INSERT INTO TABLE (field1, field2) VALUES (:v1, :v2)"); | |
$stmt->bindParam(':v1', $value1); | |
$stmt->bindParam(':v2', $value2); | |
for ($i = 0; $i < 300; $i++) { | |
$value1 = 'value'; | |
$value2 = 'another value'; | |
$stmt->execute(); | |
} |
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
TextWindow.WriteLine("hola") | |
TextWindow.WriteLine(" hola soy tito ") | |
TextWindow.WriteLine( "te amo mama " ) | |
TextWindow.Write("8x7=") | |
TextWindow.WriteLine(8*7) | |
TextWindow.WriteLine(10+20*53) | |
TextWindow.WriteLine("3 en ingles es tree") |
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
def count_words(max_occurrences, unique_words) | |
unique_words -= 1 | |
total_words = max_occurrences | |
for i in 2..unique_words | |
total_words += max_occurrences / i.to_f | |
end | |
return total_words | |
end | |
def search(max_ocurrences, unique_words) |
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
# encoding: UTF-8 | |
def standar_deviation(values) | |
total = 0.0 | |
values.each { |value| total += value } | |
average = total / values.length | |
total = 0.0 | |
deviation = values.each { |value| | |
total += (value - average) ** 2 | |
} |