Skip to content

Instantly share code, notes, and snippets.

View gatherheart's full-sized avatar
🤗
Always Gather Heart

Milkybean gatherheart

🤗
Always Gather Heart
View GitHub Profile
@gatherheart
gatherheart / run_coroutine_in_another_thread.py
Created September 29, 2018 08:46 — forked from lars-tiede/run_coroutine_in_another_thread.py
Safely run a coroutine in another thread's asyncio loop and return the result
import threading
import asyncio
async def run_coro_threadsafe(self, coro, other_loop, our_loop = None):
"""Schedules coro in other_loop, awaits until coro has run and returns
its result.
"""
loop = our_loop or asyncio.get_event_loop()
# schedule coro safely in other_loop, get a concurrent.future back
@gatherheart
gatherheart / asyncio_loops.py
Created September 29, 2018 08:46 — forked from lars-tiede/asyncio_loops.py
asyncio + multithreading: one asyncio event loop per thread
import asyncio
import threading
import random
def thr(i):
# we need to create a new loop for the thread, and set it as the 'default'
# loop that will be returned by calls to asyncio.get_event_loop() from this
# thread.
loop = asyncio.new_event_loop()
@gatherheart
gatherheart / graphql-args-passing.md
Created November 12, 2020 09:05 — forked from loganpowell/graphql-args-passing.md
GraphQL Passing Arguments (parent, args, context, info)
@gatherheart
gatherheart / Image Caching OpenSource.md
Created April 21, 2021 08:55 — forked from linearhw/Image Caching OpenSource.md
이미지 캐싱 오픈소스 라이브러리에 대한 요약/정리

성능 비교하기

  • 테스트앱
  • 낮은 해상도 = 사진 크기: 10 ~ 50KB
  • 중간 해상도 = 사진 크기: 100 ~ 500KB + 5MB
  • 높은 해상도 = 사진 크기: 10 ~ 50MB
  • 기본 설정 = 설정: 메모리 100MB 디스크 150MB
  • 리사이즈 = (화면 너비 / 3)^2. iPhone 8+ 기준으로 414 pixel.

리사이즈 없이 테스트

so A and B are structurally identical
C reverses the order of the 8 and 32 bit Ints
and D substitutes a string for the Int8
then I try to read aaaa’s bits using B C and D overlays 😊
C is printing the 8 bits of the A integer j and then the first 8 bits of integer k but somehow that still works out to one
when I hit D it doesn’t find a string so prints a blank
but the important point is: it doesn’t check anything, and doesn’t crash
@gatherheart
gatherheart / implementationWithBlock.swift
Created January 18, 2022 16:39 — forked from neonichu/implementationWithBlock.swift
How to use imp_implementationWithBlock in Swift
import Foundation
import ObjectiveC.runtime
let myString = "foobar" as NSString
println(myString.description)
let myBlock : @objc_block (AnyObject!) -> String = { (sself : AnyObject!) -> (String) in
"✋"
}
@gatherheart
gatherheart / UILabelCountLines.swift
Created February 25, 2022 04:26 — forked from fuxingloh/UILabelCountLines.swift
iOS Swift: How to check if UILabel is truncated? Calculate number of lines for UILabel
func countLabelLines(label: UILabel) -> Int {
// Call self.layoutIfNeeded() if your view uses auto layout
let myText = label.text! as NSString
let rect = CGSize(width: label.bounds.width, height: CGFloat.greatestFiniteMagnitude)
let labelSize = myText.boundingRect(with: rect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: label.font], context: nil)
return Int(ceil(CGFloat(labelSize.height) / label.font.lineHeight))
}
@gatherheart
gatherheart / LocalCommunicationNotification.swift
Created November 15, 2022 02:33 — forked from Dexwell/LocalCommunicationNotification.swift
iOS 15 Local Communication Notification
var content = UNMutableNotificationContent()
content.title = "Title"
content.subtitle = "Subtitle"
content.body = "Text"
content.sound = nil
content.categoryIdentifier = "categoryName"
var personNameComponents = PersonNameComponents()
personNameComponents.nickname = "Sender Name"
@gatherheart
gatherheart / git-mv-with-history
Created December 6, 2022 04:34 — forked from emiller/git-mv-with-history
git utility to move/rename file or folder and retain history with it.
#!/bin/bash
#
# git-mv-with-history -- move/rename file or folder, with history.
#
# Moving a file in git doesn't track history, so the purpose of this
# utility is best explained from the kernel wiki:
#
# Git has a rename command git mv, but that is just for convenience.
# The effect is indistinguishable from removing the file and adding another
# with different name and the same content.
@gatherheart
gatherheart / readme.md
Created January 4, 2023 09:56 — forked from bgromov/readme.md
Compiling Swift framework with mixed-in Objective-C code

Problem

You can't use bridging headers within a framework.

Solution 1 (umbrella header):

Xcode will automatically create umbrella header for you Cocoa Framework project. That will be the file named <FrameworkName>.h in the <FrameworkName> group/folder (where the rest of your sources are).

  1. To include the required Obj-C header you need to set it as Public: select it in the project explorer (left pane) and change the property Target Membership (left—Inspectors—pane) from Project to Public.
  2. Open umbrella header (<FrameworkName>.h) and import the required header as: