Skip to content

Instantly share code, notes, and snippets.

View isoiphone's full-sized avatar

Jacob Schwartz isoiphone

View GitHub Profile
@isoiphone
isoiphone / PrivacyScreen.h
Created January 17, 2014 20:57
Hide contents of screen when displaying Instabug feedback form.
#import <UIKit/UIKit.h>
@interface PrivacyScreen : UIViewController
@end
@isoiphone
isoiphone / gist:8535715
Created January 21, 2014 07:23
Why was this so hard!? Aspect fitting an OpenGL ES 2 view in a randomly sized window.
void Graphics::resize(int screenWidth, int screenHeight)
{
glViewport(0, 0, screenWidth, screenHeight);
const float widthRatio = screenWidth/(float)kViewWidth;
const float heightRatio = screenHeight/(float)kViewHeight;
const float scale = 1.0f/std::max(widthRatio, heightRatio);
const float finalWidth = screenWidth*scale;
const float finalHeight = screenHeight*scale;
@isoiphone
isoiphone / FindWithDefault.h
Last active January 4, 2016 05:09
Lookup given key in map. If it isn't found than use getDefault() to create a default value which is inserted then returned. I find myself re-writing this functionality ALL THE FREAKING TIME, so finally wrote a template. https://github.com/nguillemot suggested an edit to remove functor, now iz better.
#pragma once
#include <map>
template <typename K, typename V, typename F>
V FindWithDefault(std::map <K,V> & map, const std::string & key, const F& getDefault) {
typename std::map<K, V>::const_iterator it = map.find( key );
if ( it == map.end() ) {
V defaultValue = getDefault();
map.insert( std::pair<K,V>(key, defaultValue) );
// oh dear god...
if ([[[[_actionSheet superview] superview] nextResponder] respondsToSelector:@selector(setPassthroughViews:)]) {
[[[[_actionSheet superview] superview] nextResponder] performSelector:@selector(setPassthroughViews:) withObject:nil];
}
@isoiphone
isoiphone / arrayWithoutDuplicates.m
Last active August 29, 2015 13:57
Given an array, remove the duplicates and return a unique array keeping the first occurrence of the duplicates and the order. [@2, @1, @3, @1, @2] --> [@2, @1, @3]
#import <Foundation/Foundation.h>
#import <stdio.h>
@interface Test : NSObject
@end
@implementation Test
+ (NSArray*)arrayWithoutDuplicates:(NSArray*)a {
NSMutableSet* s = [NSMutableSet set];
#import <Foundation/Foundation.h>
#import <stdio.h>
@class Node;
@interface Node : NSObject
@property (strong) Node* next;
@property (assign) NSString* val;
@end
#include "Platform.h"
bool Platform::mapFile(const char* filename, uint8_t** bytes, long* length) {
FILE* fin = fopen(Platform::pathForFile(filename).c_str(), "rb");
if (!fin) {
dbgLog("error opening file '%s'", filename);
return false;
}
@isoiphone
isoiphone / NQueens.swift
Last active August 29, 2015 14:14
N queens problem in Swift
// jacob schwartz | @isoiphone
// solves N queens problem in swift
// for N=8 there should be 92 possible solutions
// each solution is a list of numbers, these indicate the row to place queen for given column
// for example 0,4,7,5,2,6,1,3 maps to:
// Q-------
// ------Q-
// ----Q---
// -------Q
// -Q------
@isoiphone
isoiphone / main.c
Last active August 29, 2015 14:14
one line string reverse in place, because
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void reverse(char *s) {
for (char *front = s, *back=s+strlen(s)-1; front < back; *front ^= *back, *back ^= *front, *front ^= *back, ++front, --back) {}
}
void test(const char* s) {
char* tmp = strdup(s);
@isoiphone
isoiphone / gist:a1c8ec2e8fceae3be56b
Last active August 29, 2015 14:15
Swift 1.2 breaks my __FUNCTION__
// no longer compiles in swift 1.2
func someFunc(block: () -> (), functionName: String = __FUNCTION__) {
println("NEAT!")
block()
}
someFunc {
println("oh")
}