Skip to content

Instantly share code, notes, and snippets.

View davidyeiser's full-sized avatar

David Yeiser davidyeiser

View GitHub Profile
@davidyeiser
davidyeiser / oo-css-good.css
Last active December 16, 2015 15:19
Object Oriented CSS good example
.subhead {
padding: 20px 0 10px 0;
font-family: Georgia, serif;
font-style: italic;
}
.subhead-major {
letter-spacing: 1px;
text-transform: uppercase;
color: #00f;
@davidyeiser
davidyeiser / oo-html-bad.html
Created April 25, 2013 13:07
HTML example matching oo-css-bad.css
<h3 class="subhead">
<h4 class="minor-subhead">
@davidyeiser
davidyeiser / oo-html-good.html
Created April 25, 2013 13:08
HTML example matching oo-css-good.css
<h3 class="subhead-major subhead">
<h4 class="subhead-minor subhead">
@davidyeiser
davidyeiser / ViewController.m
Last active December 23, 2015 18:39
Scroll view setup with basic view controller
- (void)viewDidLoad
{
[super viewDidLoad];
// Get screen size (e.g. iPhone 4 or 5)
CGRect screenSize = [[UIScreen mainScreen] bounds];
// Sets dimensions for the root view and scroll view
[self.view setFrame:CGRectMake(0.0, 0.0, screenSize.size.width, screenSize.size.height)];
[scrollView setFrame:CGRectMake(0.0, 0.0, screenSize.size.width, screenSize.size.height)];
@davidyeiser
davidyeiser / displayCurrentDate.m
Last active December 24, 2015 12:09
The code I use to display a date label in my weather app.
- (void)displayCurrentDate
{
// This grabs the current date and initializes it to
// the variable "now"
NSDate *now = [[NSDate alloc] init];
// This initializes the class that turns NSDate objects
// into readable text strings
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
@davidyeiser
davidyeiser / WeatherAlertsCount.m
Last active December 26, 2015 14:19
My quick and easy way to distinguish singular from plural when it comes to weather alerts.
// "alerts" is the array that contains the weather alerts
int weatherAlertsCount = alerts.count;
NSString *weatherAlertLabelMain = @"";
NSString *weatherAlertLabelMinor = @"";
if (weatherAlertsCount > 1) {
weatherAlertLabelMain = [NSString stringWithFormat:@"%d Weather Alerts", weatherAlertsCount];
}
else {
@davidyeiser
davidyeiser / temperature.m
Last active December 27, 2015 13:09
Sample code of grabbing temperature value and then either leaving as-is or converting to °C.
// Round temperature values to whole integers
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setMaximumFractionDigits:0];
[numberFormatter setRoundingMode: NSNumberFormatterRoundUp];
// Get the current temp from Current Forecast JSON
// Default is °F, convert to °C if User Settings is set to Celcius (0)
if (unitTemp == 1) {
currentTemp = [numberFormatter stringFromNumber:[currently valueForKeyPath:@"temperature"]];
}
@davidyeiser
davidyeiser / UserSettings.m
Created November 6, 2013 05:55
Sample user settings retrieval.
// Grab User Settings for units
unitTemp = [[NSUserDefaults standardUserDefaults] integerForKey:@"EverydayWeatherUnitTempPrefKey"];
@davidyeiser
davidyeiser / AppDelegate.m
Created November 10, 2013 04:37
Registering NSUserDefaults
NSString * const EverydayWeatherUnitTempPrefKey = @"EverydayWeatherUnitTempPrefKey";
NSString * const EverydayWeatherOptShowHelperTaps = @"EverydayWeatherOptShowHelperTaps";
@implementation EverydayWeatherAppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Registers applications default settings
NSArray *dictObjects = [NSArray arrayWithObjects:[NSNumber numberWithInt:1], [NSNumber numberWithBool:YES], nil];
@davidyeiser
davidyeiser / typesetting.sass
Created January 12, 2016 18:37
Typesetting with Sass
@function pem($target, $context: $em_base)
@return #{$target / $context}em
@function prem($target, $context: $em_base)
@return #{$target / $context}rem
@mixin setFont($face: "regular", $size: 0, $line-height: 0)
$family: "Helvetica Neue", Arial, sans-serif
$style: normal
$weight: normal