Skip to content

Instantly share code, notes, and snippets.

@timgcarlson
timgcarlson / gist:11407446
Last active August 29, 2015 14:00
HTML to prevent pinch-to-zoom on touch screen devices.
<meta name="viewport" content="width=1000px; user-scalable=0;" />
@timgcarlson
timgcarlson / Get specific view of a UIBarButtonItem from a UINavigationController
Created January 14, 2015 19:21
Get the view of the bar button item with respect to the right most item on the navigation bar. Useful for when you want to the frame of a UIBarButtonItem on a UINavigationBar
/** Get the view of the bar button item with respect to the right most item.
@param viewsFromRight The index of the button on the navigation controller from the right side. Pass 0 if the right most view is desired.
@param navController The UINavigationController where the bar button item exists.
@returns A UIView of the item on the navigation bar provided, x number of views from the right side (where x is the viewsFromRight property.
*/
- (UIView *)barItemViewFromRight:(NSUInteger)viewsFromRight ofNavController:(UINavigationController *)navController {
UINavigationBar *navBar = navController.navigationBar;
UIView *rightView = nil;
UIView *desiredView = nil; // The right-most view to hold and eventually return
@timgcarlson
timgcarlson / drawText:inFrame:withFont:textColor:alignment:verticalAlignment
Created March 13, 2015 17:12
Method to draw text to the current Core Graphics context (missing vertical alignment ability)
- (void)drawText:(NSString *)textToDraw inFrame:(CGRect)frameRect withFont:(UIFont *)originalFont textColor:(UIColor *)textColor alignment:(PDFTextAlignment)alignment verticalAlignment:(PDFTextVerticalAlignment)verticalAlignment {
if (!textToDraw) {
// If nil, give it an empty value to draw
textToDraw = @"";
}
// Prepare font
CTFontRef font = [self ctFontRefFromUIFont:originalFont];
@timgcarlson
timgcarlson / ShapeCutout.swift
Last active June 10, 2021 22:04
Using the non-zero winding rule to cutout the path of a shape (uses bezierPathByReversingPath)
UIGraphicsBeginImageContextWithOptions(CGSize(width: 200, height: 200), false, 0.0)
let context = UIGraphicsGetCurrentContext()
let rectPath = UIBezierPath(roundedRect: CGRectMake(0, 0, 200, 200), cornerRadius: 10)
var cutoutPath = UIBezierPath(roundedRect: CGRectMake(30, 30, 140, 140), cornerRadius: 10)
rectPath.appendPath(cutoutPath.bezierPathByReversingPath())
UIColor.orangeColor().set()
outerForegroundPath.fill()
@timgcarlson
timgcarlson / javascript.json
Last active July 5, 2018 18:45
Visual Studio Code - Snippets for Javascript (Babel), React, Redux, React Router, JSX - (This file is always being updated)
/** TODO:
* - Add shortcut acronyms to each prefix
* - Remove empty div and return placeholders from component snippets
* - Add prop-types to all new file components
*/
{
// Component snippets
"New Class Component": {
"prefix": "new class component",
"body": [
@timgcarlson
timgcarlson / postDailyOOOEventsToSlack.js
Last active July 25, 2024 23:09
Google Apps Script: Post Daily OOO Events to Slack
function postDailyOOOEventsToSlack() {
// The alphanumeric portion of your Google calendar ID
const calendarId = '';
const fullCalendarId = `${calendarId}@group.calendar.google.com`;
// The link to your Slack app with an Incoming Webhook
const slackWebhookUrl = '';
// Update this URL with your expected timezone
const calendarUrl = `https://calendar.google.com/calendar/embed?src=${calendarId}%40group.calendar.google.com&ctz=America%2FLos_Angeles/event`;
const today = new Date();