Skip to content

Instantly share code, notes, and snippets.

@fisherds
fisherds / simple_json_get_handler.py
Last active August 29, 2015 14:08
Example from our ServerTime demo of a simple Python AppEngine handler that returns JSON
import json
import webapp2
class ServerTime(webapp2.RequestHandler):
def get(self):
self.response.headers["Content-Type"] = "application/json"
#self.response.headers.add_header("Access-Control-Allow-Origin", "*")
response = {"message": "Hello AJAX!"}
@fisherds
fisherds / sample_jquery_post.js
Last active August 29, 2015 14:08
Skeleton code for a jQuery post from our ServerTime demo
var dataToSend = {};
$.post( "/servertime", dataToSend ).done(function( data ) {
console.log("Response JSON: " + JSON.stringify(data));
// TODO: Do something with the data
}).fail(function(jqxhr, textStatus, error) {
console.log("POST Request Failed: " + textStatus + ", " + error);
});
@fisherds
fisherds / jquery_get_skeleton.js
Last active August 29, 2015 14:08
Skeleton code for a jQuery getJSON call from our ServerTime example
$.getJSON("/servertime").done(function(json) {
console.log("JSON Data: " + JSON.stringify(json));
// TODO: Do something with the JSON data.
}).fail(function(jqxhr, textStatus, error) {
console.log("GET JSON Request Failed: " + textStatus + ", " + error);
});
@fisherds
fisherds / main_simple_ajax_links.py
Last active August 29, 2015 14:08
Lines of code to add to main.py for this unit
@fisherds
fisherds / ButtonsAndLabelsViewController.swift
Last active January 2, 2018 17:09
Code added in this video to implement the ButtonsAndLabelsViewController
import UIKit
class ButtonsAndLabelsViewController: UIViewController {
var counter = 0;
@IBOutlet weak var countLabel: UILabel!
@IBAction func pressedIncrement(_ sender: Any) {
counter += 1
updateView()
@fisherds
fisherds / TouchesViewController.swift
Last active January 2, 2018 17:08
Implementation of our TouchesViewController in the first day demo
import UIKit
class TouchesAndViewsViewController: UIViewController {
@IBOutlet weak var logoImageView: UIImageView!
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
let position = touch.location(in: view)
print(position)
UIView.beginAnimations(nil, context: nil)
@fisherds
fisherds / StudentTableViewController.swift
Last active January 2, 2018 17:24
Code used in the video to implement StudentTableViewController in the First Day Demo
import UIKit
class StudentTableViewController: UITableViewController {
let students = ["Nick", "Trevor", "Joseph", "Ruying", "Zhiyang", "Chris", "Jonathan", "Matt", "Tayler", "Jonathan", "Matt", "Jonathan", "Haolin", "Anthony", "Tianjiao", "Chris", "Bo", "Ashok", "Philip", "Grant", "Ishank", "Stephen", "Benedict", "Xiangqing"]
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
@fisherds
fisherds / ScoreKeeper.swift
Last active March 8, 2018 16:57
Code used in the ScoreKeeper Lab
import UIKit
class ViewController: UIViewController {
// Interface Builder Connections redacted
var roundNumber = 1
var playerScores = [0, 0, 0, 0]
var scoreTextFields = [UITextField]()
var scoresListTextViews = [UITextView]()
@fisherds
fisherds / ColorSliders_updateView.swift
Created December 3, 2014 20:21
Swift code added to update the background color of the view to the slider values
override func viewDidLoad() {
super.viewDidLoad()
redSlider.value = 0.71
greenSlider.value = 0.04
blueSlider.value = 0.22
alphaSlider.value = 1.0
updateView()
}
func updateView() {
@fisherds
fisherds / SwiftBasics.swift
Last active February 28, 2018 18:44
Code used in our Swift Playgrounds lecture
var myVariable = 42
myVariable = 50
let myConstant = 42
//myConstant = 50
let scores = [75, 52, 93, 87, 41, 83]
var totalPassing = 0
for score in scores {
if score >= 60 {
totalPassing += 1