Skip to content

Instantly share code, notes, and snippets.

View tikipatel's full-sized avatar

Pratikbhai Patel tikipatel

  • San Francisco, CA
View GitHub Profile
@tikipatel
tikipatel / rref.swift
Created November 29, 2022 04:12
Reduced Row Echelon Form in Swift
// Int and Double implementation of RREF
func rref(matrix: [[Int]]) -> [[Double]] {
var lead = 0
var returnMatrix = matrix.map({ (row) in
return row.map { Double($0) }
})
let rowCount = matrix.count
@tikipatel
tikipatel / sieve_primes.swift
Created April 3, 2022 20:34
Gets primes by Sieve of Eratosthenes
func findPrimes(upTo limit: Int) -> [Int] {
guard limit > 1 else { return [] }
var sieve = Array(repeating: true, count: limit + 1)
sieve[0] = false
sieve[1] = false
for i in 2...limit where sieve[i] {
for j in stride(from: i*i, through: limit, by: i) {
@tikipatel
tikipatel / resources.txt
Created April 24, 2020 15:47
Just a list of resources that I have found useful
Markdown files online -- https://stackedit.io/app#
@tikipatel
tikipatel / ZoomLevels.md
Last active April 24, 2020 15:32
Quick reference how zoom levels work on MapBox and Google Maps

NOTE -- THIS IS NOT MY CONTENT AND IS NOT MEANT TO PLAGERIZE ANY REFERENCED RESOURCES. I HAVE PUT THESE TWO IN A SINGLE PLACE AND REFERECED TO OFFICIAL DOCUMENTATION.

Google Maps

Scroll to "Zoom" section -- https://developers.google.com/maps/documentation/ios-sdk/views

Zoom

The zoom level of the camera determines the scale of the map. At larger zoom levels more detail can be seen on the screen, while at smaller zoom levels more of the world can be seen on the screen. At zoom level 0, the scale of the map is such that the entire world has a width of approximately 256 points.

Increasing the zoom level by 1 doubles the width of the world on the screen. Hence at zoom level N, the width of the world is approximately 256 * 2N, i.e., at zoom level 2, the whole world is approximately 1024 points wide. Note that the zoom level need not be an integer. The range of zoom levels permitted by the map depends on a number of factors including location, map type and screen size. The following list shows the appr

@tikipatel
tikipatel / RounderCorner.swift
Created April 10, 2020 16:28
Defines a shape that is rounded with given corners and radius.
import SwiftUI
struct RoundedCorner: Shape {
var radius: CGFloat
var corners: UIRectCorner
func path(in rect: CGRect) -> Path {
let path = UIBezierPath(
roundedRect: rect,
byRoundingCorners: corners,
@tikipatel
tikipatel / daily_coder_march_13_2020.swift
Created March 13, 2020 20:56
Daily Coder Problem March 13, 2020
/*
Given a list of numbers and a number k, return whether any two numbers from the list add up to k.
For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17.
Bonus: Can you do this in one pass?
*/
let testArray = [10, 15, 3, 7]
let testTarget = 17
@tikipatel
tikipatel / TableViewAnimatedRearranging.swift
Last active September 24, 2019 07:53
An example of animated rearranging of a UITableView
import PlaygroundSupport
import UIKit
/**
This playground is an example of how how to move cells when the data source of a table view
changes.
*/
class TVDataSource: NSObject, UITableViewDataSource {
private let tableView: UITableView
@tikipatel
tikipatel / MultiplicativePersistence.swift
Created March 21, 2019 19:37
Prints out steps of multiplicative persistence
func multiplicativePersistence(of int: UInt64, step: Int = 1) {
if step == 1 {
print("Step 0:", int)
}
var mutatingInt = int
var remainder: UInt64
var currentValue: UInt64 = 1
while mutatingInt != 0 {
(mutatingInt, remainder) = mutatingInt.quotientAndRemainder(dividingBy: 10)
@tikipatel
tikipatel / SoundSelectionViewController.swift
Created May 6, 2017 18:24
Select a sound to play from a picker view
import UIKit
import AVFoundation
class SoundViewController: UIViewController {
var sounds: [String] = ["island", "jingle", "starwars", "wind", "does_no_exist"] // Files that will possibly available to paly
var selectedSoundString: String? = nil
var player: AVAudioPlayer?
//: Playground - noun: a place where people can play
import UIKit
import Foundation
import PlaygroundSupport
let canvasWidth: CGFloat = 500.0
let canvasHeight: CGFloat = 500.0
let padding: CGFloat = 10.0