Skip to content

Instantly share code, notes, and snippets.

@xingheng
xingheng / launchctl-reload.sh
Created January 22, 2019 07:08
Extend the load/unload/reload subcommands for launchctl.
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 January 22, 2019 07:08
Extend the load/unload/reload subcommands for launchctl.
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 July 13, 2021 11:01
A handy script to open the xcode workspace/project file easily.
#!/usr/bin/env bash
# set -x
#
# Source: https://gist.github.com/xingheng/f7bc8d7d89a68a8f6ae42851b5aa0d0e
# Author: Will Han
#
target_dir=${1:-$(pwd)}
test ! -d ${target_dir} && { echo "Invalid target directory for searching!"; exit 1; }
@xingheng
xingheng / UIView+EdgeBorder.h
Last active July 12, 2023 16:43
Add edge borders to UIView with autolayout, inspired from https://stackoverflow.com/a/23157272/1677041
//
// 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 10:15
[Objective-C] A category for UIControl to bind action block easily.
//
// UIControl+BlockAction.h
// Pods
//
// Created by WeiHan on 5/26/17.
//
//
#import <UIKit/UIKit.h>

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@xingheng
xingheng / UIViewControllerAttemptRotationToDeviceOrientationWorkaround.m
Last active November 17, 2016 04:06 — forked from felix-schwarz/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…
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 November 4, 2015 09:22 — forked from JeOam/Compatible.md
Compatible with iOS 6 and iOS 7: Layout

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 August 29, 2015 14:25 — forked from noamtm/build-dist.sh
iOS: Re-sign an app for distribution
# 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 August 29, 2015 14:25 — forked from wmerrifield/build+archive.sh
A shell script to perform the equivalent of Xcode's "Build & Archive" command.
#!/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: