Skip to content

Instantly share code, notes, and snippets.

View khaled0fares's full-sized avatar

Khaled Fares khaled0fares

  • Egypt
View GitHub Profile
@khaled0fares
khaled0fares / static.js
Created August 18, 2017 06:25
simple static handler in nodejs
const http = require('http')
const fs = require('fs')
const mime = require('mime')
const server = http.createServer().listen(3000)
server.on('request', (req, res)=>{
const filePath = __dirname + req.url
fs.stat(filePath, (err, stat)=>{
body {
}
.slider{
margin: auto;
width: 400px;
overflow: hidden;
position: relative;
}
@khaled0fares
khaled0fares / txtToVim.js
Created April 29, 2017 22:59
changing files extensions from txt to vim included in a directory
const fs = require('fs')
const txtFetcherInDir = (dirname, callback)=>{
fs.readdir(dirname, (err, files) => {
if (err) throw err;
const endWithtxt= files.filter((file)=>{
const lastDot = file.lastIndexOf('.') + 1
return file.substring(lastDot) === 'txt'
})
callback(endWithtxt)
const createStudentCalsses = function(...classes){
console.log(classes.length)
if(classes[0].length < 1) throw new Error("You should enroll in at least two classes")
const privateObj = {}
privateObj.classes = classes;
const studentClasses = {
getClasses(){ return privateObj.classes}
const net = require('net')
const tcp = net.createServer()
tcp.maxConnections = 2
const notTheSame = (sender, receiver) => sender !== receiver
const messageOthers = (sockets,sender,callback)=>{
sockets.forEach((receiver,i)=>{
@khaled0fares
khaled0fares / bst.js
Last active October 2, 2016 13:32
Binary Search Tree in js
class NodeTree{
constructor(data, leftNode, rightNode){
this.data = data;
this.leftNode = leftNode;
this.rightNode = rightNode;
}
display(){
return this.data
}
@khaled0fares
khaled0fares / set.js
Created September 18, 2016 14:46
Set data structure
class Set{
constructor(){
this.data = new Array();
}
_exist(ele){
return this.data.indexOf(ele) >= 0
}
add(ele){
@khaled0fares
khaled0fares / hashtable.js
Last active September 17, 2016 20:26
Hash table implementation in JS
let LinkedList = require('./linked_list');
class HashTable{
constructor(size){
this.table = new Array(size);
}
_setup(key, index,head){
let obj = {};
obj[key] = head;
@khaled0fares
khaled0fares / dictionary.js
Last active September 14, 2016 11:59
Dictionary class in es6 with text compression demo.
class Dictionary{
constructor(){
this.data = new Array();
}
add(key, val){
this.data[key] = val;
}
remove(key){
@khaled0fares
khaled0fares / linked_list.js
Last active September 23, 2016 14:36
Singly Linked List implementation in JavaScript using ES2015 syntax
class Node{
constructor(val){
this.val = val;
this.next = null
}
}
class LinkedList{
constructor(valOfHead){