Skip to content

Instantly share code, notes, and snippets.

Avatar
🤖
Too much to do, too little time.

Gaurav Menghani reddragon

🤖
Too much to do, too little time.
View GitHub Profile
View gist:95a689aaadea3365a144
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.
View gist:b43132bfe5801ca90466
* 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
View gist:195dd2ce87f62d2db66d
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 Aug 29, 2015
Interesting Companies
View gist:bca9be25e50a475044a7
Delivery/Logistics:
Instacart
Munchery
Lyft
Sidecar
Uber
Thumbtack
DoorDash
Grubhub
Seamless
@reddragon
reddragon / libevent-demo.cpp
Last active Jun 11, 2021
A demo for libevent usage
View libevent-demo.cpp
#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>
View djikstra-slow.cpp
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
struct Edge {
int src, dst;
int w;
};
View linked-list-cyle.cpp
#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 Dec 8, 2016
First node in a cycle in a Linked List
View linked-list-cycle-first-node.cpp
#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 Dec 8, 2016
A util file for misc algo problems
View util.h
#pragma once
#include <iostream>
#include <cassert>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdio>
@reddragon
reddragon / unordered_map.cpp
Created Dec 22, 2016
Hash Function for unordered_map
View unordered_map.cpp
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);
}
};