Skip to content

Instantly share code, notes, and snippets.

@aranm
aranm / gist:5428332
Created April 21, 2013 03:20
Make sure that you respond to notifications on the main thread
- (void)respondToNotification:(NSNotification *)notification {
if (![NSThread isMainThread]) {
[self performSelectorOnMainThread:@selector(respondToNotification:) withObject:notification waitUntilDone:YES];
return;
}
//Code here
}
@aranm
aranm / gist:5410239
Created April 18, 2013 04:57
Render a partial razor view to a string. Can't remember where this code came from originally (it isn't mine)
private static string RenderPartialViewToString(Controller controller, string pathToView, object viewModel,
ViewDataDictionary viewData = null) {
String result;
var viewEngine = ViewEngines.Engines.FindPartialView(controller.ControllerContext, pathToView);
using (var writer = new StringWriter()) {
var vd = viewData == null ? new ViewDataDictionary(viewModel)
: new ViewDataDictionary(viewData) { Model = viewModel };
var viewContext = new ViewContext(controller.ControllerContext,
viewEngine.View,
@aranm
aranm / gist:3916122
Created October 19, 2012 03:48
Require Config with jQuery
require.config({
paths: {
//3rd Party libraries
'knockout': 'knockout-2.2.0.debug',
'jquery': 'jquery-1.7.1',
'doubletap': 'jquery.doubletap',
'address': 'jquery.address-1.4.min',
'bootstrap': 'bootstrap-2.0.1',
'amplify': 'amplify',
'JQueryDictionary": "Utilities/JQueryDictionary',
@aranm
aranm / gist:1406610
Created November 29, 2011 21:34
iOS AudioSession Getting all USB Audio Ouputs
/* print a CFNumber */
void printCfNumber(CFNumberRef cfNum) {
SInt32 s;
if(!CFNumberGetValue(cfNum, kCFNumberSInt32Type, &s)) {
printf("***CFNumber overflow***");
return;
}
printf("%d", (int)s);
}