This file contains hidden or 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
| // Testing City model with JSON initializer against my NodeJS/Postgres API | |
| // Hubert Cross 2018 | |
| import UIKit | |
| import PlaygroundSupport | |
| print("Playground RUNNING") | |
| struct City : Codable { | |
| let name: String |
This file contains hidden or 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
| struct Todo : Codable { | |
| let title: String | |
| let userid: Int | |
| let id: Int | |
| let completed: Bool | |
| } | |
| enum SerializationError: Error { | |
| case missing(String) | |
| case invalid(String, Any) |
This file contains hidden or 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
| // parse the result as JSON, since that's what the API provides | |
| do { | |
| guard let returnObject = try JSONSerialization.jsonObject(with: returnData, options: []) | |
| as? [String: Any] else { | |
| print("error trying to convert data to JSON") | |
| return | |
| } | |
| // now we have the return object (it's a dictionary) |
This file contains hidden or 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 Foundation | |
| class City: NSObject, Codable { | |
| var name: String = "" | |
| var countrycode: String = "" | |
| var district: String = "" | |
| var population: Int = 0 | |
| init(name: String, countrycode: String, district: String, population: Int) { | |
| self.name = name |
This file contains hidden or 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
| /* | |
| https://jsbin.com/yakaxuwugo/edit?js,console | |
| You have a tree represented by an array. | |
| The 0th element of the array is the top node of the tree | |
| The 1st element is the left child, the 2nd is the right | |
| The 3rd and 4th element are the children of the 1st element | |
| The 5th and 6th elements are the children of the 2nd element, and so on. | |
| Find out which branch of the top node has the the child nodes with the greatest sum |
This file contains hidden or 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
| const PageItem = props => { | |
| const liClassName = (props.activePage === props.pageName) ? "page-item active" : "page-item"; | |
| return ( | |
| <li className={liClassName}><a className="page-link" href="#">{props.pageName}</a></li> | |
| ); | |
| } | |
| class Pagination extends React.Component { | |
| constructor(props) { |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>canvas tinkering</title> | |
| </head> | |
| <body> | |
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
| <script> | |
| $(document).ready(function() { |
This file contains hidden or 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
| const pool = require('../services/pgdatabase'); | |
| module.exports.get = function get(req, res, next) { | |
| console.log("Cities GET service"); | |
| console.log("wtf1"); | |
| return pool().query('SELECT * FROM city LIMIT 10;') | |
| .then(function(res) { | |
| console.log("debug1"); | |
| console.log(res.rows) |
This file contains hidden or 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 asyncForEach(array, callback) { | |
| const results = []; | |
| for (let index = 0; index < array.length; index += | |
| results.push(callback(array[index], index, array) | |
| } | |
| await Promise.all(results); | |
| } |
NewerOlder