Skip to content

Instantly share code, notes, and snippets.

View lexrus's full-sized avatar
🏠
Working from home

Lex Tang lexrus

🏠
Working from home
View GitHub Profile
@lexrus
lexrus / cow.conf
Created December 2, 2013 15:34
/etc/supervisor/conf.d/cow.conf
[program:cow]
command=/usr/local/bin/cow -err=true -rc="/root/.cow/rc"
numprocs=1
directory=/root/.cow
autostart=true
autorestart=unexpected
startsecs=2
startretries=3
stdout_logfile=/var/log/cow.log
stdout_logfile_maxbytes=2MB
// Fixed iOS 7 backButtonBackground issue.
// http://stackoverflow.com/questions/18617522/back-button-is-not-visible-in-ios-7/18950658#18950658
if ([[UIDevice currentDevice].systemVersion compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) {
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"BackButtonIcon"]];
} else {
UIImage *backButtonBackground = [[UIImage imageNamed:@"BackButtonIcon"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 29, 0, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonBackground forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}
@lexrus
lexrus / uncrustify.cfg
Last active December 21, 2015 13:59
My ~/.uncrustify/uncrustify.cfg for https://github.com/benoitsan/BBUncrustifyPlugin-Xcode
#
# Uncrustify Configuration File
# File Created With UncrustifyX 0.4.3 (252)
#
# Alignment
# ---------
## Alignment
@lexrus
lexrus / vpn.sh
Last active December 21, 2015 02:49 — forked from alvinl/vpn.sh
#!/bin/bash
#apt-get update
apt-get install pptpd -y --force-yes
echo localip 192.168.240.1 >> /etc/pptpd.conf
echo remoteip 192.168.240.2-200 >> /etc/pptpd.conf
echo ms-dns 8.8.8.8 >> /etc/ppp/pptpd-options
echo ms-dns 8.8.4.4 >> /etc/ppp/pptpd-options
echo "lex pptpd lexrusontwitter *" | tee -a /etc/ppp/chap-secrets
/etc/init.d/pptpd restart
@lexrus
lexrus / url_qrcode.rb
Created August 5, 2013 08:21
A tiny Sinatra app turns URL to QRCode.
require 'sinatra'
require 'pngqr'
require 'slim'
require 'stylus'
require 'stylus/tilt'
set :site_name => 'QRCode.rb'
set :server => %w[thin]
set :port => 9494
#set :dump_errors => true
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>info.chenyufei.cow</string>
<key>ProgramArguments</key>
<array>
<string>/Users/Lex/Dropbox/bin/cow</string>
<string>-core=4</string>
@lexrus
lexrus / HD.txt
Last active July 20, 2023 08:11
All WWDC 2013 Session Videos URLs in https://developer.apple.com/wwdc/videos/ dumped with Chrome. You can download these videos **without** a Apple developer account by running the download.sh script. There is also a sample code downloader here: https://github.com/jfahrenkrug/WWDC-Downloader
http://devstreaming.apple.com/videos/wwdc/2013/710xfx3xn8197k4i9s2rvyb/710/710-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/202xdx2x47ezp1wein/202/202-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/200xdx2x35e1pxiinm/200/200-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/413xdx5x97itb5ek4yex3r7/413/413-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/612xax4xx65z1ervy5np1qb/612/612-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/221xex4xxohbllf4hblyngt/221/221-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/220xbx4xipaxfd1tggxuoib/220/220-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/711xcx4x8yuutk8sady6t9f/711/711-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/404xbx2xvp1eaaqonr8zokm/404/404-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/505xbx4xrgmhwby4oiwkrpp/505/505-HD.mov?dl=1
@lexrus
lexrus / gist:5734257
Last active January 6, 2016 08:54
Log all NSNotifications. #import <objc/runtime.h> absolutely! Original: https://coderwall.com/p/7mopeq
#if TARGET_IPHONE_SIMULATOR
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wimplicit"
// Log all notifications via tail -f /tmp/msgSends-*
instrumentObjcMessageSends(YES);
#pragma clang diagnostic pop
#endif
@lexrus
lexrus / gist:5617493
Created May 21, 2013 04:31
Initial Phonetic Letter
static NSString *phonetic(NSString *sourceString) {
NSMutableString *source = [sourceString mutableCopy];
CFStringTransform((__bridge CFMutableStringRef) source, NULL, kCFStringTransformMandarinLatin, NO);
return source;
}
static inline NSString *initialPhoneticLetter(NSString *string) {
return [[[[phonetic([string substringToIndex:1]) substringToIndex:1] uppercaseString]
stringByReplacingOccurrencesOfString:@"\u0100" withString:@"A"]
stringByReplacingOccurrencesOfString:@"\u00c9" withString:@"E"];
@lexrus
lexrus / gist:5574347
Created May 14, 2013 07:47
LTScrollView.m set contentSize that fit the contents of UIScrollView
#import "LTScrollView.h"
@implementation LTScrollView
- (void)layoutSubviews
{
CGFloat perfectContentWidth = 0.0f;
CGFloat perfectContentHeight = 0.0f;
BOOL isHorizontalScrollIndicatorVisible = self.showsHorizontalScrollIndicator;