Skip to content

Instantly share code, notes, and snippets.

View coryalder's full-sized avatar

Cory Alder coryalder

View GitHub Profile
@coryalder
coryalder / BBFlakes.py
Created August 10, 2012 20:46 — forked from jshell/BBFlakes.py
Flake8 Script for BBEdit 10
#!/usr/bin/env python
"""
A quick script to install into your `Application Support/BBEdit/Scripts` folder.
This runs flake8 (requires flake8 to be installed at `/usr/local/bin` -
try ``pip install flake8``) and reformats the results
so that they show up in BBEdit's search results / error / warnings window. Then
the errors can be stepped through one at a time.
I've bound this to control-shift-l. You must save your Python file first before
running the check.
@coryalder
coryalder / UIImage+Invert.swift
Created March 12, 2015 05:42
Invert a UIImage at runtime using Core Image CIFilter + CIContext
extension UIImage {
func invertedImage() -> UIImage? {
let img = CoreImage.CIImage(CGImage: self.CGImage)
let filter = CIFilter(name: "CIColorInvert")
filter.setDefaults()
filter.setValue(img, forKey: "inputImage")
@coryalder
coryalder / blogpost.md
Created August 17, 2011 07:37
Extract html book files from the safari books online iPad app "Safari To Go" using php.

Save books out of Safari Books Online

From http://objectivesea.tumblr.com/post/9033067018/safaribooks

This is hard. I spent way too much time figuring this out, because I was annoyed that a book I bought (Addison-Wesley) was available online for free, except only for 45 days after which payment was required. So I made this hack... probably useful to no one else, but here it is.

Requirements:

  1. iPad.
  2. Safari To Go (the Safari Books Online iPad app).
@coryalder
coryalder / debugserver.js
Created September 6, 2011 18:26
A quick node.js HTTP debug server
// associated blog post here: http://objectivesea.tumblr.com/post/9883454476/node-js-as-an-http-debug-server
var http = require('http');
var echoStore = ''; // put initial value here, will be replaced with the contents of any put or post request.
var server = http.createServer(function (request, response) {
var data = '';
request.on('data', function (chunk) {
@coryalder
coryalder / AmazonProduct.swift
Last active October 23, 2019 08:47
Amazon Product Advertising API + Alamofire
//
// AmazonProduct.swift
// Requires SHXMLParser for parsing Amazon's XML responses (https://github.com/simhanature/SHXMLParser)
//
// Created by Cory Alder on 2015-01-11.
// Copyright (c) 2015 Davander Mobile Corporation. All rights reserved.
//
// partly inspired by RWMAmazonProductAdvertisingManager
import Alamofire
@coryalder
coryalder / gist:6effee57a123420f2f949955f039fcee
Last active July 11, 2017 18:50 — forked from gavrix/gist:5054182
Script integrating OCLint into XCode. Put it in "Run script" build phase.
#!/bin/bash
# https://gist.github.com/gavrix/5054182 original
source ~/.bash_profile
hash oclint &> /dev/null
if [ $? -eq 1 ]; then
echo >&2 "oclint not found, analyzing stopped"
exit 1
fi
class Dummy: NSObject {
@objc func barStyle() -> UIStatusBarStyle {
return .LightContent
}
func swizzle() {
guard let safariClass = NSClassFromString("SFSafariViewController") else {
print("can't swizzle, iOS 8")
@coryalder
coryalder / cgi.swift
Created December 3, 2015 23:04
Example linux swift cgi
import Foundation
// work around the currently missing .componentsSeparatedByString method
extension String {
func split(on: Character) -> [String] {
var segments = [String]()
var current = ""
// This code does not compile without the following two changes
//
// 1. add ! to the type of expensiveThing (`String!`)
// 2. expensiveThing = nil // set expensiveThing to nil
//
// This doesn't really make sense to me. Why should I be forced to finish setup, if I'm going to fail?
// The swift book explains that this is required, but not the logic behind it:
// https://developer.apple.com/library/mac/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-XID_339
// Search for "Failable Initializers for Classes"
//
@coryalder
coryalder / .bash_profile
Created May 20, 2013 02:01
wopen, an Xcode project/workspace opening script
function wopen { # via https://gist.github.com/coryalder/5609996
WORKSPACE="${PWD##*/}.xcworkspace"
PROJECT="${PWD##*/}.xcodeproj"
if [ -a $WORKSPACE ]; then
open $WORKSPACE;
elif [ -a $PROJECT ]; then
open $PROJECT;
else
echo "No workspace or project found.";
fi