Skip to content

Instantly share code, notes, and snippets.

View donly's full-sized avatar
🎯
Focusing

Tung donly

🎯
Focusing
View GitHub Profile
@donly
donly / gist:1294543
Created October 18, 2011 03:28
代码风格示范
// 设置标题背景图
[functionButton setBackgroundImage:(i == 0 ? firestImageNormal : othersImageNormal)
forState:UIControlStateNormal];
[functionButton setBackgroundImage:(i == 0 ? firestImageHighlighted : othersImageHighlighted)
forState:UIControlStateHighlighted];
// 未完
#include<stdio.h>
#include<windows.h>
#include<malloc.h>
int main(void)
{
int c;
int i;
int j;
nihao:
@donly
donly / good.c
Created October 26, 2011 08:50 — forked from wwhhjj/gist:1315802
注意代码风格!
#include<stdio.h>
int main(void)
{
float a,r1,r2,m;
char b,c;
printf("请输入加油量,汽油类型(a,b,c)以及服务类型(f,m,e)\n");
printf("***************************************************\n");
printf("请输入:");
@donly
donly / gist:1367070
Created November 15, 2011 13:28 — forked from wwhhjj/gist:1366956
再次提醒注意代码书写风格!
#include <stdio.h>
int main (int argc, const char * argv[]) {
int a, b, i, t;
scanf("%d%d", &a, &b);
if (a < b) {
t = a;
- (IBAction)startOneOffTimer:sender {
[NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(targetMethod:)
userInfo:[self userInfo]
// declcare
@property (assign) NSTimer *repeatingTimer;
// implements
- (IBAction)startRepeatingTimer:sender {
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.5
// declare
@property (retain) NSTimer *unregisteredTimer;
// implements
- (IBAction)createUnregisteredTimer:sender {
NSMethodSignature *methodSignature = [self methodSignatureForSelector:@selector(invocationMethod:)];
CLLocationManager *manager = [[CLLocationManager alloc] init];
if (manager.locationServicesEnabled == NO) {
UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[servicesDisabledAlert show];
[servicesDisabledAlert release];
}
- (IBAction)openGPS:(id)sender {
if (locationManager == nil) {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest; // 越精确,越耗电!
}
[locationManager startUpdatingLocation]; // 开始定位
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
switch (error.code) {
case kCLErrorLocationUnknown:
NSLog(@"The location manager was unable to obtain a location value right now.");
break;
case kCLErrorDenied:
NSLog(@"Access to the location service was denied by the user.");
break;
case kCLErrorNetwork: