os_log
random snippet:
#include <os/log.h>
mach_msg_type_number_t count = TASK_DYLD_INFO_COUNT;
task_dyld_info_data_t dyld_info;
kern_return_t kr = task_info(mach_task_self(),
TASK_DYLD_INFO,
reinterpret_cast<task_info_t>(&dyld_info),
&count);
dyld_all_image_infos* image_infos = (dyld_all_image_infos*)dyld_info.all_image_info_addr;
for(int i=0;i<(int)image_infos->infoArrayCount;i++) {
os_log(OS_LOG_DEFAULT, "LOGME: Image %d: %s\n", i, image_infos->infoArray[i].imageFilePath);
}
mach_msg_type_number_t thread_count = 0;
thread_act_array_t threads;
kr = task_threads(mach_task_self(), &threads, &thread_count);
os_log(OS_LOG_DEFAULT, "LOGME: Thread Count %d\n", (int)thread_count);
HEIC for CVS
Every time I try to do a quick print of photos for CVS I need to locally convert the ones I choose from HEIC to jpg.
Brainless convert:
for i in *.HEIC(:r) ; sips -s format jpeg "$i.HEIC" --out "$i.jpg"
git prompt.
# From https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
source ~/.git-prompt.sh export PS1='\[\033[38m\]\u@mbp\[\033[01;34m\] \w \[\033[31m\]$(__git_ps1 "(%s) ")\[\033[37m\]$\[\033[0m\] '
Fix Apple Watch Auto Unlock
Stolen from here from LongZheng
I’ve finally fixed it! I found a bunch of errors related to “AutoUnlock” in the Console that was hinting to me that there was some invalid state on my Mac with keys and plists not being reset properly. After clearing/resetting them, I can now successfully pair my watchOS 7 Series 3 to macOS 10.15.6.
Steps (follow at your own discretion)
- Open “Keychain Access” -> Passwords.
- In “View”, enable “Show Invisible Items”
- Search for “Auto Unlock”
- You should see a whole bunch of application passwords for “Auto Unlock: XXXX’s …”
- Select all records and delete (this will reset/disable auto unlock on other Macs if you use multiple Macs)
- Whilst still in “Keychain Access”, search for “AutoUnlock” (no space)
- There should be 4 entries for “tlk” “tlk-nonsync” “classA” “classC”
- Select 4 records and delete (don’t worry if they re-appear, the system repairs this automatically)
- Open “Finder” and navigate to “~/Library/Sharing/AutoUnlock”
- There should be two files “ltk.plist” and “pairing-records.plist”
- Delete both files
(Some users have reported better success restarting macOS at this stage) - Open “System Preferences” and try enabling auto unlock. You may need to enable it twice, the first attempt will fail.
flash!
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
UIView* snapshotView = [[UIView alloc] init];
snapshotView.translatesAutoresizingMaskIntoConstraints = false;
[window addSubview:snapshotView];
[NSLayoutConstraint activateConstraints:@[
[snapshotView.topAnchor constraintEqualToAnchor:window.topAnchor],
[snapshotView.leadingAnchor constraintEqualToAnchor:window.leadingAnchor],
[snapshotView.trailingAnchor constraintEqualToAnchor:window.trailingAnchor],
[snapshotView.bottomAnchor constraintEqualToAnchor:window.bottomAnchor]
]];
snapshotView.backgroundColor = [UIColor blueColor];
[UIView animateWithDuration:0.2
animations:^{
snapshotView.alpha = 0;
}
completion:^(BOOL finished) {
[snapshotView removeFromSuperview];
}];
Rebase without re-checkout
TL;DR: when using multiple branches, prefer to use “git rebase –onto origin/master origin/master ${branch}” if you want to checkout and then rebase a branch.
Let’s say you have the working history:
/-*-* A *-*-*-*-*-*-* origin/master \-*-*-* B
and you want to push the branch A because your CL has been approved. You have to rebase A on origin/master, then build and run test and do git cl push. Once this is done, you now have the following history:
*-*-*-*-*-*-*-@ origin/master (after push) \-*-*-* B
Now you want to go back to work on B. Until recently, I used the following commands (striked-ed out as I now consider them broken):
$ git checkout B
$ git rebase origin/master
This has the disadvantage of marking as dirty all the files that are in the delta between the point B diverged from origin/master in addition to all the files modified in B since the branch was created.
There is however a better way:
$ git rebase –onto origin/master origin/master B
This will still rebase B on top of origin/master, but will not checkout B first, so only the files that have been modified in B will be touched and considered dirty by the build. Depending on how large the change in origin/master have been, this can be the difference between rebuilding thousand of files and rebuilding just a few tens.
How to print Chromium string16 values from lldb using python scripts
I found this here: http://stackoverflow.com/questions/12923873/how-to-print-wchar-t-string-in-lldb with a minor tweak of if -> elif
Thanks stack overflow!
Python file:
$ cat ~/work/lldbscripts/unsignedshortptrsummary.py
import lldb
def unsignedshortptr_SummaryProvider(valobj, dict):
e = lldb.SBError()
s = u'"'
if valobj.GetValue() != 0:
i = 0
newchar = -1
while newchar != 0:
# read next wchar character out of memory
data_val = valobj.GetPointeeData(i, 1)
size = data_val.GetByteSize()
if size == 1:
newchar = data_val.GetUnsignedInt8(e, 0) # utf-8
elif size == 2:
newchar = data_val.GetUnsignedInt16(e, 0) # utf-16
elif size == 4:
newchar = data_val.GetUnsignedInt32(e, 0) # utf-32
else:
return "
if e.fail:
return '
i = i + 1
# add the character to our string 's'
if newchar != 0:
s = s + unichr(newchar)
s = s + u'"'
return s.encode('utf-8')
init file:
$ cat .lldbinit
command script import /Users/justincohen/work/lldbscripts/unsignedshortptrsummary.py
type summary add -F unsignedshortptrsummary.unsignedshortptr_SummaryProvider "unsigned short *"
Gives you:
(lldb) p new_text
(string16) $5 = {
(std::basic_string
(unsigned short *) _M_p = 0x110625cc "This is a string16!!"
}
}
Git clean. No seriously, clean it.
Working on Chrome, there are lots of dependencies that get pulled, and when I make untracked temporary changes in those dependancies sometimes I just want everything back to normal. So, here’s the scorched earth method:
git clean -f -f -x -d
This blows away everything git doesn’t know about. Then I do another clean dependency pull and I’m back to the beginning!
mach.h, dumping vm info
#import "mach/mach.h"
....
- (void)logTimer {
task_basic_info info;
mach_msg_type_number_t size = sizeof(info);
kern_return_t kerr = task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t)&info,
&size);
if ( kerr == KERN_SUCCESS ) {
NSLog(@"task_info: %d.2MB\n", info.resident_size / 1048576);
}
else {
NSLog(@"task_info failed with error %d ( 0x%08d ), '%s'\n",
kerr, kerr, mach_error_string(kerr));
}
}