Skip to content

Instantly share code, notes, and snippets.

@centwave
centwave / shared-property.m
Created July 24, 2013 04:09
Shared Property with All Instance
- (NSDateFormatter *)formatter {
static NSDateFormatter *formatter;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_formatter = [[NSDateFormatter alloc] init];
_formatter.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy"; // twitter date format
});
return formatter;
}
@centwave
centwave / image-colored.m
Created July 17, 2013 17:00
Image With Color burn
// begin a new image context, to draw our colored image onto
UIGraphicsBeginImageContext(img.size);
// get a reference to that context we created
CGContextRef context = UIGraphicsGetCurrentContext();
// set the fill color
[color setFill];
@centwave
centwave / cheatsheet-raw
Created July 12, 2013 05:16
Cheat sheet for markdown
# Header 1 #
## Header 2 ##
### Header 3 ### (Hashes on right are optional)
#### Header 4 ####
##### Header 5 #####
## Markdown plus h2 with a custom ID ## {#id-goes-here}
[Link back to H2](#id-goes-here)
This is a paragraph, which is text surrounded by whitespace. Paragraphs can be on one
@centwave
centwave / playsound
Created July 6, 2013 13:53
play a sound for ios
@interface MyClass:NSObject
{
SystemSoundID mySound;
}
@implementation MyClass
- (void) viewDidLoad {
[super viewDidLoad];
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"changeTrack" ofType:@"aif"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &mySound);
@centwave
centwave / UIlabel-text-top
Created June 26, 2013 10:14
Make UILabel text always stay on top of the frame
CGSize textSize = [label.text sizeWithFont:label.font
constrainedToSize:CGSizeMake(label.frame.size.width, MAXFLOAT)
lineBreakMode:label.lineBreakMode];
label.frame = (CGRect){.origin=label.origin,.size={ceilf(textSize.width), ceilf(textSize.height)}}};
@centwave
centwave / iOS-Requirement
Created June 23, 2013 12:48
The minium requirement of iOS version in order to run a code
#if __IPHONE_OS_VERSION_MIN_REQUIRED <= __IPHONE_6_1
//code here
#endif
@centwave
centwave / Django app
Created June 16, 2013 00:09
Nginx configuration for Django
server {
listen 80;
server_name server_name;
access_log /var/log/app/access.log;
error_log /var/log/app/error.log;
# https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-$
location /static { # STATIC_URL
alias /path/to/app/static; # STATIC_R$
@centwave
centwave / Nodejs app
Created June 15, 2013 23:56
Nginx configuration for nodejs app
# the IP(s) on which your node server is running. I chose port 3000.
upstream app_server {
server 127.0.0.1:3000;
keepalive 64;
}
# the nginx server instance
server {
listen 80;
server_name #{servername};
@centwave
centwave / navbar-bar-button
Created June 11, 2013 15:45
Navigation bar button item
/* create a bar button item */
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"button" style:UIBarButtonItemStylePlain target:self action:@selector(barButtonDidTap:)];
self.navigationItem.rightBarButtonItem = item;
/*
* call back when bar button did tap
*/
- (void)barButtonDidTap:(id)sender
{
//do something