This file contains 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
using System; | |
using System.IO; | |
namespace Write2Text | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
using (StreamWriter writetext = new StreamWriter("C:/Users/abdul_na/Desktop/hello.txt")) |
This file contains 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
from multiprocessing import Process | |
import time | |
class TimeoutException(Exception): | |
pass | |
timer = 5 | |
def start_timer(): | |
time.sleep(timer) | |
raise TimeoutException |
This file contains 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
// A Template for implementing factory method | |
#include <iostream> | |
using namespace std; | |
// Declare the available types that can be passed to the factory | |
enum robotType {R_Bipedal, R_Drone, R_Rover}; | |
// Superclass | |
class Robot{ |
This file contains 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
// A Template for implementing singleton design pattern. | |
class Singleton | |
{ | |
public: | |
int getX(){ return var_x;} | |
int getY(){ return var_y;} | |
void setX(int x){ var_x = x;} | |
void setY(int y){ var_y = y;} | |
static Singleton *instance(){ |
This file contains 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
// more bitwise manipulations | |
#include <iostream> | |
using namespace std; | |
void set(int &num, int pos); | |
void toggle(int &num, int pos); | |
void unset(int &num, int pos); | |
void cudi(); |
This file contains 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
// some bitwise operations | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main() { | |
unsigned char a = 5; | |
unsigned char b = 9; | |
printf("a= %d, b= %d\n", a, b); | |
printf("binary a= 00000101, b= 00001001\n"); |
This file contains 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
import random | |
def quickSort(iList): | |
print("ALL", iList) | |
if len(iList) <= 1: | |
return iList | |
else: | |
left = quickSort([x for x in iList[1:] if x<iList[0]]) | |
middle = [iList[0]] |
This file contains 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
# simple bubble sort implementation | |
import random | |
def bubbleSort(iList): | |
for i in range(len(iList)): | |
try: | |
if iList[i] > iList[i+1]: | |
tmp = iList[i] | |
iList[i] = iList[i+1] |
This file contains 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
# Simple merge sort implementation | |
# reference: http://interactivepython.org/courselib/static/pythonds/SortSearch/TheMergeSort.html | |
import random | |
def mergeSort(iList): | |
if len(iList) > 1: | |
mid = len(iList) // 2 | |
lList = iList[:mid] | |
rList = iList[mid:] |
This file contains 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
# Brute implementation attempt of Merge Sort algorithm from the scratch | |
from math import ceil | |
import random | |
def divide(ListofLists): | |
newList = list() | |
for i in range(len(ListofLists)): | |
if len(ListofLists[i]) > 2: | |
tmp = ListofLists[i] |