Skip to content

Instantly share code, notes, and snippets.

View davidyeiser's full-sized avatar

David Yeiser davidyeiser

View GitHub Profile
@davidyeiser
davidyeiser / Post.js
Created April 2, 2018 13:02
Example Post component for React
import Link from 'next/link'
import dateFormat from 'dateformat'
import Markdown from 'react-markdown'
class Post extends React.Component {
render() {
const {
title,
content,
publish_date,
componentDidMount() {
const cachedAirtableNotes = localStorage.getItem('_cachedAirtableNotes')
if (cachedAirtableNotes) {
// Local data exists, now let's see if it has "expired"
// parse data
const parsedAirtableNotes = JSON.parse(cachedAirtableNotes)
// Check current time against timestamp
//
// Media Queries
// —·—·—·—·—·—·—·—·—·—·—·—
// NOTE: a 93.75% reduction in full resolution width was
// made for the desktop breakpoints to accommodate
// browser chrome and small vertical spaces in
// approximating a full-screen browser on that
// specific resolution.
@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
@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 / UserSettings.m
Created November 6, 2013 05:55
Sample user settings retrieval.
// Grab User Settings for units
unitTemp = [[NSUserDefaults standardUserDefaults] integerForKey:@"EverydayWeatherUnitTempPrefKey"];
@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 / 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 / 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 / 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)];