Skip to content

Instantly share code, notes, and snippets.

View trsathya's full-sized avatar

Sathya Rajaraman trsathya

  • San Francisco, CA
View GitHub Profile
@trsathya
trsathya / CurrencyStore.swift
Created January 13, 2018 13:30
An example implementation of CurrencyStoreType in github.com/trsathya/cryptex
import Foundation
import Cryptex
struct CurrencyStore: CurrencyStoreType {
static let shared: CurrencyStore = {
return CurrencyStore(currencies: CurrencyStore.currencies)
}()
let currencies: [Currency]
@trsathya
trsathya / RSA.swift
Last active February 9, 2018 10:01
Simple RSA key generation, encryption and decryption in Swift Playground
import Foundation
infix operator ^^ { }
func ^^ (radix: Int, power: Int) -> Int {
return Int(pow(Double(radix), Double(power)))
}
func euclidean(topLeft: Int, topRight: Int, bottomLeft: Int, bottomRight: Int, φ: Int) -> Int {
let leftFactor = topLeft/bottomLeft
var leftResult = topLeft - (bottomLeft * leftFactor)
http://swiftlang.ng.bluemix.net/#/repl/1717eb1a82ca957084bc404d38d36ea2e4589a08e221c8145998ded93d8d33d3
@trsathya
trsathya / osBuild
Created March 3, 2016 18:30
os build version alphanumeric string in Swift
func osBuild() -> String {
var size : Int = 0
var mib = [CTL_KERN, KERN_OSVERSION]
sysctl(&mib, u_int(mib.count), nil, &size, nil, 0)
var osBuild = [CChar](count: Int(size), repeatedValue: 0)
sysctl(&mib, u_int(mib.count), &osBuild, &size, nil, 0)
return String.fromCString(osBuild)!
}
@trsathya
trsathya / SumOfAllPrimeNumbersBelow2Million.swift
Last active January 8, 2016 09:43
Sum of all prime numbers below 2 million
// https://projecteuler.net/problem=10
let s = NSDate()
let n = 2_000_000
var isPrime : Bool = true
var primeNumbers = [Int]()
for var a = 3 ; a < n ; a+=2 {
isPrime = true
for var k = 0 ; k < primeNumbers.count && primeNumbers[k] <= Int(sqrt(Double(a))) ; k++ {
if a % primeNumbers[k] == 0 {
@trsathya
trsathya / MultiplesOf3And5Below1000.swift
Last active January 7, 2016 18:48
Sum of all the multiples of 3 and 5 below 1000 in swift
// https://projecteuler.net/problem=1
let n = 999
// Bad solution
var sum = 0
for i in 1...n {
if i % 3 == 0 || i % 5 == 0 {
sum += i
}

Keybase proof

I hereby claim:

  • I am trsathya on github.
  • I am trsathya (https://keybase.io/trsathya) on keybase.
  • I have a public key whose fingerprint is 4C01 F56A D48C 0269 1C67 60DC 3BCC E082 9E52 ACC4

To claim this, I am signing this object: