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
// Return an array sorted in a "snail" format -- that is, around the edge and then the middle. | |
// var arr = [[1,2,3], | |
// [4,5,6], | |
// [7,8,9]]; | |
// var arr1 = [[1]]; | |
// var arr2 = [[1, 2], [3, 4]]; | |
// Test.assertSimilar(snail(arr1), [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
// imperative version | |
var i, | |
callLater = {}; | |
for (i = 0; i < 3; i++) { | |
(function (val) { | |
callLater[val] = function () { | |
return "hello " + val; | |
}; | |
}(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
function countInversions(array){ | |
// Note: this uses a variant of merge sort | |
//input handlers | |
if (array === undefined) throw new Error("Array must be defined to count inversions"); | |
if (array.length === 0 || array.length === 1) return 0; | |
var tally = 0; // count for inversions | |
sort(array); // merge sort the array and increment tally when there are crossovers | |
return tally; |
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
//* | |
//* See the JS Fiddle: http://jsfiddle.net/sxcjmoj5/3/ | |
//* | |
//* | |
// make sure ngSanitize module is installed: | |
// https://docs.angularjs.org/api/ngSanitize | |
// | |
// To convert links from plaintext, you must use the linky filter which is included with ngSanitize | |
// https://docs.angularjs.org/api/ngSanitize/filter/linky | |
// |
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 balance(chars: List[Char]): Boolean = { | |
def balIter(chars: List[Char], count: Int): Boolean = { | |
if (chars.isEmpty){ | |
if (count == 0) true else false | |
} else{ | |
if (chars.head.toString == ")") { | |
if (count < 1) false else balIter(chars.tail, count - 1) | |
} else if (chars.head.toString == "("){ | |
balIter(chars.tail, count + 1) | |
} 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
def pascal(c: Int, r: Int): Int = { | |
if (c < 0 || r < 0 || c > r) throw new IllegalArgumentException("Column and row numbers must be 0 or greater. Column length must be lower than row length") else{ | |
if (c == 0 || c == r) 1 else { | |
pascal(c - 1, r - 1) + pascal(c, r - 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
/* | |
This file is a brief example of how to use angularfire to authenticate a user, save that user's public profile to firebase, then | |
ensure that both the authenticated and public user are available in your controllers. | |
The route configuration uses angular-ui-router: https://github.com/angular-ui/ui-router | |
*/ | |
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
#This will allow you to serve google TTS audio from your own domain, allowing you to use it in the source for HTML5 audio tags. | |
#tts_controller.rb | |
class TtsController < ApplicationController | |
def pipe | |
queryString = params[:query_string] #.gsub(. . ., '') | |
lang = params[:lang] #Language code; see https://sites.google.com/site/tomihasa/google-language-codes | |
require 'net/http' | |
url = URI.parse('http://translate.google.com/translate_tts?ie=UTF-8&tl=' + lang + '&q=' + URI::encode(queryString)) |