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
(* | |
Run this script: | |
1. By terminal: | |
- Enable Terminal for Accessibility in Privacy section of | |
Security & Provacy in Setting App. | |
- Run `osascript <path_to_file>/<script_name>` in terminal | |
2. By Script Editor | |
- Enable Script Editor for Accessibility in Privacy section of | |
Security & Provacy in Setting App. | |
- Copy the following code in Script Editor and click Run |
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
// Summary: | |
// | |
// immutable : read-only privilege | |
// mutable : read-write privilege | |
// | |
// 1. A read-only(immutable) vairable cannot be casted to a read-write(mutable) variable. | |
// 2. One variable can be read by multiple instances, no matter what its type is. | |
// 3. If one mutable variable is under writting, no other can read or write it. | |
// 4. If one variable is under reading, no other can write it. | |
// |
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
#include <cassert> | |
#include <iostream> | |
// Utilities | |
// ============================================================================ | |
#define SIZE_OF_ARRAY(x) (sizeof(x)/sizeof(x[0])) | |
void printArray(int a[], int length) { | |
for (int i = 0 ; i < length ; ++i) { | |
std::cout << a[i] << " "; |
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
// $ g++ avg.cpp --std=c++11 | |
#include <iostream> | |
// double average = 0; | |
// uint64_t count = 0; | |
// void Add(uint64_t data) | |
// { | |
// average += (data - average) / ++count; | |
// } |
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
#include <cassert> | |
#include <iostream> | |
#include <stack> | |
// Goal: | |
// Sort `s` by decreasing order, from the bottom to the top. | |
// The minimal element will be at the top after sorting. | |
// Limit: | |
// You cannot use other data structures to implement it | |
// except an additional stack. |
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
#include <cassert> // for assert. | |
#include <cstdlib> // for calloc, free. | |
#include <functional> // for std::hash. | |
#include <memory> // for std::unique_ptr. | |
#define DEBUG 1 // Set 1 to log the debugging messages. | |
#define LOG(...) DEBUG && fprintf(stderr, __VA_ARGS__) | |
#if DEBUG | |
#include <iostream> // for std::cout, std::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
#include <cassert> // for assert. | |
#include <cstdlib> // for calloc, free. | |
#include <cstring> // for memcpy. | |
template<class T> | |
class AutoArray | |
{ | |
public: | |
AutoArray(unsigned int aCapacity = 0) | |
: mCapacity(aCapacity) |
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
// $ g++ mincost.cpp --std=c++11 | |
#include <algorithm> | |
#include <cassert> | |
#include <iostream> | |
#include <vector> | |
#undef RECURSION | |
#undef MEMOIZATION | |
#undef DYNAMIC_PROGRAMMING | |
#undef RUN |
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
// Combination(n, k): | |
// Returns the number of combination of n things taken k | |
// at a time without repetition. | |
#include <algorithm> | |
#include <cassert> | |
#include <iostream> | |
#include <vector> | |
#undef RECURSION | |
#undef MEMOIZATION |