Skip to content

Instantly share code, notes, and snippets.

View ramzesenok's full-sized avatar
:octocat:

Roman Mirzoyan ramzesenok

:octocat:
View GitHub Profile
@ramzesenok
ramzesenok / calc.swift
Last active October 17, 2021 10:42
Here's my attempt to create a calculator, that takes a string as an input, parses it and calculates the result. Key difficulties: taking the operator's precedence and parenthesis in account. Operates only on integer values. Solved using an AST
// MARK: - Data Structures
enum Operation: String {
case add = "+"
case subtract = "-"
case multiply = "*"
case divide = "/"
var action: (Int, Int) -> Int {
switch self {
@zappycode
zappycode / NSImageToJpeg.swift
Last active June 12, 2024 02:15
Coverting an NSImage into JPEG Data
func jpegDataFrom(image:NSImage) -> Data {
let cgImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil)!
let bitmapRep = NSBitmapImageRep(cgImage: cgImage)
let jpegData = bitmapRep.representation(using: NSBitmapImageRep.FileType.jpeg, properties: [:])!
return jpegData
}