Skip to content

Instantly share code, notes, and snippets.

View chaitanyaSoni96's full-sized avatar

Chaitanya Soni chaitanyaSoni96

View GitHub Profile
@chaitanyaSoni96
chaitanyaSoni96 / podman-deploy.sh
Last active March 3, 2026 21:19
Deploy podman images to VPS
#!/usr/bin/env bash
set -euo pipefail
# ── Arguments ─────────────────────────────────────────────────────────────────
usage() {
echo "Usage: $0 <host> <compose-file> [remote-dir] [--tag <version>]"
exit 1
}

TicTacToe

Overview

This app allows the user to enter their name and play a Tic-Tac-Toe game against a computer opponent. The user plays as "X" and taps on the game board to make their moves. After each turn, the computer will randomly select a move.


Challenge 1: Project Setup

  • Create a project named TicTacToe in Xcode.
lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let container = NSPersistentContainer(name: "CoreDataExample")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
let start = CFAbsoluteTimeGetCurrent()
// run your work
let diff = CFAbsoluteTimeGetCurrent() - start
print("Took \(diff) seconds")
@chaitanyaSoni96
chaitanyaSoni96 / ViewController.swift
Created June 21, 2020 12:05
Alamofire implementation for generic api calls in swift
import UIKit
import Alamofire
import iOSDropDown
class ViewController: UIViewController {
//Variables
@IBOutlet weak var dropDownTxtField: DropDown!
You can make a deep copy of your object via the following extension functions:
import UIKit
import Realm
import RealmSwift
protocol RealmListDetachable {
func detached() -> Self
}
@chaitanyaSoni96
chaitanyaSoni96 / HexToUIColor1
Created June 14, 2019 11:12
UIColor Extensions
A great Swift implementation (updated for Xcode 7) using extensions, pulled together from a variety of different answers and places. You will also need the string extensions at the end.
Use:
let hexColor = UIColor(hex: "#00FF00")
NOTE: I added an option for 2 additional digits to the end of the standard 6 digit hex value for an alpha channel (pass in value of 00-99). If this offends you, just remove it. You could implement it to pass in an optional alpha parameter.
-(void)method:(NSString *)str withCompletion:(void (^)(NSArray* arr))callback{
NSMutableArray *a = [NSArray new];
[a addObject:str];
callback(a);
}
[YourClassName method:@"" withCompletion:^(NSArray *arr) {
NSLog(arr.count)
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"JBlues" message:@"Please login to see products" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAct = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:okAct];
[self presentViewController:alert animated:true completion:nil];
extension Array where Element:Equatable {
func removeDuplicates() -> [Element] {
var result = [Element]()
for value in self {
if result.contains(value) == false {
result.append(value)
}
}