Skip to content

Instantly share code, notes, and snippets.

View reddragon's full-sized avatar
🤖
Too much to do, too little time.

Gaurav Menghani reddragon

🤖
Too much to do, too little time.
View GitHub Profile
If you delete the default Storyboard etc., put this in the AppDelegate.m
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
When setting things like images in cells, reuse the cells. For some reason, if you allocate a fresh cell, it doesn't work.
Pass data between controllers, rather than views, or modifying the view of the next controller.
* Select Image View Mode for Image Resizing if its bigger than the screen.
* Delegate - Add callbacks somewhere else when something changes.
* protocol and interface are synonyms in objc.
Delegate Pattern
* Can use delegate instead of passing around controllers.
* Mark protocol methods as @optional if you dont need them.
* Check this via respondsToSelector method.
* KVO
@reddragon
reddragon / gist:195dd2ce87f62d2db66d
Created December 12, 2014 13:33
Some interview questions
1. Do binary search on a rotated array.
Eg., given [100, 110, 121, 5, 11, 44, 78, 91, 99], be able to binary search on it.
2. Implement the * and / operations without actual multiplication and division.
3. Implement the ^ operator without using any in-build exponentiation methods.
4. Implement the median of an unsorted array in O(n).
5. Implement sqrt()
@reddragon
reddragon / gist:bca9be25e50a475044a7
Last active August 29, 2015 14:11
Interesting Companies
Delivery/Logistics:
Instacart
Munchery
Lyft
Sidecar
Uber
Thumbtack
DoorDash
Grubhub
Seamless
@reddragon
reddragon / libevent-demo.cpp
Last active November 24, 2023 10:32
A demo for libevent usage
#include <iostream>
#include <cstdio>
#include <vector>
#include <event2/event.h>
#include <glog/logging.h>
#include <cassert>
#include <string>
#include <cstring>
#include <sys/socket.h>
#include <netinet/in.h>
@reddragon
reddragon / djikstra-slow.cpp
Created December 30, 2014 18:13
O(|V||E|) Djikstra
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
struct Edge {
int src, dst;
int w;
};
#include <iostream>
#include <cassert>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <limits>
#include <bitset>
@reddragon
reddragon / linked-list-cycle-first-node.cpp
Created December 8, 2016 05:28
First node in a cycle in a Linked List
#include <iostream>
#include <cassert>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <limits>
#include <bitset>
@reddragon
reddragon / util.h
Created December 8, 2016 05:43
A util file for misc algo problems
#pragma once
#include <iostream>
#include <cassert>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdio>
@reddragon
reddragon / unordered_map.cpp
Created December 22, 2016 03:06
Hash Function for unordered_map
struct Slope {
int n, d;
Slope(int nn, int dd) {
int g = gcd(abs(nn), abs(dd));
// cout << "gcd of " << nn << ", " << dd << " is: " << g << endl;
n = (g > 0 ? nn/g : nn);
d = (g > 0 ? dd/g : dd);
}
};