Skip to content

Instantly share code, notes, and snippets.

View scriptpapi's full-sized avatar
🎯
Focusing

Nawaf Abdullah scriptpapi

🎯
Focusing
  • Dubai, United Arab Emirates
View GitHub Profile
@scriptpapi
scriptpapi / write2txt.cs
Created December 27, 2018 09:52
C# write to text file
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"))
@scriptpapi
scriptpapi / alarm.py
Created August 24, 2018 11:15
python timer alarm script using multiprocessing
from multiprocessing import Process
import time
class TimeoutException(Exception):
pass
timer = 5
def start_timer():
time.sleep(timer)
raise TimeoutException
@scriptpapi
scriptpapi / factoryPattern.cpp
Created May 25, 2018 23:20
A Template for implementing factory method in C++
// 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{
@scriptpapi
scriptpapi / singletonPattern.cpp
Created May 24, 2018 21:29
Singleton design pattern template
// 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(){
@scriptpapi
scriptpapi / bitwiseOps2.cpp
Created May 23, 2018 22:34
more bitwise manipulations
// 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();
@scriptpapi
scriptpapi / bitwiseOps.c
Created May 23, 2018 21:29
basic bitwise operations
// 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");
@scriptpapi
scriptpapi / quicksort.py
Last active May 23, 2018 17:23 — forked from bcambel/quicksort.py
Simple quick sort implementation
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]]
@scriptpapi
scriptpapi / bubbleSort.py
Created May 22, 2018 22:49
simple bubble sort algorithm implementation
# 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]
@scriptpapi
scriptpapi / mergeSort.py
Created May 22, 2018 22:26
Simple merge sort implementation
# 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:]
@scriptpapi
scriptpapi / bruteMerge.py
Last active May 22, 2018 18:39
Brute implementation attempt of Merge Sort algorithm from the scratch
# 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]