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
@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()
* 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
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.
@reddragon
reddragon / gist:319b2a89d6bbb5ca0836
Last active August 29, 2015 14:07
iOS Week 1 - Class 1
pttrns.com => 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
reddragon / Coins.cpp
Created October 11, 2014 19:48
Count the number of distinct ways to make an amount N, with C coins.
#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;
@reddragon
reddragon / FooThread.java
Created January 15, 2014 13:10
Threading Demo
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);
}
@reddragon
reddragon / gist:8398211
Created January 13, 2014 10:49
Cowsay Example
_________________________________________
/ Walter White: If you don’t know who I \
| am, maybe your best course would be to |
\ tread lightly. /
-----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
@reddragon
reddragon / gist:7407165
Last active December 27, 2015 23:39
This is what I add in my .bashrc / .bash_profile file. This acts like a usual fortune command.
curl -s http://randquotes.com/qt?f=cowsay
@reddragon
reddragon / gist:7243190
Created October 31, 2013 01:37
Bash Colors & Prompt
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\] "
gauravmenghani at localhost [~]
> curl -s http://andazapnapna.com/quote | cowsay
______________________________________
/ "Jab koi bachcha nahin sota, to uski \
| maa kehti hai ki... soja soja soja |
\ nahin toh Gogo aa jayega." /
--------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\