Skip to content

Instantly share code, notes, and snippets.

@Sunnyztj
Sunnyztj / gist:57952770ff7413e5a603
Last active August 29, 2015 14:07
gem 'ckeditor' + gem 'paperclip'
rails generate ckeditor:install --orm=active_record --backend=paperclip
升级OSX的同学 运行这个代码就能修好postgresql
mkdir /usr/local/var/postgres/pg_tblspc
mkdir /usr/local/var/postgres/pg_twophase
mkdir /usr/local/var/postgres/pg_stat_tmp
@Sunnyztj
Sunnyztj / gist:960b6c7c30bbbf33258a
Created October 24, 2014 05:34
NSDateFormatter string to nsdate
NSDateFormatter *startDateFormatter = [[NSDateFormatter alloc] init];
[startDateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[startDateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
NSDate *dateT = [startDateFormatter dateFromString:dateString];
@Sunnyztj
Sunnyztj / gist:150ca7ef098a9c8024e1
Created October 28, 2014 00:46
adding an existing product to githug
https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
@Sunnyztj
Sunnyztj / gist:8b23cd588add18fe00aa
Last active August 29, 2015 14:08
IOS config file
#define TimeZone [[NSTimeZone localTimeZone] name]
#define IS_IPHONE_6_PLUS ([[UIScreen mainScreen] respondsToSelector:@selector(nativeScale)] && [UIScreen mainScreen].nativeScale > 2.1)
#define IS_IPHONE_4 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)480) < DBL_EPSILON)
#define IS_IPHONE_5 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)568) < DBL_EPSILON)
#define IS_IPHONE_6 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)667) < DBL_EPSILON)
#define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)
#define IS_OS_5_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0)
#define IS_OS_6_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
@Sunnyztj
Sunnyztj / gist:bffc6a05da37fba2b457
Last active August 29, 2015 14:08
TextView or TextField animation
#pragma mark - UITextViewDelegate
- (void)textViewDidBeginEditing:(UITextView *)textView {
self.isTextViewEdit = YES;
_currentTextView = textView;
CGFloat distance;
distance = (self.firstURLDescriptionTextView == textView ? 70 : 180);
if (IS_IPHONE_6_PLUS) {
distance += 35.0;
The main reason you use the default queue over the main queue is to run tasks in the background.
For instance, if I am downloading a file from the internet and I want to update the user on the progress of the download, I will run the download in the priority default queue and update the UI in the main queue asynchronously.
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
//Background Thread
dispatch_async(dispatch_get_main_queue(), ^(void){
//Run UI Updates
});
});
@Sunnyztj
Sunnyztj / gist:683b3da3d0e17b9664dc
Created October 30, 2014 02:44
add tap to label and toggle url event
- (void)addTagGestureRecognizerToURLLabel {
// first image tag gesture recognizer setup
UITapGestureRecognizer *firstURLSingleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(url1TapEvent)];
firstURLSingleTap.numberOfTapsRequired = 1;
self.link1Url.userInteractionEnabled = YES;
[self.link1Url addGestureRecognizer:firstURLSingleTap];
UITapGestureRecognizer *secondURLSingleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(url2TapEvent)];
secondURLSingleTap.numberOfTapsRequired = 1;
@Sunnyztj
Sunnyztj / gist:e29b560b010a5c472c5b
Created November 3, 2014 00:48
`echo "#{row[7]}" >> #{Rails.root.join('missing_flavours.txt').to_s}`
`echo "#{row[7]}" >> #{Rails.root.join('missing_flavours.txt').to_s}`
rake db:test:load