Skip to content

Instantly share code, notes, and snippets.

View arunenigma's full-sized avatar

Shan arunenigma

  • Silicon Valley
View GitHub Profile
@arunenigma
arunenigma / mac_terminal_commands.txt
Last active December 15, 2015 07:19
Mac Terminal Commands
mdfind dict.txt ==> pulls down all paths associated with the file name
ffmpeg ==> combine images to form video
ffmpeg -f image2 -r 1/5 -i image%03d.png -vcodec mpeg4 -y movie.mp4
where image2 --> part of command
image%03d --> all images of series 001, 002, 003 ...
-r --> rate 1/5 (rate of holding each frame for 5 seconds) can be changed to 24 frames (experiment yourself)
dig
@arunenigma
arunenigma / bloomberg_1.cpp
Created March 22, 2013 05:52
Given a char array "1,204,342,544". Modify the char array so that there is no comma, in the most efficient way. We must get a char array 120434254.
/*
Given a char array "1,204,342,544"
Modify the char array so that there is no comma in the most efficient way.
We must get a char array 1204342544
*/
#include <iostream>
using namespace std;
@arunenigma
arunenigma / vector_delete_elements.cpp
Last active December 15, 2015 06:49
C++ Vector : Deleting elements easily from Vectors using Vector Iterator and Erase
// C++ program to remove multiples of 6 from a vector list
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool condFunc (int i) { return ((i%6)==0); } // function to check if a number is a multiple of 6
void remove_if_example()
@arunenigma
arunenigma / vector_deletion_preserve_order.cpp
Last active December 15, 2015 06:49
Remove an element from a Vector preserving order
// removing an element from vector preserving order
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> v {3,2,9,82,2,5,4,3,4,6};
for (int i=0; i < v.size(); i++) {
if (v[i] > 9) { // remove element > 9
while (i < v.size()) {
v[i] = v[i+1];
@arunenigma
arunenigma / vector_deletion.cpp
Last active December 15, 2015 06:49
removing an element from an unordered Vector
// removing an element from an vector (order gets changed)
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> v {3,2,9,82,2,5}; // remove element that is greater than 10
unsigned long last_pos = v.size() - 1;
for (int i=0; i < v.size(); i++) {
if (v[i] > 9) { // remove element > 9
@arunenigma
arunenigma / vector.cpp
Created March 22, 2013 01:04
// locate the position of the first element in the Vector that is greater than 100
// locate the position of the first element that is greater than 100
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int>data {4,2,4,2,2,23,23,5,115,113};
int pos = 0;
bool found = false;
while (pos < data.size() && !found) {
if (data[pos] > 100) {
@arunenigma
arunenigma / randint.cpp
Last active December 15, 2015 05:18
C++ snippet to generate random number between a range
// C++ snippet to generate random number between a range
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
srand(time(0));
cout << time(0) << endl;
cout << rand() << endl;
@arunenigma
arunenigma / quick_sort.py
Last active December 15, 2015 04:38
Quick Sort Implementation in Python
#!/usr/bin/env python
# Quick Sort Implementation in Python
# Author: Arunprasath Shankar
# Case Western Reserve University
# Using Partition Method
from random import randint
@arunenigma
arunenigma / python_negatives
Last active December 15, 2015 04:29
Python Negatives
Python's lack of support for recursion elimination causes the recursive implementation to suffer from linear stack usage, which is not acceptable for large lists. An iterative implementation solves this problem.
@arunenigma
arunenigma / binary_search.py
Created March 20, 2013 03:14
Binary Search Implementation in Python
__author__ = 'arun'
def binarySearch(lst, search_term):
"""
Simple Binary Search in Python
for searching sorted sequences
Complexity: log N (base 2) compared to N/2 of Linear Search
"""
min_index = 0