Skip to content

Instantly share code, notes, and snippets.

@leilee
leilee / UIColor+HexString.m
Created December 19, 2018 15:18
UIColor+HexString
@implementation UIColor (UPHex)
+ (instancetype)up_colorWithHexString:(NSString *)hexString {
NSString *colorString = PrepareHexString(hexString);
CGFloat r, g, b, a;
switch (colorString.length) {
case 3: // #RGB
a = 1.0;
var children2ProjectXML = (projects) => {
return projects.map(p => {
return "<project path=\"" + p.relative_path + "\" name=\"" + p.relative_path + "\" groups=\"" + p.relative_path.split("/")[1] + "\" />"
})
}
@leilee
leilee / Makefile
Created November 21, 2018 10:25
SPM Helper
init:
swift package init
init_exe:
swift package init --type executable
gen_xcode:
swift package generate-xcodeproj
build:
@leilee
leilee / Watchdog.h
Created November 12, 2018 16:27
Watchdog
@interface SCWatchdog : NSObject
- (instancetype)initWithThreashold:(NSTimeInterval)threshold;
@end
//override this in a UIView Custom Class
// check if any sub element inside view is outside bounds of the view
// if yes, expand the hitable area of view with its sub element
// http://stackoverflow.com/questions/11770743/capturing-touches-on-a-subview-outside-the-frame-of-its-superview-using-hittest
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (!self.clipsToBounds && !self.hidden && self.alpha > 0) {
for (UIView *subview in self.subviews.reverseObjectEnumerator) {
CGPoint subPoint = [subview convertPoint:point fromView:self];
@leilee
leilee / bluetooth_battery.sh
Created May 2, 2018 03:40
echo bluetooth device battery
ioreg -r -k "BatteryPercent" | awk -F " = " '/"Product" = / {print $2":"} /"BatteryPercent" = / {print $2"%"}' | sed 'N;s/\n/ /;' | sed -e 's/"//g'
@leilee
leilee / StringWithFormat.m
Created April 26, 2018 12:29
NSString StringWithFormat using asprintf
#define STRING_WITH_FORMAT(format, ...) \
({ \
char *buffer; \
asprintf(&buffer, format, ##__VA_ARGS__); \
NSString* result = [NSString stringWithUTF8String:buffer]; \
free(buffer); \
result; \
})
@leilee
leilee / plistGitDiff
Created February 3, 2018 03:18 — forked from scottrigby/plistGitDiff
Shows git diff of tracked plist files
#!/bin/bash
## @file
## Shows git diff of tracked plist files.
##
## Normally, Mac plist files are binary, so git diffs do not display. However,
## there are cases where seeing diffs is important. For example, when tracking
## changes via Mackup's git storage option.
##
## @see http://confusatory.org/post/133141617492/git-diff-for-binary-apple-property-list-files
@leilee
leilee / cl-fmt.sh
Created December 13, 2017 07:52
clang-format files recursively
#!/bin/bash
# Variable that will hold the name of the clang-format command
FMT=""
# Some distros just call it clang-format. Others (e.g. Ubuntu) are insistent
# that the version number be part of the command. We prefer clang-format if
# that's present, otherwise we work backwards from highest version to lowest
# version.
for clangfmt in clang-format{,-{4,3}.{9,8,7,6,5,4,3,2,1,0}}; do