Skip to content

Instantly share code, notes, and snippets.

View Kjuly's full-sized avatar

Kaijie Yu Kjuly

View GitHub Profile
@Kjuly
Kjuly / ky_iOS7_note.m
Created September 16, 2013 04:27
Note for iOS7.0.
/* Status Bar
*
* Related threads:
* - https://devforums.apple.com/message/867059#867059
* - https://devforums.apple.com/thread/199395?start=0&tstart=0
*
* The relevant messages to override are:
*/
- (UIStatusBarStyle)preferredStatusBarStyle NS_AVAILABLE_IOS(7_0); // Defaults to UIStatusBarStyleDefault
- (BOOL)prefersStatusBarHidden NS_AVAILABLE_IOS(7_0); // Defaults to NO
@Kjuly
Kjuly / ky_grep_content_global.sh
Created August 4, 2013 15:02
Use grep to search "THE_TARGET_CONTENT" in all files. It'll list all files that include the content
// Search "THE_TARGET_CONTENT" in all .m files
find . -type f -iname "*.m" -exec grep -i "THE_TARGET_CONTENT" {} +
@Kjuly
Kjuly / ky_convert_12345678910_to_1234xxx8910.m
Last active December 18, 2015 16:29
Convert "1234567890" to "1234***8910" (Obj-C).
// Result: 1234***8910
NSString * original = @"12345678910";
NSError *error = nil;
NSRegularExpression * regex =
[NSRegularExpression regularExpressionWithPattern:@"\\d"
options:NSRegularExpressionCaseInsensitive
error:&error];
NSString * result =
[regex stringByReplacingMatchesInString:original
@Kjuly
Kjuly / ky_create_c_array_of_retained_pointers_under_arc.m
Last active December 16, 2015 04:38
Create a C array of retained pointers under ARC (Obj-C)
// Note calloc() to get zero-filled memory.
__strong SomeClass **dynamicArray = (__strong SomeClass **)calloc(sizeof(SomeClass *), entries);
for (int i = 0; i < entries; ++i)
dynamicArray[i] = [[SomeClass alloc] init];
// When you're done, set each entry to nil to tell ARC to release the object.
for (int i = 0; i < entries; ++i)
dynamicArray[i] = nil;
free(dynamicArray);
@Kjuly
Kjuly / ky_xcode_version_management.sh
Last active October 3, 2015 19:58
Xcode version management script
#!/bin/bash
cd $PROJECT_DIR
# BUILD_VERSION=`/usr/local/bin/git rev-parse --short HEAD`
BUILD_VERSION=`git rev-parse --short HEAD`
cd $BUILT_PRODUCTS_DIR/$PRODUCT_NAME.app
# Note: It's Info.plist, not Proj-Info.plist
RELEASE_VERSION=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" Info.plist)
/usr/libexec/PlistBuddy -c "Set CFBundleVersion $BUILD_VERSION" Info.plist
# here, 5 is my index of version part in |PreferenceSpecifiers| array
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:5:DefaultValue $RELEASE_VERSION ($BUILD_VERSION)" Settings.bundle/Root.plist
@Kjuly
Kjuly / ky_auto_change_topbar_position.js
Last active September 27, 2015 09:28
Auto change the topbar position type depend on scrollbar
/*!
* Author: Kjuly(Kj Yu)
* Date: 09/29/2011
* Feel free to use this code snippet. ;)
*
*/
$(function() {
$(window).scroll(function() {
if ($(this).scrollTop() >= 100) { // The Logo's above the topbar is 100px
@Kjuly
Kjuly / ky_webview_edit_code.js
Last active September 27, 2015 00:08
Make the web page editable anytime.
// Put it in as the browser address & press ENTER, after you have opened a web page.
javascript:document.body.contentEditable='true';document.designMode='on';void 0