Skip to content

Instantly share code, notes, and snippets.

@adamontherun
adamontherun / aware_app.dart
Last active September 4, 2022 16:04
an example of a platform aware vs unaware Flutter app
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:platformaware/screens/aware_home_screen.dart';
class AwareApp extends StatelessWidget {
const AwareApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
@adamontherun
adamontherun / cloudSettings
Created November 28, 2019 01:05
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-11-28T01:05:48.155Z","extensionVersion":"v3.4.3"}
@adamontherun
adamontherun / PlanetsJSONClient.swift
Created May 13, 2017 19:02
JSON client for connecting to the StarWars Planets endpoint
import Foundation
enum PlanetsJSONClient: StarwarsJSONClient {
// MARK: - Public methods
static func fetchPlanets(page: Int = 1, _ completionHandler: @escaping StarWarsJSONCompletionHandler) {
AlamoFireJSONClient.makeAPICall(to: PlanetEndPoint.planets(page: page)) { (result) in
self.handle(result: result, completionHandler: completionHandler)
}
@adamontherun
adamontherun / PlanetEndPoint.swift
Created May 13, 2017 18:55
Models the Planets endpoint from the StarWars API.
import Foundation
import Alamofire
/// Models the Planets endpoint from the StarWars API.
enum PlanetEndPoint: AlamofireEndPoint {
case searchPlanets(forTerm: String, page: Int)
case planets(page: Int)
case planet(id: Int)
@adamontherun
adamontherun / StarWarsJSONClient.swift
Created May 13, 2017 18:50
Types that conform to this can return results from the StarWars JSON API
import Foundation
/// All of the StarWars endpoints return a [String : Any] json object
typealias StarWarsJSONCompletionHandler = (Result<[String : Any]>)->()
/// The base URL for connecting to the StarWars json endpoint
let baseURL = "http://swapi.co/api"
/// Types that conform to this can return results from the StarWars JSON API
protocol StarwarsJSONClient {
@adamontherun
adamontherun / AlamofireJSONClient.swift
Created May 13, 2017 18:45
/// Used to connect to any JSON API that is modeled by an AlamofireEndpoint
import Foundation
import Alamofire
/// The Reponse type from Alamofire is Any
typealias AlamofireJSONCompletionHandler = (Result<Any>)->()
/// Used to connect to any JSON API that is modeled by an AlamofireEndpoint
enum AlamoFireJSONClient {
static func makeAPICall(to endPoint: AlamofireEndPoint, completionHandler:@escaping AlamofireJSONCompletionHandler) {
@adamontherun
adamontherun / Result.swift
Created May 13, 2017 18:37
The response from a method that can result in either a successful or failed state
import Foundation
/// The response from a method that can result in either a successful or failed state
public enum Result<T> {
case success(T)
case failure(Error)
}
@adamontherun
adamontherun / AlamofireEndpoint.swift
Last active May 13, 2017 18:36
Swift protocol for modeling an Alamofire API endpoint
/// Types that conform to this model an API endpoint that can be connected to via Alamofire
protocol AlamofireEndPoint {
/// Provides all the information required to make the API call from Alamofire
func provideValues()-> (url: String, httpMethod: HTTPMethod, parameters:[String:Any]?,encoding: ParameterEncoding)
var url: URLConvertible { get }
var httpMethod: HTTPMethod { get }
var parameters: [String: Any]? { get }
var encoding: ParameterEncoding { get }
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import zipfile, os, shutil
# unzip the file
zip_ref = zipfile.ZipFile('data/train.zip', 'r')
zip_ref.extractall('data')
zip_ref.close()
os.remove('data/train.zip')
#rename train to dogscatsredux
os.rename('data/train', 'data/dogscatsredux')