Skip to content

Instantly share code, notes, and snippets.

View kim4apple's full-sized avatar

kim4apple kim4apple

  • Shenzhen, China
View GitHub Profile
// this code will cause a UIView to shake--good for "login error"
CAKeyframeAnimation * anim = [ CAKeyframeAnimation animationWithKeyPath:@"transform" ] ;
anim.values = [ NSArray arrayWithObjects:
[ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(-5.0f, 0.0f, 0.0f) ],
[ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(5.0f, 0.0f, 0.0f) ],
nil ] ;
anim.autoreverses = YES ;
anim.repeatCount = 2.0f ;
anim.duration = 0.07f ;
git=/usr/local/git/bin/git
touch Info.plist
version=`$git describe --dirty`
version=`echo $version | sed 's/[a-zA-Z]*//'`
versionNum=`echo $version | sed 's/\-[0-9]*\-[a-zA-Z0-9]*//'`
echo "#define GIT_VERSION $version" > InfoPlist.h
echo "#define APP_VERSION $versionNum" >> InfoPlist.h
@kim4apple
kim4apple / README.md
Last active August 29, 2015 14:06 — forked from oodavid/README.md

Deploy your site with git

This gist assumes:

  • you have a local git repo
  • with an online remote repository (github / bitbucket etc)
  • and a cloud server (Rackspace cloud / Amazon EC2 etc)
    • your (PHP) scripts are served from /var/www/html/
    • your webpages are executed by apache
  • apache's home directory is /var/www/
@kim4apple
kim4apple / NSData+UTF8.m
Last active May 16, 2018 06:20
ignore the invalid utf-8
- (NSData *)cleanUTF8:(NSData *)data {
// this function is from
// https://stackoverflow.com/questions/3485190/nsstring-initwithdata-returns-null
//
//
iconv_t cd = iconv_open("UTF-8", "UTF-8"); // convert to UTF-8 from UTF-8
int one = 1;
iconvctl(cd, ICONV_SET_DISCARD_ILSEQ, &one); // discard invalid characters
size_t inbytesleft, outbytesleft;
inbytesleft = outbytesleft = data.length;
@kim4apple
kim4apple / getargv.c
Created February 18, 2019 09:59 — forked from nonowarn/getargv.c
/* Copied, Pasted and summarized from ps' source code.
You can use sysctl to get other process' argv.
*/
#include <sys/sysctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define pid_of(pproc) pproc->kp_proc.p_pid
@kim4apple
kim4apple / CommandUtil.m
Created February 19, 2019 01:58
Get command with pid
- (NSString *)_commandFromPid:(int)pid {
int mib[3], argmax, nargs, c = 0;
size_t size;
char *procargs, *sp, *np, *cp;
mib[0] = CTL_KERN;
mib[1] = KERN_ARGMAX;
size = sizeof(argmax);
@kim4apple
kim4apple / CommandUtil.m
Created February 19, 2019 01:58
Get command with pid, modify from ps.
- (NSString *)_commandFromPid:(int)pid {
int mib[3], argmax, nargs, c = 0;
size_t size;
char *procargs, *sp, *np, *cp;
mib[0] = CTL_KERN;
mib[1] = KERN_ARGMAX;
size = sizeof(argmax);
@kim4apple
kim4apple / ProcessUtil.m
Created February 19, 2019 02:07
Get process path with pid using libproc.
#import <libproc.h>
#import <sys/proc_info.h>
@interface ProcessUtil : NSObject
+ (NSArray <NSNumber *> *)loadProcessIds;
+ (NSString *)pathWithPid:(int)pid;
@end
@kim4apple
kim4apple / gist:99ddb8d5cdba1716bd1909a7afd277fe
Created April 21, 2019 10:06 — forked from rtrouton/gist:4ff699b3f7660ae06a13
Software Update keys in Yosemite's /Library/Preferences/com.apple.SoftwareUpdate.plist
Automatically check for updates:
Enable: sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticCheckEnabled -bool TRUE
Disable: sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticCheckEnabled -bool FALSE
Download newly available updates in the background:
Enable: sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticDownload -bool TRUE
Disable: sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate AutomaticDownload -bool FALSE
# Even though device management is disabled in Server.app,
# the processes still run. Which the only issue with this is
# it causes extremely slow shutdown times. So here we disable this shit
sudo launchctl stop com.apple.DeviceManagement.postgres;
sudo launchctl remove com.apple.DeviceManagement.postgres;
sudo launchctl unload -w /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.apple.DeviceManagement.postgres.plist
# Same goes for calendar server
sudo launchctl stop org.calendarserver.agent;