Skip to content

Instantly share code, notes, and snippets.

Too much to do, too little time.

Gaurav Menghani reddragon

Too much to do, too little time.
View GitHub Profile
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()
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.
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:319b2a89d6bbb5ca0836 => For patterns.
Reference Counting (arc).
@ for NSLiteral, so that "" doesn't mean C-string.
Set tableView delegate and dataSource = self.
Set numberOfRowsInSection
Set cell
reddragon / Coins.cpp
Created Oct 11, 2014
Count the number of distinct ways to make an amount N, with C coins.
View Coins.cpp
#include <iostream>
#include <cstring>
// This is a toy program, so please excuse the trivial flaws.
#define MAXN 2000
#define MAXC 20
// An N*C array, hard-coding the max N = 2000, C = 20.
int r[MAXN][MAXC];
int cval[MAXC];
int N, C;
import java.util.Random;
class FooThread extends Thread {
int threadNum;
Random random;
FooThread(int threadNum) {
this.threadNum = threadNum;
this.random = new Random(System.currentTimeMillis() + threadNum);
View gist:8398211
/ Walter White: If you don’t know who I \
| am, maybe your best course would be to |
\ tread lightly. /
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
reddragon / gist:7407165
Last active Dec 27, 2015
This is what I add in my .bashrc / .bash_profile file. This acts like a usual fortune command.
View gist:7407165
curl -s
reddragon / gist:7243190
Created Oct 31, 2013
Bash Colors & Prompt
View gist:7243190
export PS1="\n\[$(tput bold)\]\033[38;5;132m\\u\033[39m \[$(tput sgr0)\]at \033[38;5;180m\h \033[39m\\[$(tput sgr0)\][\033[38;5;191m\\W\033[39m]\n\[\033[38;5;208m\]>\[\033[39m\] "
View gist:7030425
gauravmenghani at localhost [~]
> curl -s | cowsay
/ "Jab koi bachcha nahin sota, to uski \
| maa kehti hai ki... soja soja soja |
\ nahin toh Gogo aa jayega." /
\ ^__^
\ (oo)\_______
(__)\ )\/\