Skip to content

Instantly share code, notes, and snippets.

View sandofsky's full-sized avatar

Benjamin Sandofsky sandofsky

View GitHub Profile
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)")
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)
typealias Callback = () -> ()
// Both methods are required
class Something {
var calledOnce:Callback?
var calledMultipleTimes:Callback?
}
@sandofsky
sandofsky / gist:1004151
Created June 2, 2011 09:14
Alternatives to alias_method_chain
# Different ways to hook into an action
class ExampleAPI
def foo
puts "Foo"
end
end
# Option 1: alias_method_chain
class ExampleAPI
javascript:(document.body.innerHTML = document.body.innerHTML.replace(/HTML5/g,"Java Applet"))
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
#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];
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)
<?xml version="1.0" encoding="UTF-8"?>
<status>
<created_at>Thu Mar 18 21:19:11 +0000 2010</created_at>
<id>10689863523</id>
<text>As you can tell by this tweet, geo tagging is now available on mobile.twitter.com.</text>
<source>&lt;a href=&quot;http://mobile.twitter.com&quot; rel=&quot;nofollow&quot;&gt;mobile web&lt;/a&gt;</source>
<truncated>false</truncated>
<in_reply_to_status_id></in_reply_to_status_id>
<in_reply_to_user_id></in_reply_to_user_id>
<favorited>false</favorited>
{
"in_reply_to_screen_name": null,
"in_reply_to_user_id": null,
"created_at": "Thu Mar 18 21:19:11 +0000 2010",
"in_reply_to_status_id": null,
"geo": {
"type": "Point",
"coordinates": [37.77576905, -122.40486341]
},
"favorited": false,