diff --git a/bash/z-eyes.sh b/bash/z-eyes.sh new file mode 100755 index 0000000..4657285 --- /dev/null +++ b/bash/z-eyes.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# got to redirect stderr of zenity to /dev/null. Otherwise error message about lack of parent window will show up in the terminal + +rest_time=20m +distant_stare_time=20 + +function show_progress_bar { + for i in {0..100..5} # equiv of 20s because 1s per iterations as there are 20 iterations for this loop. + do + echo $i + sleep $(( $distant_stare_time / 20 )) + done | + zenity --title='z-eyes' --text='Look 20 feet away for 20 seconds' --progress --auto-close 2> /dev/null + + if [ "$?" -eq 0 ] # Didn't cancel + then + zenity --notification --text "20 seconds is up." 2> /dev/null + else # Cancelled + zenity --notification --text "20 seconds was not completed." 2> /dev/null + fi +} + +while true +do + sleep "$rest_time" && zenity --info --text "Your eyes are tired. Rest?" --title="z-eyes" 2> /dev/null + + show_progress_bar +done diff --git a/cpp/README.md b/cpp/README.md new file mode 100644 index 0000000..7a412c8 --- /dev/null +++ b/cpp/README.md @@ -0,0 +1,3 @@ +## Some C++ sample programs + +To get familiar with some STL. diff --git a/cpp/deque.cpp b/cpp/deque.cpp new file mode 100644 index 0000000..c14f78f --- /dev/null +++ b/cpp/deque.cpp @@ -0,0 +1,42 @@ +/* +Reference: https://en.cppreference.com/w/cpp/container/deque +Tried on: g++ 7.5.0 + +Double ended queue. + +Pros: +Easy insertion/deletion at front/back. +Supports indexing (random access). +Has all methods of queue (NOT SURE) +*/ + +#include +#include + +void print_dq(std::deque dq) { + std::cout << "Deque is: "; + for(auto elem: dq) { + std::cout << elem << ","; + } + std::cout << "\n"; +} + +int main() { + std::deque intdq = {10, 20, 30, 40, 50}; + print_dq(intdq); + + intdq.push_back(60); + print_dq(intdq); + + intdq.push_front(5); + print_dq(intdq); + + intdq.pop_front(); + print_dq(intdq); + + intdq.pop_back(); + print_dq(intdq); + + std::cout << "intdq[2]: " << intdq[2] << "\n"; +} + diff --git a/cpp/exceptions.cpp b/cpp/exceptions.cpp new file mode 100644 index 0000000..d12e8b3 --- /dev/null +++ b/cpp/exceptions.cpp @@ -0,0 +1,31 @@ +/* +Reference: https://en.cppreference.com/w/cpp/error +Tried on: g++ 7.5.0 +*/ + +#include +#include + +int divide(int a, int b) { + if(b == 0) { + throw std::runtime_error("Divide by zero!"); + } + return a / b; +} + +int main() { + try { + std::cout << divide(40, 0) << "\n"; + } catch(std::runtime_error &e) { + std::cout << e.what() << "\n"; + } + + std::vector vec = {1, 2}; + try { + std::cout << vec.at(2) << "\n"; + } catch(std::out_of_range &e) { + std::cout << e.what() << "\n"; + } + std::cout << vec[2] << "\n"; // [] operator doesn't throw exception + // but at() does +} diff --git a/cpp/files.cpp b/cpp/files.cpp new file mode 100644 index 0000000..5223766 --- /dev/null +++ b/cpp/files.cpp @@ -0,0 +1,16 @@ +/* +Reference: https://en.cppreference.com/w/cpp/container/vector +Tried on: g++ 7.5.0 +*/ + +#include +#include + +int main() { + int x, y; + std::ifstream fin("input.txt"); + fin >> x >> y >> y; + std::cout << x << ", " << y << "\n"; +} + + diff --git a/cpp/list.cpp b/cpp/list.cpp new file mode 100644 index 0000000..0d0cfb1 --- /dev/null +++ b/cpp/list.cpp @@ -0,0 +1,73 @@ +/* +Reference: https://en.cppreference.com/w/cpp/container/list +Tried on: g++ 7.5.0 + +LIke a singly linked list. + +Pros: +Easy insertion/deletion at front/back. +Sorting possible. + +Cons: +No random access. Got to iterate to access required indices. +*/ + + +#include +#include + +void print_list(std::list lst) { + std::cout << "List is:"; + for(auto elem: lst) { + std::cout << elem <<","; + } + std::cout << "\n"; +} + +int main() { + std::list intlist = {1, 2}; + print_list(intlist); + + // Insert at the end of the list + intlist.push_back(3); + print_list(intlist); + + // Insert at the begining + intlist.push_front(0); + print_list(intlist); + + std::cout << "Current size: " << intlist.size() << "\n"; + //std::cout << "Max size: " << intlist.max_size() << "\n"; + std::cout << "First elem (font): " << intlist.front() << "\n"; + std::cout << "Last elem (back): " << intlist.back() << "\n"; + + // Accessing elements + std::list::iterator itr = intlist.begin(); // iterator from beginning + // of list + + std::advance(itr, 2); // advance iterator by two positions + std::cout << *itr << "\n"; + + ++itr; // advance itertor by 1 + std::cout << *itr << "\n"; + print_list(intlist); + + // Modifying elements + *itr = 33; + print_list(intlist); + + ++itr; + *itr = 4; // No effect. Outside the list now. Iteration over. + print_list(intlist); + + //Remove next to the last element + //std::list::reverse_iterator ritr = intlist.rend(); + itr = intlist.begin(); + itr++; // Now points to next to the last element + intlist.erase(itr); // Remove 1 from index 1 + print_list(intlist); + + // Reverse list inplace + intlist.reverse(); + print_list(intlist); +} diff --git a/cpp/queue.cpp b/cpp/queue.cpp new file mode 100644 index 0000000..fdd155b --- /dev/null +++ b/cpp/queue.cpp @@ -0,0 +1,32 @@ +/* +Reference: https://en.cppreference.com/w/cpp/container/queue +Tried on: g++ 7.5.0 + +Pros: +Easy insertion at back. +Easy deletion at front. +Easy access front/back. + +Cons: +Printing not easy. +No easy initialization from array (NOT SURE) +*/ + +#include +#include + +int main() { + std::queue intq; + + // Push + intq.push(60); + intq.push(70); + intq.push(80); + std::cout << "Size: " << intq.size() << "\n"; + std::cout << "Front: " << intq.front() << "\n"; + std::cout << "Back: " << intq.back() << "\n"; + + // Pop + intq.pop(); + std::cout << "Front: " << intq.front() << "\n"; +} diff --git a/cpp/reading_input.cpp b/cpp/reading_input.cpp new file mode 100644 index 0000000..fe327d2 --- /dev/null +++ b/cpp/reading_input.cpp @@ -0,0 +1,19 @@ +/* +Reference: https://en.cppreference.com/w/cpp/io/cin + https://en.cppreference.com/w/cpp/string/basic_string/getline +Tried on: g++ 7.5.0 +*/ + +#include +#include + +int main() { + std::string msg; + + std::getline(std::cin, msg); + std::cout << msg << "\n"; + + std::cin >> msg; // only read till first white space + std::cout << msg << "\n"; +} + diff --git a/cpp/set.cpp b/cpp/set.cpp new file mode 100644 index 0000000..5a12f1d --- /dev/null +++ b/cpp/set.cpp @@ -0,0 +1,27 @@ +/* +Reference: https://en.cppreference.com/w/cpp/container/set +Tried on: g++ 7.5.0 + +*/ + +#include +#include + +void print_set(std::set st) { + std::cout << "Set is: "; + for(auto elem: st) { + std::cout << elem << ","; + } + std::cout << "\n"; +} + +int main() { + std::set intset = {10, 20, 30, 40, 50}; + print_set(intset); + + // Check if set is empty + std::cout << intset.empty() << "\n"; + + // Set size + std::cout << intset.size() << "\n"; +} diff --git a/cpp/strings.cpp b/cpp/strings.cpp new file mode 100644 index 0000000..bf1f785 --- /dev/null +++ b/cpp/strings.cpp @@ -0,0 +1,34 @@ +/* +Reference: https://en.cppreference.com/w/cpp/string +Tried on: g++ 7.5.0 +*/ + +#include +#include + +int main() { + std::basic_string str = "hello"; + std::cout << str << "\n"; + + // Char-by-char access + std::cout << str[1] << "\n"; + std::cout << str.at(2) << "\n"; + + // Length + std::cout << str.length() << "\n"; + std::cout << str.size() << "\n"; + + // Appending + str += " wo"; + std::cout << str << "\n"; + str.append("rld"); + std::cout << str << "\n"; + + // String to int + str = "234"; + std::cout << std::stoi(str) << "\n"; + + // String to float + str += ".5"; + std::cout << std::stof(str) << "\n"; +} diff --git a/cpp/vector.cpp b/cpp/vector.cpp new file mode 100644 index 0000000..184c715 --- /dev/null +++ b/cpp/vector.cpp @@ -0,0 +1,62 @@ +/* +Reference: https://en.cppreference.com/w/cpp/container/vector +Tried on: g++ 7.5.0 + +Like an array. + +Pros: +Supports indexing (random access) +Easy insertion or deletion at back. + +Cons: +No sorting. +*/ + +#include +#include + +void print_vector(std::vector vec) { + std::cout << "Vector is: "; + for(auto elem: vec) { + std::cout << elem << ","; + } + std::cout << "\n"; +} + +int main() { + std::vector intvec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + print_vector(intvec); + + //Size + std::cout << "Size: " << intvec.size() << "\n"; + std::cout << "Capacity: " << intvec.capacity() << "\n"; + //std::cout << "Max size: " << intvec.max_size() << "\n"; + + // Random access + intvec[2] = 33; + print_vector(intvec); + std::cout << "intvec[1]: " << intvec[1] << "\n"; + std::cout << "intvec.at(1): " << intvec.at(1) << "\n"; + + // Insert + //std::vector::const_iterator itr = intvec.cbegin(); + std::vector::iterator itr = intvec.begin(); + intvec.insert(itr + 1, 132); + print_vector(intvec); + + // Push back + intvec.push_back(100); + print_vector(intvec); + + // Pop back (pop_back() returns void) + intvec.pop_back(); + print_vector(intvec); + + // Exchange (swap) contents of two vectors + std::vector othervec = {11, 22}; + othervec.swap(intvec); + std::cout << "intvec:-"; + print_vector(intvec); + std::cout << "othervec:-"; + print_vector(othervec); +} diff --git a/python/keylog.py b/python/keylog.py new file mode 100644 index 0000000..4b1864d --- /dev/null +++ b/python/keylog.py @@ -0,0 +1,26 @@ +# For now, ignore specials. + +from pynput.keyboard import Key, Listener + +def on_press(key): + #print(f"{key} pressed") + #key = ord(key.char) + #print(f"{key:x}") + + try: + #print(f"{key.char},{key} up") + print(f"{key:x}") + except ValueError: + #print(f"special key {key} up") + pass + + +def on_release(key): + print('{0} release'.format(key)) + #if key == Key.esc: + # Stop listener + # return False + +# Collect events until released +with Listener(on_press=on_press, on_release=on_release) as listener: + listener.join() diff --git a/python/sympy-hello.py b/python/sympy-hello.py new file mode 100644 index 0000000..2b827e3 --- /dev/null +++ b/python/sympy-hello.py @@ -0,0 +1,23 @@ +""" +∨: | +∧: & +¬: ~ +→: >> +←: << + +True: sympy.S.true +False: sympy.S.false + +XOR: ^ + +NAND: Nand() +NOR: Nor() + +Equivalence: Equivalent() +""" + + +import sympy + +a, b = sympy.symbols("a,b") +#∨ = sympy.logic.boolalg.Boolean.__or__