Skip to content

Instantly share code, notes, and snippets.

@JeOam
JeOam / Animation.md
Last active February 18, 2024 21:18
iOS Core Animation: Advanced Techniques, Part 1: The Layer Beneath

Author: https://www.cyanhall.com/

1. The Layer Tree

Core Animation's original name is Layer Kit

Core Animation is a compositing engine; its job is to compose different pieces of visual content on the screen, and to do so as fast as possible. The content in question is divided into individual layers stored in a hierarchy known as the layer tree. This tree forms the underpinning for all of UIKit, and for everything that you see on the screen in an iOS application.

In UIView, tasks such as rendering, layout and animation are all managed by a Core Animation class called CALayer. The only major feature of UIView that isn’t handled by CALayer is user interaction.

There are four hierarchies, each performing a different role:

@JeOam
JeOam / Kafka.md
Last active October 9, 2023 17:13
Apache Kafka Notes

Apache Kafka is publish-subscribe messaging rethought as a distributed commit log.

@JeOam
JeOam / Structure.md
Last active April 18, 2023 06:52
Project Structure for Python (Tornado) Application

Project:

  • project/: A directory named with the project's name which stores the actual Python package
    • __init__py
    • app.py
    • settings.py
    • urls.py
    • models/
      • __init__.py
      • baes.py
  • handlers/
@JeOam
JeOam / exlog.py
Last active March 13, 2023 12:13
Extract error log information from logfle
#!/usr/bin/env python
# coding: utf-8
'''
Extract error log information from logfle
run:
$ python exlog.py file.log
Please enter an integer, last n (n > 1) day you want to extract:
Exactract finished.
@JeOam
JeOam / PyCharm.md
Last active August 22, 2022 18:31
PyCharm Tips
Keyboard Shortcuts Descption
Cmd-/ Comment/uncomment
Cmd + Alt + L Reformat code
Cmd-F Find text
Cmd-Shift-F Find text in files
Cmd-Plus Expand code block
Cmd-Minus Collapse code block
Cmd-B Goto declaration of current variable
Cmd-U Goto superclass
@JeOam
JeOam / NSZombieEnabled.md
Created July 8, 2014 02:05
NSZombieEnabled

NSZombieEnabled is an environment variable which controls whether the Foundation runtime will use zombies. When zombies are enabled, a deallocated object's class is dynamically changed to be _NSZombie, and by default, the memory region is never marked as free, although this can be controlled separately(so, remember to disable NSZombieEnabled for Archived Release Build).

The end result is that, with zombies enabled, messages to deallocated objects will no longer behave strangely or crash in difficult-to-understand ways, but will instead log a message and die in a predictable and debugger-breakpointable way. This is the tool to use when trying to track down over-releases and premature releases.

Zombies will take effect for all Objective-C objects that are deallocated through normal means, including most Cocoa classes as well as user-created classes. On 10.4 and earlier, a rather important exception to this is most/all TollFreeBridged classes, as they are deallocated using CoreFoundation which NSZombieEnab

@JeOam
JeOam / Location.md
Last active January 4, 2022 07:57
Get Current Location in iOS
@JeOam
JeOam / UICollectionView.md
Last active July 6, 2021 00:31
UICollectionView Tips

Add HeaderView in UICollectionView like UITableView's tableHeaderView:

{
    [self.collectionView registerNib:[UINib nibWithNibName:@"HeaderView" bundle:nil]
          forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
                 withReuseIdentifier: @"HeaderView"];
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView   viewForSupplementaryElementOfKind:(NSString *)kind  atIndexPath:(NSIndexPath *)indexPath{
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]){
        UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind   withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
@JeOam
JeOam / Algebra.md
Last active March 25, 2021 15:21
Bool Algebra in Computer Science

Except from Computer Systems: A Programmer's Perspective, Second Edition.

@JeOam
JeOam / Celery.md
Last active November 11, 2020 16:39
Celery Tips

#####What is Celery?
Celery is an asynchronous task queue. You can use it to execute tasks outside of the context of your application. The general idea is that any resource consuming tasks that your application may need to run can be offloaded to the task queue, leaving your application free to respond to client requests.

Celery has three core components:

  • The Celery client. This is used to issue background jobs.
  • The Celery workers. These are the processes that run the background jobs. Celery supports local and remote workers, so you can start with a single worker running on the same machine as your application server, and later add more workers as the needs of your application grow.
  • The message broker. The client communicates with the the workers through a message queue, and Celery supports several ways to implement these queues. The most commonly used brokers are RabbitMQ and Redis.