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 / pi_from_primes.py
Created March 15, 2016 20:08
Calculating value of pi using prime numbers
from operator import mul
def sievePrimes(maximum):
primes = dict.fromkeys(range(3,maximum+1,2),True)
sieveList = [2]
for num in sorted(primes):
if primes[num] == True:
sieveList.append(num)
j = num ** 2
while j < maximum:
extension String {
///Get array of individual strings
func array() -> [String] {
return self.characters.map({ (char) -> String in
return String(char).lowercaseString
})
}
///Get `NSCountedSet` from string
func countedSet() -> NSCountedSet {
@tikipatel
tikipatel / coprime_pi.py
Created March 13, 2017 19:59
Get an approximation of π using probabilities of coprime integers
from random import randint
import math
def gcd(x,y):
while y!= 0:
(x, y) = (y, x % y)
return x
rolls = 1000
max_int = 10000000000
@tikipatel
tikipatel / coprime_pi.swift
Last active March 13, 2017 20:27
Get an approximation of π using probabilities of coprime integers
import Foundation
let rolls = 1_000_000
func getPi() -> Double {
func gcd(x: Int, y: Int) -> Int {
var internal_x = x
var internal_y = y
@tikipatel
tikipatel / ViewController.swift
Last active April 28, 2017 20:35
Auto-expanding UITableViewCell
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tableView.estimatedRowHeight = 44
@tikipatel
tikipatel / apéys_constant.swift
Created May 4, 2017 21:20
Numerical calculation of Apéry's Constant
import Foundation
func gcd(_ m: Int, _ n: Int) -> Int {
var a = 0
var b = max(m, n)
var r = min(m, n)
while r != 0 {
a = b
b = r
//: 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
@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?
@tikipatel
tikipatel / Playground.swift
Last active November 28, 2018 13:24
Quick Playground for adding rows to the top of a tableview
import PlaygroundSupport
import UIKit
class TableViewManager: NSObject, UITableViewDataSource, UITableViewDelegate {
weak var tableView: UITableView?
var strings = ["a", "b", "c", "d","e", "f", "g", "h","i", "j", "k", "dl","am", "bn", "co", "dp","aq", "br", "cs", "dt","au", "bv", "cw", "dx","ay", "bz", "caa", "dbb","acc", "bdd", "cee", "dff","agg", "bhh", "cii", "djj","akk", "bll", "cmm", "dnn","aoo", "bpp", "cqq", "zrr"]
func add(data: [String]) {