Skip to content

Instantly share code, notes, and snippets.

View AmatsuZero's full-sized avatar
💭
I may be slow to respond.

Daubert Jiang AmatsuZero

💭
I may be slow to respond.
  • Tencent
  • Beijing, China
View GitHub Profile
@danielCarlosCE
danielCarlosCE / ContentSizePagingCollectionDelegate.swift
Last active June 28, 2022 15:40
Horizontal paging for collections based on the content size
//
// ContentSizePagingCollectionDelegate.swift
// CardsCarousel
//
// Created by Daniel Carlos Souza Carvalho on 2/20/21.
//
import UIKit
/// Horizontal paging for collections based on the content size
@ArtFeel
ArtFeel / CALayer+AnimationPlayback.swift
Last active November 15, 2023 23:06
Persistent Core Animations (Swift 4.2). All you need is `self.layer.makeAnimationsPersistent()` 😎
//
// CALayer+AnimationPlayback.swift
// Created by Philip Vasilchenko on 4/27/18.
//
import UIKit
// Pause animations of layer tree
//
// Technical Q&A QA1673:
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active July 12, 2024 03:33
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@proxpero
proxpero / Iso3166_1a2.swift
Last active February 20, 2024 16:44
A Swift 4.0 enum representing ISO 3166-1 alpha-2 (two letter country codes) Includes properties for country name and unicode flag.
// taken 2018-03-19 from wikipedia. https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
enum Iso3166_1a2: String {
case af = "AF"
case ax = "AX"
case al = "AL"
case dz = "DZ"
case `as` = "AS"
case ad = "AD"
case ao = "AO"
@steven2358
steven2358 / ffmpeg.md
Last active July 22, 2024 08:40
FFmpeg cheat sheet
#!/usr/bin/env python2
# lrdcq
# usage python2 unwxapkg.py filename
import sys, os
import struct
class WxapkgFile(object):
nameLen = 0
@Azoy
Azoy / install-swift-ubuntu.md
Last active December 9, 2022 03:42
Guide on how to install Swift on Ubuntu

Install Swift on Ubuntu

Requirements

  1. Ubuntu 14.04, 16.04, or 16.10

Step 1 - Dependencies

  1. Open up terminal
  2. Install core deps: sudo apt-get install clang libicu-dev git

Step 1.1 - Ubuntu 14.04 Clang

@cotkjaer
cotkjaer / CGRect+Center.swift
Last active November 23, 2023 06:15
Swift extensions to add "center" to CGRect
extension CGRect
{
/** Creates a rectangle with the given center and dimensions
- parameter center: The center of the new rectangle
- parameter size: The dimensions of the new rectangle
*/
init(center: CGPoint, size: CGSize)
{
self.init(x: center.x - size.width / 2, y: center.y - size.height / 2, width: size.width, height: size.height)
@alskipp
alskipp / ignoreNil.swift
Created May 6, 2016 00:04
How to ignore `nil` values using RxSwift without using❗️
// Create an `Observable` of Optional<Int>
let values: Observable<Int?> = [1, 2, .None, 3, .None, 4, 5].toObservable()
// Method 1: using a free function
// Requires passing the function to `flatMap`
func ignoreNil<A>(x: A?) -> Observable<A> {
return x.map { Observable.just($0) } ?? Observable.empty()
}
@steinwaywhw
steinwaywhw / One Liner to Download the Latest Release from Github Repo.md
Last active July 19, 2024 22:35
One Liner to Download the Latest Release from Github Repo
  • Use curl to get the JSON response for the latest release
  • Use grep to find the line containing file URL
  • Use cut and tr to extract the URL
  • Use wget to download it
curl -s https://api.github.com/repos/jgm/pandoc/releases/latest \
| grep "browser_download_url.*deb" \
| cut -d : -f 2,3 \
| tr -d \" \