Skip to content

Instantly share code, notes, and snippets.

import re
#the extended version
def multiple_replace(dict, text):
# Create a regular expression from the dictionary keys
regex = re.compile("(%s)" % "|".join(map(re.escape, dict.keys())))
# For each match, look-up corresponding value in dictionary
return regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], text)
@ahmed4end
ahmed4end / nodejs-tcp-example.js
Created July 21, 2019 03:21 — forked from tedmiston/nodejs-tcp-example.js
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
import re, random, sys, time
text = "Hello, World!, this message should be printed in a cool way xD"
def CS_Printing(text): #random, re, sys, time
letters = [chr(i) for i in range(65, 91)] + [chr(i) for i in range(97, 123)]
core = lambda text:re.sub(random.sample(text, len(text))[0], random.choice(letters), text, count=1)
res = [text]
for i in range(len(text) + 5):
for i in range(random.randint(1, 3)):
import re, random, sys, time
text = "Hello, World!, this message should be printed in a cool way xD"
def CS_Printing2(text):
text = list(text)
letters = [chr(i) for i in range(65, 91)] + [chr(i) for i in range(97, 123)]
res = ["".join(text)]
for i in range(len(text)+5):
for i in range(random.randint(0, 3)):
#(0: clear step), (5 or any number other than zero: obstacles)
state = [[0,0,0,0,0],
[0,5,5,5,0],
[0,5,5,5,0],
[0,5,5,5,0],
[0,0,0,0,0]]
def access(state, x, y):
try:return state[x][y]
except:pass
state = [[0 for i in range(50)] for j in range(50)]
import random
def access(state, x, y):
try:return state[x][y]
except:pass
neighbours = lambda x, ngrid=len(state):list(filter(lambda x:x is not False,map(lambda x:x if 0<=x[0]<=ngrid-1 and x[1]>=0 and access(state, x[0], x[1]) == 0 else False, random.sample([(x[0],x[1]-1),(x[0]-1,x[1]),(x[0],x[1]+1),(x[0]+1,x[1])], 4))))
@ahmed4end
ahmed4end / Prose.md
Created November 4, 2019 09:19 — forked from shakna-israel/Prose.md
Obfuscating Python

Obfuscating Python

Obfuscation isn't difficult in most programming languages. It's why we have "good practices" because it is so easy to hide what you mean in badly written code.

Obfuscation tends to be even easier in dynamic languages because of how forgiving they tend to be - and because they tend to give you direct access to the environment so that you can manipulate it.

Today, for fun, I'm going to obfuscate this code:

def _(n):

if n <= 0:

@ahmed4end
ahmed4end / Caesar-cipher.py
Created January 16, 2020 06:03
one line python code to encode text in (Caesar cipher).
print("".join([(lambda i:[chr(i) for i in range(97,123)][(ord(i)%97+3)%26] if i != " " else " ")(i) for i in "i love being alone"]))
@ahmed4end
ahmed4end / format.py
Created January 31, 2020 21:29
print beautiful format.
methods = [i for i in dir(str) if not i[0]=="_"]
for i in zip(*[iter(methods)]*4):
print("{:15}{:^15}{:^15}{:>15}".format(*i))
mat = {}
for i in range(5):
for j in range(5):
print((i,j), j+i*5)