Skip to content

Instantly share code, notes, and snippets.

View AlexHedley's full-sized avatar
💭
⚀⚁⚂⚃⚄⚅

Alex Hedley AlexHedley

💭
⚀⚁⚂⚃⚄⚅
View GitHub Profile
//Parsing a date in the following format '//2014-07-13T20:35:47.000Z'
//Use the DateFormat of @"yyyy-MM-dd'T'HH:mm:ss.zzz'Z'"
- (NSString *)formattedDate {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.zzz'Z'"]; //2014-07-13T20:35:47.000Z
NSDate *tempDate = [dateFormatter dateFromString:self.date];
[dateFormatter setDateFormat:@"EE MMM, dd"];
return [dateFormatter stringFromDate:tempDate];
}
@AlexHedley
AlexHedley / gist:5bc12ef4902bf1ce8fb7
Created October 1, 2014 22:05
Formatted Time from Seconds to Hours/Minutes/Seconds
- (NSString *)formattedTime {
int seconds = [self.duration intValue] % 60;
int minutes = [self.duration intValue] / 60;
int hours = [self.duration intValue] / 3600;
return [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds];
}
//Better solution
- (NSString *)timeFormatted:(int)totalSeconds{
@AlexHedley
AlexHedley / gist:80552a75bfdf071f58cb
Created October 1, 2014 22:54
First Element of Dictionary
URL: http://gdata.youtube.com/feeds/api/users/unpluggedacoustic1/uploads/?alt=json
JSON:
"media$group":{
"media$thumbnail": [
{ "url":"http://i.ytimg.com/vi/OKJk4QVyUTw/0.jpg","height":360,"width":480,"time":"00:01:39.500" },
{ "url":"http://i.ytimg.com/vi/OKJk4QVyUTw/1.jpg","height":90,"width":120,"time":"00:00:49.750" },
{ "url":"http://i.ytimg.com/vi/OKJk4QVyUTw/2.jpg","height":90,"width":120,"time":"00:01:39.500" },
{ "url":"http://i.ytimg.com/vi/OKJk4QVyUTw/3.jpg","height":90,"width":120,"time":"00:02:29.250" }
]
@AlexHedley
AlexHedley / gist:d326c1efbd1830d33a48
Created October 14, 2014 09:30
MFMailComposeViewController
//http://www.appcoda.com/ios-programming-101-send-email-iphone-app/
- (IBAction)sendEmail:(id)sender {
// Email Subject
NSString *emailTitle = @"iOS Email";
// Email Content
NSString *messageBody = @"Sent from iOS App";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:@"unpluggedne@gmail.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
@AlexHedley
AlexHedley / application:handleOpenURL.m
Last active August 29, 2015 14:13
Custom URL Scheme
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(@"url recieved: %@", url);
NSLog(@"query string: %@", [url query]);
NSLog(@"host: %@", [url host]);
NSLog(@"url path: %@", [url path]);
NSDictionary *dict = [self parseQueryString:[url query]];
NSLog(@"query dict: %@", dict);
return YES;
}
@AlexHedley
AlexHedley / NSUserDefaults.m
Last active August 29, 2015 14:13
NSUserDefaults with own plist
NSString *defaultPrefsFile = [[NSBundle mainBundle] pathForResource:@"defaultPrefs" ofType:@"plist"];
NSDictionary *defaultPrefs = [NSDictionary dictionaryWithContentsOfFile:defaultPrefsFile];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultPrefs];
//Get
NSString *strBaseURL = [[NSUserDefaults standardUserDefaults] stringForKey:@"BaseURL"];
//Set
[[NSUserDefaults standardUserDefaults] setObject:baseURL forKey:@"BaseURL"];
@AlexHedley
AlexHedley / activity.java
Created January 23, 2015 15:14
Android WebView
Button button = (Button) findViewById(R.id.button);
Toolbar toolbar = (Toolbar) findViewById(R.id.myToolbar);
final WebView webView = (WebView) findViewById(R.id.webView);
//Set links to show in webview not open in another program.
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
String url = "http://www.alexhedley.com/form.asp";
webView.loadUrl(url);
@AlexHedley
AlexHedley / MainActivity.java
Created January 28, 2015 10:32
Integrate Zxing into Android Studio
// import the various classes
// Add the controls to your View
Button button;
TextView tvScanResults;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_barcode);
@AlexHedley
AlexHedley / manifest.xml
Last active August 29, 2015 14:14
Stop Reload of Page when Orientation changes
<activity
android:name=".YourActivityName"
android:configChanges="orientation|screenSize" >
</activity>
//http://stackoverflow.com/questions/5913130/dont-reload-application-when-orientation-changes
@AlexHedley
AlexHedley / Activity.java
Created January 28, 2015 14:28
Dismiss Keyboard
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(EDITTEXT.getWindowToken(), 0);
//http://stackoverflow.com/questions/3553779/android-dismiss-keyboard