Skip to content

Instantly share code, notes, and snippets.

Benjamin Sandofsky sandofsky

Block or report user

Report or block sandofsky

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View BadExtensions.swift
import AVFoundation
import UIKit
class ViewController: UIViewController {
var discoverSession:MyDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInDualCamera, .builtInWideAngleCamera, .builtInTelephotoCamera], mediaType: .video, position: .back)
@IBAction func didTapCrashButton(_ sender: Any) {
let devices = discoverSession.myDevices
print("Got devices: \(devices)")
View Storyboard Backed Extension
import UIKit
protocol StoryboardBacked:class {
static func newFromStoryboardWithName(name:String?, bundle:NSBundle?) -> Self
}
extension StoryboardBacked {
static func newFromStoryboardWithName(name:String?, bundle:NSBundle?) -> Self {
let realName = name ?? NSStringFromClass(self as AnyClass).componentsSeparatedByString(".").last!
let storyboard = UIStoryboard(name: realName, bundle: bundle)
View example.swift
typealias Callback = () -> ()
// Both methods are required
class Something {
var calledOnce:Callback?
var calledMultipleTimes:Callback?
}
@sandofsky
sandofsky / gist:7134b1ff90d235901254
Created Feb 19, 2015
Example of fetching messages from Parse
View gist:7134b1ff90d235901254
class ViewController: UITableViewController {
var messages:[Message]?
var timer:NSTimer?
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
View gist:fc65dde1a012a207eb9a
let delay = 2.0 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue(), {
})
@sandofsky
sandofsky / gist:1004151
Created Jun 2, 2011
Alternatives to alias_method_chain
View gist:1004151
# Different ways to hook into an action
class ExampleAPI
def foo
puts "Foo"
end
end
# Option 1: alias_method_chain
class ExampleAPI
View gist:933270
javascript:(document.body.innerHTML = document.body.innerHTML.replace(/HTML5/g,"Java Applet"))
View threadtest.rb
require 'thread'
t = ARGV[0].to_i
c = ARGV[1].to_i
0.upto(t) do |i|
thread = []
0.upto(c) do |j|
thread[j] = Thread.new { }
end
0.upto(c) do |j|
thread[j].join
View threadtest.c
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *dumb_thread();
main(int argc, char *argv[])
{
int total = atoi(argv[1]);
int concurrency = atoi(argv[2]);
pthread_t pthread[concurrency];
View ImageResizingBenchmarks.rb
require 'rubygems'
require 'rusage'
require 'pp'
require 'benchmark'
files = Dir['samples/**/*']
command = case ARGV[0]
when 'gd2'
require 'gd2'
lambda do |file|
GD2::Image.import(file).resize(128, 128).export('/dev/null', :format => :jpeg)
You can’t perform that action at this time.