Skip to content

Instantly share code, notes, and snippets.

View tomisacat's full-sized avatar
🤯

tomisacat tomisacat

🤯
  • Shanghai, China
View GitHub Profile
NSString *pattern = @"([\\.\\+\\(\\)\\-\\_\\s])";
NSRegularExpression *re = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:nil];
NSString *replaced = [re stringByReplacingMatchesInString:phoneNumber options:0 range:NSMakeRange(0, [phoneNumber length]) withTemplate:@""];
NSLog(@"%@", replaced);
@tomisacat
tomisacat / clearEllipseInRect.m
Created December 4, 2014 07:55
clear a circle/ellipse area like CGContextClearRect to clear a rect area
- (void)drawRect:(CGRect)rect
{
CGContextRef con = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(con, [UIColor grayColor].CGColor);
CGContextFillRect(con, rect);
CGContextAddEllipseInRect(con, self.circle); // self.circle is a property of CGRect
CGContextClip(con);
CGContextClearRect(con, self.circle);
}
@tomisacat
tomisacat / customize_segmentcontrol.m
Created December 9, 2014 12:42
customize segment control ui style
NSDictionary *normalSettings = @{UITextAttributeTextColor: [UIColor grayColor], UITextAttributeFont: [UIFont systemFontOfSize:13]};
[self.segmentControl setTitleTextAttributes:normalSettings forState:UIControlStateNormal];
NSDictionary *highlightedSettings = @{UITextAttributeTextColor: [UIColor red:43 green:206 blue:119 alpha:1.0], UITextAttributeFont: [UIFont systemFontOfSize:16]};
[self.segmentControl setTitleTextAttributes:highlightedSettings forState:UIControlStateSelected];
@tomisacat
tomisacat / FRP iOS Learning resources.md
Created February 15, 2016 02:47 — forked from JaviLorbada/FRP iOS Learning resources.md
The best FRP iOS resources.

Videos

mach_absolute_time() CACurrentMediaTime() CFAbsoluteTimeGetCurrent()

@tomisacat
tomisacat / convert_mp3_to_m4a.rb
Created November 23, 2016 10:30
Convert mp3 to m4a with AAC codec and 128kb/s bitrate.
#!/usr/bin/env ruby
if ARGV.length < 1
puts "Please input file name."
exit
end
mp3_name = ARGV[0] + ""
m4a_name = mp3_name.split(".")[0] + ".m4a"
puts "******************************************"
@tomisacat
tomisacat / bump_build_number_per_build.sh
Created November 23, 2016 10:48
Bump build number of Xcode project automatically
#!/bin/sh
# bump_build_number_per_build.sh
# @desc Automaticvally create build number depend on current time.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
@tomisacat
tomisacat / .gitconfig
Created December 6, 2016 12:47 — forked from pksunkara/config
Sample of git config file (Example .gitconfig)
[user]
name = Pavan Kumar Sunkara
email = pavan.sss1991@gmail.com
[core]
editor = vim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore
[sendemail]
smtpencryption = tls
smtpserver = smtp.gmail.com
@tomisacat
tomisacat / notify-tm-backup
Created February 10, 2017 08:37 — forked from hazcod/notify-tm-backup
Show a notification when Time Machine backup completes
# Raw command
BACKUP=$(tmutil latestbackup) ; if [ "$(cat ~/.lastbackup 2>/dev/null)" != "$BACKUP" ]; then echo $BACKUP > ~/.lastbackup ; osascript -e "display notification \"$(echo $BACKUP | xargs basename)\" with title \"Backup finished\""; fi
# As cron entry
*/5 * * * * BACKUP=$(tmutil latestbackup 2>/dev/null) ; if [ "$(cat ~/.lastbackup 2>/dev/null)" != "$BACKUP" ]; then echo $BACKUP > ~/.lastbackup ; osascript -e "display notification \"$(echo $BACKUP | xargs basename)\" with title \"Backup finished\""; fi 2>&1 >/dev/null
@tomisacat
tomisacat / filter_digits.swift
Last active April 6, 2017 14:39
simple illustration of `flatMap` and `reduce` to filter digits from string
let s = "fdsf6fdsf7dsf7s7sdf789sdff9s8fs8df98dfsdsd5fsf"
let r = s.characters.flatMap { Int(String($0)) != nil ? nil : $0 }.reduce("") { $0 + String($1) }
Swift.print(r)