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
async function showMessageFromServer() { | |
let data = await fetch('/get/data.json'); | |
let message = data.json().message; | |
alert(message); | |
} |
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
//Promises take a function that receives callbacks that can be run when an operation completes | |
let delay5Seconds = new Promise(function(resolve, reject) { | |
setTimeout(resolve, 5000); | |
}); | |
//You can respond to the results of a successfully resolved Promise using the `then` function | |
delay5Seconds.then(function() { | |
console.log('This gets logged 5 seconds later') | |
}); |
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
//fetch makes an HTTP request and returns a promise that resolves | |
//when the file is loaded | |
let p1 = fetch('/data/file1.json'); | |
let p2 = fetch('/data/file2.json'); | |
let p3 = fetch('/data/file3.json'); | |
Promise.all([p1,p2,p3]).then(function(values) { | |
//values contains the responses from each of the promises | |
let [response1, response2, response3] = values; |
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
//Backbone.Model's save function is a function that takes callbacks | |
//for successful or failed saves. | |
//Normal usage | |
let model = new Backbone.Model(); | |
model.save(null, { | |
success: function() { | |
alert('saved'); |
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 { | |
fetch('/some/data').then(function() { | |
throw 'error'; | |
}) | |
} catch(e) { | |
//this code won't be executed | |
console.log('Exception Caught') | |
} |
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
#!/bin/bash | |
# This is a script to set up a Linux Mint environment for Tim's development this summer. It is by no means complete, but is just meant to get started with some of the basics for java development and the courage project. | |
#set your username here | |
USER=ben | |
#update available packages | |
apt-get update | |
#installing postgres | |
apt-get -y install postgresql |
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
/* Small Knockout Extension to allow for canceling/confirming | |
* changes to the view model Originally from: | |
* http://www.knockmeout.net/2011/03/guard-your-model-accept-or-cancel-edits.html | |
*/ | |
//wrapper to an observable that requires accept/cancel | |
ko.protectedObservable = function(initialValue) { | |
//private variables | |
var _actualValue = ko.observable(initialValue), | |
_tempValue = initialValue; |
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
/* Small Knockout Extension to allow for canceling/confirming | |
* changes to the view model. Defaults to the changed option. Based on code sample from Ryan Niemeier | |
* http://www.knockmeout.net/2011/03/guard-your-model-accept-or-cancel-edits.html | |
* | |
* Please note: You should not use this unless you are | |
* explicitly confirming or resetting the values in every scenario before you | |
* reference them again. An unwanted revert may occur if you make changes without confirming and then cancel at a later point. | |
*/ | |
//wrapper to an observable that requires accept/cancel |
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
import java.io.BufferedReader; | |
import java.io.BufferedWriter; | |
import java.io.File; | |
import java.io.FileReader; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
public class Palindrome { | |
public static void main(String[] args) throws Exception |
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
fs = require('fs') | |
writevalue = (i, val)-> | |
output += "Case #"+i+": "+val+"\n" | |
# is a palindrome (expects a string) | |
isPalindrome = (num) -> | |
reversed = (num).split("").reverse().join("") | |
num is reversed |