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
void MyClass::FetchMagicNumber(std::function<void(int)> callback) { | |
std::weak_ptr<MyClass> weak_this = shared_from_this(); | |
auto fetch_results = [weak_this] { | |
auto shared_this = weak_this.lock(); | |
if (!shared_this) return -1; | |
return shared_this->requester_->DoLongWebRequest(); | |
}; | |
system::Runtime::net_io.Post<int>(fetch_results, callback, system::Runtime::ui()); |
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
// Computers represent numbers in binary (base 2), while humans represent them in decimal (base 10). | |
// In javascript, we can represent a binary number by putting "0b" in front of it | |
0b011 // evaluates to decimal 3! | |
// To convert a number from base 2 to base 10, we assign a value to each position | |
// _ _ _ | |
// 4 2 1 | |
// If the bit at that position is 1, that value is added to the sum. If it's 0, it isn't. |
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
<canvas id="myCanvas" width="400" height="400"></canvas> | |
<script> | |
var canvas = document.getElementById('myCanvas'); | |
var context = canvas.getContext('2d'); | |
// use the context to draw! | |
</script> |
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
// Event reference: https://developer.mozilla.org/en-US/docs/Web/Events |
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
// Extended drawing example where we change colors on mouse click. | |
<canvas id="myCanvas" width="400" height="400"></canvas> | |
<script> | |
var canvas = document.getElementById('myCanvas'); | |
var context = canvas.getContext('2d'); | |
// array of colors to rotate through on click | |
var colors = [ |
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
// Drawing example we used in class. | |
<canvas id="myCanvas" width="400" height="400"></canvas> | |
<script> | |
var canvas = document.getElementById('myCanvas'); | |
var context = canvas.getContext('2d'); | |
context.fillStyle = 'pink'; | |
canvas.addEventListener('mousemove', function(event) { |
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 implementation preserves the original arr | |
function flatten(arr) { | |
var result = []; | |
var queue = []; | |
var pointer = 0; | |
while(pointer < arr.length) { | |
queue.push(arr[pointer]); | |
pointer += 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 randomFromStream() { | |
var length = 0; | |
var result = null; | |
var potentialResult; | |
while(potentialResult = gfs()) { | |
length += 1; | |
if (Math.floor(Math.random() * length) === 0) { | |
result = potentialResult; | |
} |
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 randomFromStream(currentResult, length) { | |
var potentialResult = gfs(); | |
// no more numbers in stream | |
if (potentialResult === null) { | |
return currentResult; | |
} | |
length += 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
var userEmail = $('.user-email').text(); | |
var commonContactsWidget = document.createElement('common-contacts-widget'); | |
commonContactsWidget.setAttribute('user-email', userEmail); | |
$('.some-area-of-the-page').append(commonContactsWidget); | |
angular.bootstrap(commonContactsWidget, ['ng', 'commonContactsModule']); |
NewerOlder