Skip to content

Instantly share code, notes, and snippets.

View ShonFrazier's full-sized avatar
🟢
✍🏻

Shon Frazier ShonFrazier

🟢
✍🏻
View GitHub Profile
@ShonFrazier
ShonFrazier / wat.txt
Created August 25, 2015 18:33
homebrew GitHub API rate limit error ... why?
# Regenerated the API token, set it at the command line, added it to shell config scripts
shon@atlas ~> echo $HOMEBREW_GITHUB_API_TOKEN
fc...24
shon@atlas ~> brew search json-c
json-c
Error: GitHub API rate limit exceeded for 107.192.237.60. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)
Try again in 11 minutes 19 seconds, or create an personal access token:
https://github.com/settings/tokens
and then set the token as: HOMEBREW_GITHUB_API_TOKEN
// Playground - noun: a place where people can play
import Cocoa
let polyPath = NSBezierPath()
var sides = 8
var 𝛉 = 0.0
var 𝜋 = 3.14159
var 𝜋2 = 2*𝜋
@ShonFrazier
ShonFrazier / utf8utility.m
Created December 11, 2013 20:48
Some utility code for examining strings for UTF-8-ness
enum UTF8SequenceLength {
Bytes1 = 0,
Bytes2 = 0b11000000,
Bytes3 = 0b11100000,
Bytes4 = 0b11110000,
BytesErr = 0b10000000,
};
enum UTF8ParsingMode {
UTF8ParsingModeNone = 0,
typedef enum {
StyleCircle = 'circ',
StylePie = '3.14',
StylePolygon = 'poly',
} Style;
@ShonFrazier
ShonFrazier / tests.m
Created November 11, 2013 17:59
Awesome tests for your Cocoa projects
Class thisClass = [self class];
BOOL conforms = class_conformsToProtocol(thisClass, @protocol(NSObject));
XCTAssert(!conforms, @"*gasp*");
@ShonFrazier
ShonFrazier / string_parse.m
Created October 30, 2013 14:19
Problem with encoding detection?
char *cString = "CHS - 中设置了私人内容文件夹 您可以随时访问此文件夹。.pdf";
NSUInteger sLen = strlen(cString);
NSString *wrongString = [NSString stringWithFormat:@"%s", cString];
NSLog(@"%@", wrongString); // CHS - 中设置了私人内容文件夹 您可以随时访问此文件夹。.pdf
NSString *rightString = [[NSString alloc] initWithBytes:cString length:sLen encoding:NSUTF8StringEncoding];
NSLog(@"%@", rightString); // CHS - 中设置了私人内容文件夹 您可以随时访问此文件夹。.pdf
void dispatch_wait_while(dispatch_wait_condition_t condition_block, dispatch_time_t interval, dispatch_wait_completion_t completion_block) {
if ( !condition_block ) return;
if ( !interval ) return;
if ( !completion_block ) return;
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_current_queue());
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, interval, 0.25*NSEC_PER_SEC);
dispatch_source_set_event_handler(timer, ^{
if (!condition_block()) {
dispatch_source_cancel(timer);
@ShonFrazier
ShonFrazier / DailySoftwareUpdates.plist
Last active December 20, 2015 08:59
Automatically install updates on OS X every day
<!-- sudo DailySoftwareUpdate.plist /Library/LaunchDaemons/ -->
<!-- sudo launchctl load /Library/LaunchDaemons/DailySoftwareUpdate.plist -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>DailySoftwareUpdate</string>
@ShonFrazier
ShonFrazier / dispatch-timer.c
Last active December 20, 2015 03:18
dispatch timer
//
// dispatch-timer.c
//
// Created by Shon Frazier on 4/22/13.
// Copyright (c) 2013 Shon Frazier. All rights reserved.
//
#include <stdio.h>
#include <dispatch/dispatch.h>
, .
, / .
, / .- .
. .- .-
./ .-- ...
.-------- * .--
/ .......
, ..
........ ----
. --..