Skip to content

Instantly share code, notes, and snippets.

View HarrisHan's full-sized avatar
🎯
Focusing

Harris HarrisHan

🎯
Focusing
View GitHub Profile
@HarrisHan
HarrisHan / gist:a71b7584d10adf6478fb8c4749128574
Created January 11, 2017 08:11
beginningOfDay and endOfDay
+ (NSDate *)beginningOfDay:(NSDate *)date;
{
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:( NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond ) fromDate:date];
[components setHour:0];
@HarrisHan
HarrisHan / this is a category for NSString to calculate the lengh of a string
Last active August 20, 2016 05:46
limit textField textView input char length
+ (NSUInteger)countLengthOfString:(NSString *)textString {
NSUInteger strlength = 0;
char *p = (char *)[textString cStringUsingEncoding:NSUnicodeStringEncoding];
for (int i = 0; i < [textString lengthOfBytesUsingEncoding:NSUnicodeStringEncoding]; i++) {
if (*p) {
p++;
strlength++;
@darkfall
darkfall / gist:13001c901edf0dc9fb85
Last active January 24, 2021 10:03
get objc subclasses via private runtime info
#include <objc/objc-runtime.h>
// from objc_runtime_new.h with some simplifications
#if __LP64__
typedef uint32_t mask_t;
#define FAST_DATA_MASK 0x00007ffffffffff8UL
#else
typedef uint64_t mask_t;
#define FAST_DATA_MASK 0xfffffffcUL
@congbo
congbo / charNumber
Last active August 8, 2018 03:23
计算NSString中英文字符串的字符长度,及按字符长度截取
//计算NSString中英文字符串的字符长度。ios 中一个汉字算2字符数
- (int)charNumber:(NSString*)strtemp
{
int strlength = 0;
char* p = (char*)[strtemp cStringUsingEncoding:NSUnicodeStringEncoding];
for (int i = 0; i < [strtemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding]; i++) {
if (*p) {
p++;
strlength++;
} else {
@steipete
steipete / PSPDFUIKitMainThreadGuard.m
Last active May 27, 2024 12:11
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit.
#import <objc/runtime.h>
#import <objc/message.h>
@zliuva
zliuva / gist:1084476
Last active July 31, 2023 21:32
A minimal Mach-o x64 executable for OS X
; A minimal Mach-o x64 executable for OS X (also see below Mountain Lion version)
;
; $ nasm -f bin -o tiny_hello tiny_hello.s
; $ chmod +x tiny_hello
; $ ./tiny_hello
; Hello World!
; $
; c.f.
; http://osxbook.com/blog/2009/03/15/crafting-a-tiny-mach-o-executable/ ( the original tiny mach-o executable )