Skip to content

Instantly share code, notes, and snippets.

@vickeryj
vickeryj / role_based_authorization.rb
Created March 6, 2018 20:30
role based field authorization
GraphQL::Field.accepts_definitions(
required_role: GraphQL::Define.assign_metadata_key(:required_role),
unauthorized_value: GraphQL::Define.assign_metadata_key(:unauthorized_value)
)
class RoleBasedAuthorization
def instrument(_type, field)
if field.metadata[:required_role]
old_resolve_proc = field.resolve_proc
new_resolve_proc = ->(obj, args, ctx) do
#!/bin/sh
#
# Check for ruby style errors
# https://gist.github.com/johnnyji/d1226c9467a51f7d8b39
# Put this in .git/hooks/pre-commit
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
NC='\033[0m'
@vickeryj
vickeryj / FullscreenPhotoViewController.swift
Created September 8, 2016 20:03
Zoom into and page through an array of images
import UIKit
class FullscreenPhotoViewController: UIViewController, UIScrollViewDelegate {
// MARK: - IBOutlets
@IBOutlet weak var scrollView: UIScrollView!
// MARK: - IBActions
@vickeryj
vickeryj / reset_simulator.script
Created March 11, 2014 18:01
Script to reset iOS simulator
tell application "iPhone Simulator"
activate
end tell
tell application "System Events"
tell process "iPhone Simulator"
tell menu bar 1
tell menu bar item "iOs Simulator"
tell menu "iOs Simulator"
click menu item "Reset Content and Settings…"
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_background.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackOpaque];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Helvetica-Bold" size:14], UITextAttributeFont, [UIColor colorWithWhite:0.25 alpha:1.0], UITextAttributeTextColor, [UIColor colorWithWhite:0.75 alpha:1.0], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, nil]];
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:5.f forBarMetrics:UIBarMetricsDefault];
@vickeryj
vickeryj / gist:3623319
Created September 4, 2012 16:44
contact search
- (NSArray *)searchForContacts:(NSString *)searchString {
NSArray *searchWords = [searchString componentsSeparatedByString:@" "];
NSMutableString *query = [NSMutableString stringWithString:selectColumnsClause];
[query appendString:@"WHERE "];
BOOL isFirst = YES;
NSMutableArray *arguments = [NSMutableArray array];
for (NSString *word in searchWords) {
if ([word length] > 0) {
NSString *searchWord = [word lowercaseString];
[self.currentOrder loadForm];
[self.currentOrder loadFieldControllers];
#import <Foundation/Foundation.h>
#import "NSObject+PropertySupport.h"
@interface PropertyCoder : NSObject <NSCoding> {
}
@end
- (void)testDateAdditions {
int daysAgoReversed = [[NSDate dateAtMidnightWithDaysAgo:900] numDaysAgo];
STAssertTrue(daysAgoReversed == 900, @"date methods should be reversible, but 900 != %d", daysAgoReversed);
NSDate *tomorrow = [[NSDate date] dateByAddingDays:1];
int tomorrowDaysAgo = [tomorrow numDaysAgo];
STAssertTrue(tomorrowDaysAgo == -1, @"tomorrow should be negative one day ago, but it was %d, "
"and we think tomorrow is %f seconds from 1970", tomorrowDaysAgo, [tomorrow timeIntervalSince1970]);
NSDate *yesterday = [[NSDate date] dateByAddingDays:-1];
@implementation NSDate (PKDateUtils)
+ (NSDate *)dateAtMidnightWithDaysAgo:(int)numDaysAgo
{
NSDate *today = [NSDate date];
NSCalendar *gregorianCal = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDateComponents *todayComponents = [gregorianCal components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:today];
todayComponents.day -= numDaysAgo;
todayComponents.hour = 0;
todayComponents.minute = 0;