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 SwiftUI | |
| class Favorites: ObservableObject { | |
| private var tasks: Set<String> | |
| let defaults = UserDefaults.standard | |
| init() { | |
| let decoder = JSONDecoder() | |
| if let data = defaults.value(forKey: "Favorites") as? Data { | |
| let taskData = try? decoder.decode(Set<String>.self, from: data) |
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 SwiftUI | |
| struct ContentView: View { | |
| @State var results = [TaskEntry]() | |
| var body: some View { | |
| List(results, id: \.id) { item in | |
| VStack(alignment: .leading) { | |
| Text(item.title) |
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
| func loadData() { | |
| guard let url = URL(string: "https://jsonplaceholder.typicode.com/todos") else { | |
| print("Invalid URL") | |
| return | |
| } | |
| let request = URLRequest(url: url) | |
| URLSession.shared.dataTask(with: request) { data, response, error in | |
| if let data = data { | |
| if let response = try? JSONDecoder().decode([TaskEntry].self, from: data) { |
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
| [ | |
| { | |
| "id": 1, | |
| "name": "sample-name-1" | |
| }, | |
| { | |
| "id": 2, | |
| "name": "sample-name-2" | |
| }, | |
| ] |
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 path = require('path'); | |
| const fs = require('fs'); | |
| const basePathToData = path.join(__dirname, 'path-to-your-json-data-file'); | |
| const getJsonData = function (basePathToData, filename) { | |
| var filename = path.join(basePathToData, filename); | |
| return JSON.parse(fs.readFileSync(filename, 'utf-8')); | |
| }; |
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 express = require('express') | |
| const app = express() | |
| var path = require('path') | |
| var bodyParser = require('body-parser') | |
| app.use(express.static(path.join(__dirname, 'build'))); | |
| var dataController = require('./dataController'); | |
| app.get('/api/data', dataController.getData); |
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 XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest(); | |
| var fs = require('fs') | |
| fs.readFile('birthdays', 'UTF-8', function ( err, contents ) { | |
| var birthdays = contents.toString().split('\n'); | |
| const bdayPeople = birthdayToday(birthdays); | |
| greetBirthday(bdayPeople); | |
| }) | |
| function birthdayToday(birthdays) { | |
| var results = [] |
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 XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest(); | |
| const mysql = require('mysql'); | |
| const config = require('./config'); | |
| const pool = mysql.createPool({ | |
| connectionLimit: 10, | |
| host: config.dbhost, | |
| user: config.dbuser, | |
| password: config.dbpass, | |
| database: config.dbname | |
| }); |
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 Combine | |
| import SwiftUI | |
| struct ImageViewController: View { | |
| @ObservedObject var url: LoadUrlImage | |
| init(imageUrl: String) { | |
| url = LoadUrlImage(imageURL: imageUrl) | |
| } | |
| var body: some View { |
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 ImageContentView : View { | |
| @State var url = "https://link-to-image" | |
| var body: some View { | |
| VStack { | |
| ImageView(url: url) | |
| } | |
| } |