汇编是直接跟硬件打交道的, 于是在学习汇编的同时,不经意间就了解到计算机的工作原理。
这是饭前开胃菜,作者从什么是电流开始,讲加法器、数字逻辑、触发器、CPU 原理、外设等,是计算机(硬件)组成原理的科普向轻松读物
#!/usr/bin/env python | |
from __future__ import annotations | |
import os | |
from pathlib import Path | |
from segment_anything import sam_model_registry, SamAutomaticMaskGenerator, SamPredictor | |
import cv2 | |
import numpy as np | |
import torch | |
from tqdm import tqdm |
import SwiftUI | |
import PlaygroundSupport | |
struct Desktop: View { | |
var body: some View { | |
ZStack { | |
// Image(uiImage: #imageLiteral(resourceName: "IMG_6281.JPG")) | |
Color(UIColor.systemBlue) | |
macOS() | |
} |
import UIKit | |
extension String { | |
var glyphCount: Int { | |
let richText = NSAttributedString(string: self) | |
let line = CTLineCreateWithAttributedString(richText) | |
return CTLineGetGlyphCount(line) | |
} |
private final class BundleToken {} | |
extension UIImage { | |
convenience init?(namedInBundle name: String) { | |
let bundle = Bundle(for: BundleToken.self) | |
self.init(named: name, in: bundle, compatibleWith: nil) | |
} | |
} | |
UIImage(namedInBundle: "123") |
func requestWith(endUrl: String, imageData: Data?, parameters: [String : Any], onCompletion: ((JSON?) -> Void)? = nil, onError: ((Error?) -> Void)? = nil){ | |
let url = "http://google.com" /* your API url */ | |
let headers: HTTPHeaders = [ | |
/* "Authorization": "your_access_token", in case you need authorization header */ | |
"Content-type": "multipart/form-data" | |
] | |
Alamofire.upload(multipartFormData: { (multipartFormData) in |
func copyFolder(){ | |
// Get the resource folder | |
if let resourceMainPath = Bundle.main.resourcePath{ | |
var isDirectory = ObjCBool(true) | |
// Get the path of the folder to copy | |
let originPath = (resourceMainPath as NSString).appendingPathComponent("NameOfFolder") | |
// Get the destination path, here copying to Caches | |
let destinationPath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first! |
extension String { | |
func snakeCased() -> String? { | |
let pattern = "([a-z0-9])([A-Z])" | |
let regex = try? NSRegularExpression(pattern: pattern, options: []) | |
let range = NSRange(location: 0, length: self.characters.count) | |
return regex?.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "$1_$2").lowercased() | |
} | |
} |
// | |
// ImageResizer.swift | |
// | |
// Created by Alex Seifert on 18/06/2016. | |
// http://www.alexseifert.com | |
// | |
import Foundation | |
import Cocoa |