Skip to content

Instantly share code, notes, and snippets.

@johnnyclem
johnnyclem / command line shell
Created November 6, 2012 21:18 — forked from blakmatrix/command line shell
Getting Meteor todos up on nodejitsu/jitsu
meteor create --example todos
meteor bundle myapp.tgz
tar xzf myapp.tgz
cd bundle
(create package json with settings below)
jitsu databases create mongo <dbname>
(grab dbstring)
jitsu env set PORT 3000
jitsu env set MONGO_URL <dbstring>
jitsu deploy
@johnnyclem
johnnyclem / gist:4054112
Created November 11, 2012 07:50
Store an image in redis
var fs = require('fs'),
querystring = require('querystring'),
redis = require('redis'),
r = redis.createClient(),
allowedTypes = {
'text/javascript': 'js',
'text/css': 'css',
'image/png': 'png',
'image/jpeg': 'jpg',
@johnnyclem
johnnyclem / gist:8215415
Created January 2, 2014 05:31
End the tyranny of UITextFields not resigning first responder when you expect them to, simply add this method to any UIViewController and keyboards will disappear whenever the user touches anywhere other than the keyboard itself or another UITextField
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UIControl *control in self.view.subviews) {
if ([control isKindOfClass:[UITextField class]]) {
[control endEditing:YES];
}
}
}
@johnnyclem
johnnyclem / iOS Camera - Highest Framerate
Last active May 18, 2018 05:32
this method sets the camera frame rate to the max available for the device
- (void)configureCameraForHighestFrameRate:(AVCaptureDevice *)device
{
AVCaptureDeviceFormat *bestFormat = nil;
AVFrameRateRange *bestFrameRateRange = nil;
for ( AVCaptureDeviceFormat *format in [device formats] ) {
for ( AVFrameRateRange *range in format.videoSupportedFrameRateRanges ) {
if ( range.maxFrameRate > bestFrameRateRange.maxFrameRate ) {
bestFormat = format;
bestFrameRateRange = range;
}
//
// NSArray+BinarySearch.h
// BinarySearch
//
// Created by Ole Begemann on 19.04.10.
// Copyright 2010 Ole Begemann. All rights reserved.
//
#import <Foundation/Foundation.h>
@johnnyclem
johnnyclem / gist:11015360
Created April 17, 2014 22:35
CMSamplebufferRef to CIImage
CVImageBufferRef cvImage = CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:cvImage];
let notificationCenter = NSNotificationCenter.defaultCenter()
notificationCenter.addObserver(
self,
selector: "textFieldTextChanged:",
name:UITextFieldTextDidChangeNotification,
object: nil
)
func textFieldTextChanged(sender : AnyObject) {
sendButton.enabled = messageField.text.utf16count > 0
// Developer/Library/Frameworks/SenTestingKit.framework/Headers/SenTestCaseRun.h
SENTEST_EXPORT NSString * const SenTestCaseDidStartNotification;
SENTEST_EXPORT NSString * const SenTestCaseDidStopNotification;
SENTEST_EXPORT NSString * const SenTestCaseDidFailNotification;
// Developer/Library/Frameworks/SenTestingKit.framework/Headers/SenTestDistributedNotifier.h
SENTEST_EXPORT NSString * const SenTestNotificationIdentifierKey;
// Developer/Library/Frameworks/SenTestingKit.framework/Headers/SenTestSuiteRun.h
SENTEST_EXPORT NSString * const SenTestSuiteDidStartNotification;
Here is what you need to do to register your app for a custom URL scheme (for the example we will use a "myapp" scheme).
1) In your Info.plist, add a new entry for CFBundleURLTypes: <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>MyApp's URL</string> <key>CFBundleURLSchemes</key> <array> <string>myapp</string> </array> </dict> </array>
2) Somewhere in your application's startup code (e.g. init), add this code: - (void)registerMyApp { [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; }
- (void)getUrl:(NSAppleEventDescriptor )event withReplyEvent:(NSAppleEventDescriptor )replyEvent { NSString url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; // Now you can parse the URL and perform whatever action is needed }
Related Tidbits:
(pv -n $INPUT_DISK_IMAGE | dd of=/dev/$OUTPUT_DISK_ID bs=2m conv=notrunc,noerror) 2>&1 | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0