Skip to content

Instantly share code, notes, and snippets.

Yoshimasa Niwa niw

View GitHub Profile
niw / dump_crashlytics_session.rb
Created Mar 20, 2019
A command line interface to find a single crash session stacktrace in Crashlytics.
View dump_crashlytics_session.rb
# A command line interface to find a single crash session stacktrace in Crashlytics.
# This is impossible by using their web dashboard interface.
# Usage: `ruby dump_crashlytics_session.rb BEARER_TOKEN PROJECT_ID SESSION_ID`
# The session ID is [`[CLSReport identifiter]`](
# The project ID is an unique ID for each application, you can find in Fabric settings page.
# The bearer token is an authentication token, you can find it in web browser inspector on Fabric pages.
require "net/https"
niw / RingerSwitchObserver.h
Last active Mar 14, 2019
Get current iPhone/iPad ringer switch (mute switch) state and change events
View RingerSwitchObserver.h
@import Foundation;
FOUNDATION_EXTERN NSString * const RingerSwitchDidChangedNotification;
@interface RingerSwitchObserver : NSObject
@property (nonatomic, readonly, getter=isSlient) BOOL silent;
niw / a.m
Created Jan 17, 2019
`ascending` and `descending` are confusing.
View a.m
@import Foundation;
int main()
NSDate * const a = [[NSDate alloc] initWithTimeIntervalSince1970:0];
NSDate * const b = [[NSDate alloc] initWithTimeIntervalSince1970:1];
NSLog(@"%d", (int)[a compare:b]); // -1 = NSOrderedAscending
NSLog(@"%d", (int)[a compare:a]); // 0 = NSOrderedSame
NSLog(@"%d", (int)[b compare:a]); // 1 = NSOrderedDescending
niw /
Created Nov 16, 2018
Reply to rdar://44539428 from Apple


When install Command Line Tools (macOS High Sierra version 10.13) for Xcode version 10.0 released on 9/17.2018 on High Sierra 10.13, it is installing out of sync tbd file to each /Systems Framework. Because of this, every time when we link one of these Framework by ld shows warning like

ld: warning: text-based stub file /System/Library/Frameworks//Foundation.framework/Foundation.tbd and library file /System/Library/Frameworks//Foundation.framework/Foundation are out of sync. Falling back to library file for linking.

In fact, /System/Library/Frameworks/Foundation.framework/Foundation.tbd is current-version: 1452.23, but /System/Library/Frameworks/Foundation.framework/Foundation is 1454.90.0.

Reply from Apple

niw / test_unicode_normalize.rb
Last active Oct 22, 2018
Testing `unorm2_normalize` with problematic Unicode code points.
View test_unicode_normalize.rb
str = "\u0336\u0344\u0357\u0343\u0314\u0351\u0340\u0300\u0340\u0360\u0314\u0357\u0315\u0301\u0344a"
p str
p str.unpack("U*").map{|a| "U+%04X" % a}
out = str.unicode_normalize(:nfc)
p out
p out.unpack("U*").map{|a| "U+%04X" % a}
View a.m
@import Foundation;
int main() {
NSMutableString *s = [[NSMutableString alloc] initWithString:@"🐱"];
[s replaceCharactersInRange:NSMakeRange(1, 1) withString:@"a"];
NSLog(@"%@", [s dataUsingEncoding:NSUTF8StringEncoding]); // nil
return 0;
niw /
Last active Dec 3, 2018
A script to download macOS 10.14 Mojave install image and create an install disk image
#!/usr/bin/env bash
set -e
readonly INSTALL_APP_PATH="/Applications/Install macOS"
if [[ -r "$INSTALL_APP_PATH/Contents/SharedSupport/InstallESD.dmg" ]]; then
echo "Found the install app, create an install disk image."
# Mojave install disk image requires about 7GB space.
niw / patch.diff
Created May 21, 2018
LLVM and Clang linker flag arguments should be quoted.
View patch.diff
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake
index fd5627eec..4ac6d6225 100644
--- a/cmake/modules/AddLLVM.cmake
+++ b/cmake/modules/AddLLVM.cmake
@@ -73,7 +73,7 @@ function(add_llvm_symbol_exports target_name export_file)
COMMENT "Creating export file for ${target_name}")
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
- LINK_FLAGS " -Wl,-exported_symbols_list,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
+ LINK_FLAGS " -Wl,-exported_symbols_list,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"")
niw / CMakeLists.txt
Last active May 14, 2018
Base CMakeLists.txt for making Clang plugins.
View CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
# Let CMake to find LLVM and Clang modules.
# See <>
niw /
Last active Aug 9, 2018
Using self-build toolchain with Xcode

Using self-build toolchain with Xcode

This is my personal memo to summarise a way to use self-build clang tool chain with Xcode for Objective-C project. Probably we can take same approach for Swift project.

In this way, we can take many extra approaches like analyse source code, apply modifications on the source code (source-to-source translation,) and so on.

Prepare a toolchain

You can’t perform that action at this time.