Skip to content

Instantly share code, notes, and snippets.

View jeffrafter's full-sized avatar
You are amazing

Jeff Rafter (he/him) jeffrafter

You are amazing
View GitHub Profile
@jeffrafter
jeffrafter / coin_flip.py
Created July 1, 2017 15:24
Flip a coin on Forest Quantum Virtual Machine
import pyquil.quil as pq
import pyquil.api as api
from pyquil.gates import *
coin_flip = pq.Program().inst(H(0)).measure(0, 0)
num_flips = 5
qvm = api.SyncConnection()
flips = qvm.run(coin_flip, [0], num_flips)
class HistoryPreviewItem: NSObject, QLPreviewItem {
var share: Share!
var source: NSRect!
init(_ share: Share, source: NSRect = NSRect.zero) {
super.init()
self.share = share
self.source = source
}
@jeffrafter
jeffrafter / cgimage.swift
Created February 9, 2017 00:34
Resizing CGImage in Swift 3
func resize(_ image: CGImage) -> CGImage? {
var ratio: Float = 0.0
let imageWidth = Float(image.width)
let imageHeight = Float(image.height)
let maxWidth: Float = 1024.0
let maxHeight: Float = 768.0
// Get ratio (landscape or portrait)
if (imageWidth > imageHeight) {
ratio = maxWidth / imageWidth
@jeffrafter
jeffrafter / Keychain.swift
Last active February 6, 2017 20:55
Keychain generic password management in swift 3
//
// Keychain.swift
// rplcat
//
// Created by Jeffrey Rafter on 2/6/17.
// Copyright © 2017 Rplcat. All rights reserved.
//
import Foundation
import Security
@jeffrafter
jeffrafter / .gitignore
Last active January 25, 2017 17:30 — forked from BennettSmith/.gitignore
Google Protobuf v2.6.0 Build Script for iOS
protobuf
protobuf-2.6.0
protobuf-2.6.1
protobuf-master
@jeffrafter
jeffrafter / README.md
Created March 23, 2016 20:43
Checking for azer usages in a group of repos

Fetch a list of all of the repos:

./fetch-repos.sh

This gives you a list of repos, then grab the ssh urls (ugly, but workable)

grep ssh_url repos.json | cut -f 2,3 -d: | sed -E 's/[\"\,]|[^A-Za-z0-9@:-\.\/]//g'

Clone all of those into the same folder (crazy!)

@jeffrafter
jeffrafter / rate_limits.rb
Created May 28, 2015 21:16
Handle Shopify API rate limits
# https://docs.shopify.com/api/introduction/api-call-limit
module ActiveResource
# 429 Client Error
class RateLimitExceededError < ClientError # :nodoc:
end
class Connection
RATE_LIMIT_SLEEP_SECONDS = 20 # number of seconds to sleep (by sleeping 20 you reset the clock to get 40 fresh burst calls with the default 2 calls/sec)
@jeffrafter
jeffrafter / Gemfile
Created May 28, 2015 20:30
Uploading static files to S3
# Aws and static site rendering
gem 'aws-sdk', '< 2.0'
class Thing
def say_hi
puts "Hi"
end
end
thing = Thing.new
thing.say_hi
# "Hi"
def say_hello
name = yield # runs the block and captures the output
puts "Hello #{name}"
end
say_hello do
"ellisTAA"
end