Skip to content

Instantly share code, notes, and snippets.

View Clivern's full-sized avatar

Ahmed Clivern

View GitHub Profile
@Clivern
Clivern / kafka.sh
Last active February 18, 2021 15:26
Run Kafka
#!/bin/bash
git clone https://github.com/wurstmeister/kafka-docker.git
cd kafka-docker
# Update KAFKA_ADVERTISED_HOST_NAME inside 'docker-compose.yml',
# For example, set it to 172.17.0.1
vim docker-compose.yml
docker-compose up -d
@Clivern
Clivern / ruby.py
Last active October 23, 2021 20:33
Beginning Ruby From Novice to Professional Book
# Basic Syntax
x = 1
y = "Hello"
BEGIN {
puts "Start the thing"
}
END {
puts "End the thing"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Clivern
Clivern / python_lists.py
Created March 21, 2021 18:37
Python Lists
import bisect
from heapq import *
class Lists():
def __init__(self, elem):
self.elem = elem
def append(self, x):
@Clivern
Clivern / python_queue.py
Created March 21, 2021 18:38
Python Queue
class Queue():
def __init__(self):
self.queue = []
def enqueueCharacter(self, char):
self.queue.insert(0, char)
def dequeueCharacter(self):
return self.queue.pop()
@Clivern
Clivern / python_stack.py
Created March 21, 2021 18:38
Python Stack
class Stack():
def __init__(self):
self.stack = []
def pushCharacter(self, char):
self.stack.append(char)
def popCharacter(self):
return self.stack.pop()
@Clivern
Clivern / python_heap.py
Created March 21, 2021 18:40
Python Heap
from heapq import *
class Heap():
def __init__(self):
self.heap = []
def heappush(self, item):
"""Push the value item onto the heap, maintaining the heap invariant."""
heappush(self.heap, item)
@Clivern
Clivern / python_tuple.py
Created March 21, 2021 18:40
Python Tuple
"""
A tuple is similar to a list. The difference between the two is that we cannot change the elements of a tuple once
it is assigned whereas in a list, elements can be changed.
- We generally use tuple for heterogeneous (different) datatypes and list for homogeneous (similar) datatypes.
- Since tuple are immutable, iterating through tuple is faster than with list. So there is a slight performance boost.
- Tuples that contain immutable elements can be used as key for a dictionary. With list, this is not possible.
- If you have data that doesn't change, implementing it as tuple will guarantee that it remains write-protected.
https://www.programiz.com/python-programming/tuple
@Clivern
Clivern / python_dict.py
Created March 21, 2021 18:41
Python Dicts
class Dicts():
def __init__(self, elem):
self.elem = elem
def len(self):
return len(self.elem)
def keys(self):
return self.elem.keys()
@Clivern
Clivern / python_strings.py
Created March 21, 2021 18:41
Python Strings
"""
Strings are immutable sequence of characters
http://thomas-cokelaer.info/tutorials/python/strings.html
https://docs.python.org/3/library/stdtypes.html#string-methods
"""
class Strings():
def __init__(self, elem):
self.elem = elem