This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # Quick Sort Implementation in Python | |
| # Author: Arunprasath Shankar | |
| # Case Western Reserve University | |
| # Using Partition Method | |
| from random import randint | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __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 |