Skip to content

Instantly share code, notes, and snippets.

View Uhucream's full-sized avatar
:octocat:

Takashi Uhucream

:octocat:
View GitHub Profile
@Dev1an
Dev1an / CGPoint+SIMD.swift
Created August 8, 2020 10:32
SIMD extensions for CGPoint and CGSize
import struct CoreGraphics.CGSize
import struct CoreGraphics.CGPoint
import struct CoreGraphics.CGFloat
extension CGSize: SIMD {
public typealias MaskStorage = SIMD2<CGFloat.NativeType.SIMDMaskScalar>
public subscript(index: Int) -> CGFloat {
get {
index == 0 ? width : height
@SpectralDragon
SpectralDragon / PreviewContextMenu.swift
Created April 8, 2020 19:22
Simple way to implement preview context menu for SwiftUI
//
// ContentView.swift
// PreviewSwiftUI
//
// Created by v.prusakov on 4/8/20.
// Copyright © 2020 v.prusakov. All rights reserved.
//
import SwiftUI
import Combine
import CoreData
import Foundation
class CDPublisher<Entity>: NSObject, NSFetchedResultsControllerDelegate, Publisher where Entity: NSManagedObject {
typealias Output = [Entity]
typealias Failure = Error
private let request: NSFetchRequest<Entity>
private let context: NSManagedObjectContext
@darrarski
darrarski / FetchedResultsPublisher.swift
Last active November 9, 2023 08:31
Swift-Combine-CoreData-Fetched-Results-Publisher
import Combine
import CoreData
public final class FetchedResultsPublisher
<ResultType>
: Publisher
where
ResultType: NSFetchRequestResult
{
extension UIImage {
/// Returns cost for the given image by approximating its bitmap size in bytes in memory.
/// SEE ALSO: https://github.com/kean/Nuke/blob/master/Sources/ImageCache.swift
var cost: Int {
// bytesPerRow * height gives a rough estimation of how much memory
// image uses in bytes. In practice this algorithm combined with a
// concervative default cost limit works OK.
guard let cgImage = self.cgImage else {
return 1
@mayankk2308
mayankk2308 / boost-low-pri-macOS.sh
Created July 17, 2018 17:35
Boost Low-Priority Tasks on macOS
# Useful for improving Time Machine backup prep. times, Mac App Store install speeds, etc.
sudo sysctl debug.lowpri_throttle_enabled=0
# To restore defaults
sudo sysctl debug.lowpri_throttle_enabled=1
@Bigigrammer
Bigigrammer / HTML_to_NSAttributedString.swift
Last active December 29, 2022 09:00
This extension convert HTML to NSAttributedString each other. It works on Swift4.
extension String {
func convertAttributedString() -> NSAttributedString?{
let html = self._removePT()
let encoded = html.data(using: String.Encoding.utf8)!
let attributedOptions : [NSAttributedString.DocumentReadingOptionKey : Any] = [
.documentType : NSAttributedString.DocumentType.html,
.characterEncoding : String.Encoding.utf8.rawValue
]
do {
let attributedTxt = try NSAttributedString(data: encoded, options: attributedOptions, documentAttributes: nil)
@shahbaz-momi
shahbaz-momi / Bin2Img.kt
Created May 10, 2018 21:06
Binary to image converter in Kotlin
package com.asdev.bin2img
import java.awt.Color
import java.awt.image.BufferedImage
import java.io.ByteArrayOutputStream
import java.io.File
import java.nio.file.Files
import javax.imageio.ImageIO
/**
//
// ObjcViewController.m
// FilterCam
//
// Created by B Gay on 11/3/17.
// Copyright © 2017 B Gay. All rights reserved.
//
#import "ObjcViewController.h"
#import <AVFoundation/AVFoundation.h>
@dimohamdy
dimohamdy / KeyPath.swift
Last active December 11, 2023 14:58
Accessing Dictionaries with Key Paths
/*
Thanks for @olebegemann
code of keypath from this link
https://oleb.net/blog/2017/01/dictionary-key-paths/
*/
struct KeyPath {
var segments: [String]
var isEmpty: Bool { return segments.isEmpty }