Skip to content

Instantly share code, notes, and snippets.

Will Han xingheng

Block or report user

Report or block xingheng

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@xingheng
xingheng / launchctl-reload.sh
Created Jan 22, 2019
Extend the load/unload/reload subcommands for launchctl.
View launchctl-reload.sh
function _launchctl_unload() {
local plist_file=$1
test -f $plist_file || { echo "Invalid launchctl file for unloading!"; return; }
local label_name=$(defaults read $(readlink -f $plist_file) Label)
command launchctl stop $label_name || { echo "Failed to stop the service "$label_name ; return; }
command launchctl unload -w $plist_file || { echo "Failed to unload the file "$plist_file ; return; }
}
@xingheng
xingheng / launchctl-reload.sh
Created Jan 22, 2019
Extend the load/unload/reload subcommands for launchctl.
View launchctl-reload.sh
function _launchctl_unload() {
local plist_file=$1
test -f $plist_file || { echo "Invalid launchctl file for unloading!"; return; }
local label_name=$(defaults read $(readlink -f $plist_file) Label)
command launchctl stop $label_name || { echo "Failed to stop the service "$label_name ; return; }
command launchctl unload -w $plist_file || { echo "Failed to unload the file "$plist_file ; return; }
}
@xingheng
xingheng / xcopen.sh
Last active Mar 25, 2019
A handy script to open the xcode workspace/project file easily.
View xcopen.sh
#!/usr/bin/env bash
# set -x
target_dir=${1:-$(pwd)}
test ! -d ${target_dir} && { echo "Invalid target directory for searching!"; exit 1; }
readonly pass_signal=1
open_xcode_project () {
local ret=0
@xingheng
xingheng / UIView+EdgeBorder.h
Last active Jun 24, 2019
Add edge borders to UIView with autolayout, inspired from https://stackoverflow.com/a/23157272/1677041
View UIView+EdgeBorder.h
//
// UIView+EdgeBorder.h
// DSUtility
//
// Created by WeiHan on 6/6/17.
// Copyright © 2017 WeiHan. All rights reserved.
//
#import <UIKit/UIKit.h>
@xingheng
xingheng / UIControl+BlockAction.h
Created May 26, 2017
[Objective-C] A category for UIControl to bind action block easily.
View UIControl+BlockAction.h
//
// UIControl+BlockAction.h
// Pods
//
// Created by WeiHan on 5/26/17.
//
//
#import <UIKit/UIKit.h>
View tmux_cheatsheet.markdown

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@xingheng
xingheng / UIViewControllerAttemptRotationToDeviceOrientationWorkaround.m +[UIViewController attemptRotationToDeviceOrientation] does what it says on the tin: attempt to rotate to the device's orientation. It does, however, not rotate the view controller to match -[UIViewController supportedInterfaceOrientation] when the current device orientation is not supported by the view controller it polls. I whipped together th…
View UIViewControllerAttemptRotationToDeviceOrientationWorkaround.m
UIDeviceOrientation actualDeviceOrientation = [[UIDevice currentDevice] orientation];
BOOL changedDeviceOrientation = NO;
if ((self.supportedInterfaceOrientations & (UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight)) == 0)
{
if (UIScreen.mainScreen.bounds.size.width > UIScreen.mainScreen.bounds.size.height) // Device is in landscape orientation
{
[[UIDevice currentDevice] setValue:@(UIDeviceOrientationPortrait) forKey:@"orientation"];
changedDeviceOrientation = YES;
}
@xingheng
xingheng / Compatible.md
Created Nov 4, 2015 — forked from JeOam/Compatible.md
Compatible with iOS 6 and iOS 7: Layout
View Compatible.md

iOS 7 代码布局适配:坐标起点 iOS 7 中 UIViewController 使用了全屏布局的方式,也就是说导航栏和状态栏都是不占实际空间的,状态栏默认是全透明的,导航栏默认是毛玻璃的透明效果。例如在一个 view 中加入:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,100,100)];
[label setBackgroundColor:[UIColor greenColor]];
[self.view addSubview:label];

上面代码加在没有 UINavigationController 作为 rootViewController 的情况下,得到的效果是:

@xingheng
xingheng / build-dist.sh
Last active Aug 29, 2015 — forked from noamtm/build-dist.sh
iOS: Re-sign an app for distribution
View build-dist.sh
# This is not a ready-to-run script. It just shows the relevant command-line calls.
XC_WORKSPACE=path/to/MyApp.xcworkspace
XC_SCHEME=MyApp
XC_CONFIG=Release
ARCHIVE_PATH=dest/path/to/MyApp.xcarchive
EXPORT_PATH=dest/path/to/MyApp.ipa
DIST_PROFILE=NameOfDistributionProfile
# Build and archive. This can be done by regular developers, using their developer key/profile.
@xingheng
xingheng / build+archive.sh
Last active Aug 29, 2015 — forked from wmerrifield/build+archive.sh
A shell script to perform the equivalent of Xcode's "Build & Archive" command.
View build+archive.sh
#!/bin/sh
#
# Copyright (c) 2010 Warren Merrifield
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
You can’t perform that action at this time.