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
/* | |
* Use ajax to live-refresh issues/issues/ when the filters are updated | |
*/ | |
$(function () { | |
if (window.currentPage && window.currentPage == 'issue_list') { | |
/* | |
* sends ajax request via GET for a given query at the current url. | |
* callbacks: fail, done | |
*/ | |
var get_page_num_from_query = function () { |
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 SearchResultsPageGenerator(args) { | |
'use strict'; | |
var httpRequestHandler = args.httpRequestHandler, | |
noLongerNeededObj = args.noLongerNeededObj, // never referenced, always undefined | |
sr_chapters_data_handle = args.sr_chapters_data_handle; | |
// do stuff ... | |
} |
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
// try 2 | |
// indentation looks better, but now the style is inconsistent: | |
books.forEach(function (book) { | |
$('<li/>').html( // statement.method(... here | |
$('<a>') // statement[\n].method(...) here | |
.attr('href', 'book.html') | |
.append( | |
$('<h2/>').text(book.title) | |
) | |
).click(function () { |
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 createApp () { | |
'use strict'; | |
// Create objects | |
var settings = new SettingsManager({ | |
asyncStorage: asyncStorage | |
}), | |
mediaManager = new MediaManager(), | |
fileManager = new FileManager({ | |
storage_device: lf_getDeviceStorage(), |
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
// try 1 | |
if (lf_getDeviceStorage()) { | |
LazyLoader.load(['js/lib/async_storage.js', 'js/lib/mediadb.js'], () => { | |
createApp() | |
}); | |
} | |
// try 2 | |
if (lf_getDeviceStorage()) { | |
LazyLoader.load( |
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
// try 1 | |
books.forEach(function (book) { | |
$('<li/>') | |
.html( | |
$('<a>') | |
.attr('href', 'book.html') | |
.append( | |
$('<h2/>').text(book.title) | |
) // this click now applies to the <li>, not | |
).click(function () { // the <a>, which may be confusing or unclear |
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 multiply(number1, number2) | |
# convert number1 to binary and reverse it | |
# so that the most significant bit is last | |
n1_binary_str = number1.to_s(2).reverse | |
binary_array = n1_binary_str.split '' # convert string to array | |
add_amount = nil | |
total = 0 | |
binary_array.each_with_index do |char, index| | |
# double the add_amount, or set it to number2 if it is nil |
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
class PeasantMultiplication | |
## multiply using the Peasant Multiplication Algorithm | |
def self.multiply(number1, number2) | |
# convert number1 to binary and reverse it | |
# so that the most significant bit is last | |
n1_binary_str = number1.to_s(2).reverse | |
binary_array = n1_binary_str.split '' # convert string to array | |
add_amount = number2 | |
# traverses the binary_array and calculates the total |
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
class TestClass | |
def test_scope | |
times_called = 0 | |
other_func do # passes block into #other_func | |
times_called += 1 | |
end | |
puts "Called #{times_called} times" | |
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
// adapted from displayAppFiles() in app.js | |
function checkIfAnyFiles() { | |
var items_found = 0; // variable defined in outer function | |
var each_item = function(result) { | |
items_found++; // still in scope for the callback | |
} | |
var when_done = function () { | |
// Output depends on number of items traversed by each_item |