Skip to content

Instantly share code, notes, and snippets.

View bakkiraju's full-sized avatar

Bilahari bakkiraju

View GitHub Profile
@bakkiraju
bakkiraju / closestK.cpp
Last active September 27, 2016 23:30
C++ STL playground
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <math.h>
using namespace std;
class Point
{
@bakkiraju
bakkiraju / isPalindromeWithDeque.cpp
Created September 27, 2016 23:28
palindrom check using std::deque
#include <iostream>
#include <deque>
using namespace std;
bool isPalindrome(const char *in) {
deque<char> dq;
while (*in != '\0') {
dq.push_back(*in);
@bakkiraju
bakkiraju / sortDiffSizeArrays.cpp
Created September 28, 2016 00:23
Given two sorted arrays, return single sorted array
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
vector <int> A = {10,20,30,40,50,60,70,80};
int i = A.size()-1;
vector <int> B = {11,22,33,44};
#!/usr/bin/python
#kb_map = [ ['a','b','c','d','e'],
# ['f','g','h','i','j'],
# ['k','l','m','n','o'],
# ['p','q','r','s','t'],
# ['u','v','w','x','y'],
# ['z', ' ', ' ', ' ', ' ']
# ]
from collections import deque
def isPlainDrome(inDeque):
while len(inDeque) > 1:
if inDeque.pop() != inDeque.popleft():
return False
return True
@bakkiraju
bakkiraju / shuffleArrayItems.py
Created October 10, 2016 00:56
Fisher-Yates shuffle
import random
def shuffle(in_arr):
n = len(in_arr)
for i in range(n-1,-1,-1):
j = random.randint(0,i)
in_arr[i],in_arr[j] = in_arr[j],in_arr[i]
return in_arr
@bakkiraju
bakkiraju / substringMatchScore.cpp
Created December 2, 2016 01:07
substring which would be closest (max overlap) to a given prefix and suffix
#include <iostream>
#include <string>
using namespace std;
int returnMatchCount(const string &s1, const string &s2)
{
int cnt = 0;
for (int i = s1.length()-1; i >=0; i--) {
string sub_sub = s1.substr(i,s1.length()-i);
@bakkiraju
bakkiraju / gist:47f8f228be2f0ae739c284be041b228f
Last active January 27, 2017 22:35
Important Redux concepts culled out from redux.js.org
Redux attempts to make state mutations predictable by imposing certain restrictions on how and when updates can happen.
These restrictions are reflected in the three principles of Redux.
- State is single source of truth
- State is read-only
- Changes are made with pure functions
Key terms and concepts:
State:
@bakkiraju
bakkiraju / gist:bed042bb7f659fd99c748c7a32b835d5
Created February 7, 2017 06:47
Always on the Top, click through transparent window in Swift
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
func applicationDidFinishLaunching(_ aNotification: Notification) {
@bakkiraju
bakkiraju / js
Created March 22, 2017 02:31
MultiController-AngularJS example
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp">
<div ng-controller="personCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>