By Justin on May 4, 2026
Sometimes you just need to:
template("patch_file") {
assert(defined(invoker.patch_path),
"patch_path must be defined for $target_name")
assert(defined(invoker.source_file),
"source_file must be defined for $target_name")
action(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
script = "patch.py"
sources = [
invoker.patch_path,
invoker.source_file,
]
outputs = [ "$target_gen_dir/" + invoker.source_file ]
args = rebase_path(sources, root_build_dir) +
rebase_path(outputs, root_build_dir)
}
}
patch_file("patch_SomeFile_m") {
patch_path = "patches/path_to_SomeFile.m.diff"
source_file = "src/path/to/SomeFile.m"
}
And then you need to:
sources -= [ "src/path/to/SomeFile.m" ]
sources += get_target_outputs(":patch_SomeFile_m")
deps += [ ":patch_SomeFile_m" ]
For fun and profit.
Posted in Uncategorized |
By Justin on February 8, 2026
git reset HEAD^ ios_internal && git commit --amend --no-edit
Posted in Uncategorized |
By Justin on October 3, 2024
Posted in Uncategorized |
By Justin on October 19, 2023
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);
Posted in Uncategorized |
By Justin on April 30, 2023
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"
Posted in Uncategorized |
By Justin on March 21, 2023
# 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\] '
Posted in Uncategorized |
By Justin on October 28, 2020
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.
Posted in Uncategorized |
By Justin on December 27, 2019
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];
}];
Posted in Uncategorized |
By Justin on January 3, 2014
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.
Posted in Uncategorized |
By Justin on November 19, 2012
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 "" % size
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 >::_Alloc_hider) _M_dataplus = {
(unsigned short *) _M_p = 0x110625cc "This is a string16!!"
}
}
Posted in Uncategorized |