Skip to content

Instantly share code, notes, and snippets.

View poanchen's full-sized avatar

PoAn (Baron) Chen poanchen

View GitHub Profile
@poanchen
poanchen / run.py
Created June 11, 2017 19:23
A python program which scans a folder called Monday, in that folder will be text files and each of them will have an email address on the first line. The program will simply send an email using smtp. This snippet of code is used to answer this question on Quora. https://www.quora.com/How-do-I-write-a-python-program-that-scans-a-folder-looks-at-e…
# to run the program
# python run.py
# folders structure
# |->run.py
# |->Monday/
# |->Monday/a.txt
# |->Monday/b.txt
# |->Monday/c.txt
#
# Example of a.txt file:
@poanchen
poanchen / SimpleClass.cpp
Created September 19, 2017 04:08
Write a simple class that uses with a private variable and a public member function.
// https://repl.it/LECL
#include <iostream>
using namespace std;
class SimpleClass
{
private:
string privateStr;
public:
@poanchen
poanchen / HelloWorldInterface.cpp
Created September 19, 2017 04:10
Create an interface class with a pure virtual function. Create another class that inherits from it, and give a concrete implementation of the pure virtual function.
// https://repl.it/LEHR
#include <iostream>
using namespace std;
class HelloWorldInterfaceA
{
public:
virtual void printHelloWorldA() = 0;
};
@poanchen
poanchen / LinkedListNode.cpp
Created September 19, 2017 04:11
Write a simple class template “LinkedListNode”, which stores an object of type “T” and a pointer to the next node of type “LinkedListNode*”. It doesn’t need to have any member functions.
// https://repl.it/LORG
#include <iostream>
using namespace std;
template <class T>
class LinkedListNode {
public:
T value;
LinkedListNode<T>* next;
@poanchen
poanchen / SimpleMap.cpp
Created September 19, 2017 04:12
Create a std::map and insert into it the key-value pairs {“one”,1}, {“two”,2}, and {“three”,3}.
// https://repl.it/LO2s
#include <iostream>
#include <map>
using namespace std;
int main()
{
std:map <string, int> intMap;
@poanchen
poanchen / Vector3.cpp
Created September 19, 2017 04:13
Define operator+ and operator+= for the simple 3D vector class below
// https://repl.it/LO2b
#include <iostream>
using namespace std;
struct Vector3 {
float x, y, z;
Vector3& operator+(const Vector3& rhs) {
*this += rhs;
@poanchen
poanchen / createDefaultMainJava.py
Created February 5, 2018 09:20
A python script that will create a barebone Java code with the default main class along with testcase1 and printlist functions that are necessary for doing competeive programming questions
import os
i = 12
while os.path.exists("./Solution" + str(i) + ".java"):
i += 1
file_contents = """import java.util.*;
import java.lang.*;
public class Solution%s {
public static void testCase1() {
}
@poanchen
poanchen / runJava.py
Created February 5, 2018 09:21
A python script that will find the latest java program compile and execute them
import os
i = 12
while os.path.exists("./Solution" + str(i) + ".java"):
i += 1
i -= 1
os.system("javac Solution" + str(i) + ".java")
os.system("java Solution" + str(i))
@poanchen
poanchen / kill.bash
Created February 23, 2018 22:14
Killing the process id that occupy the port you were using
lsof -w -n -i tcp:port_number
kill -9 pid_number
@poanchen
poanchen / lookUpProcessAndKillTheProcess.sh
Created March 6, 2018 07:49
look up the process that is using the port number and kill it (windows 10)
netstat -a -o -n
taskkill /F /PID 12345