Skip to content

Instantly share code, notes, and snippets.

View oguzalb's full-sized avatar
💭
Githubsızlar!

oguzalb

💭
Githubsızlar!
  • Booking.com
  • Amsterdam, Netherlands
View GitHub Profile
@oguzalb
oguzalb / arrowfunc.patch
Created July 21, 2023 14:08
adding arrow functions to Python grammar
diff --git a/Grammar/Tokens b/Grammar/Tokens
index 618ae81..29bcfeb 100644
--- a/Grammar/Tokens
+++ b/Grammar/Tokens
@@ -11,6 +11,7 @@ RPAR ')'
LSQB '['
RSQB ']'
COLON ':'
+FUNC_SIGN '=>'
COMMA ','
import httpx
content = httpx.get("https://philosophy-quotes-api.glitch.me/quotes/author/Rumi")
quotes = content.json()
print(quotes)
from string import ascii_letters
name_letters = ascii_letters + "_"
NAME_CASES = [("some_name", "some_name"), ("some ", "some"), ("some}", "some")]
def tokenize_name(text, i):
generator1 = (a for a in [1, 2, 3, 4])
generator2 = (a for a in [1, 2, 3])
for x1, x2 in zip(generator1, generator2):
print(x1, x2)
remainder = next(generator1)
@oguzalb
oguzalb / interpret.py
Created April 17, 2020 13:28
A simple stack machine implementation for Python in Python
import dis
# Run this with python3 : )
class VM:
def __init__(self):
self.stack = []
def push(self, value):
self.stack.append(value)
def pop(self):
return self.stack.pop()
import random
def put_mines(m, n, minecount):
flat_area = ["*"]*minecount + [0]*((m*n)-minecount)
random.shuffle(flat_area)
return [
flat_area[i:i+n]
for i in range(0, m*n-n+1, n)
]
@oguzalb
oguzalb / gist:6e2a5b4f3ba0024ca2e1973efd41fc20
Last active August 30, 2017 08:22
map function javascript?!?
# Python
>>> map(int, ['10', '20', '30'])
[10, 20, 30]
# Clojure
user=> (map #(Integer/parseInt %) (list "10", "20", "30"))
(10 20 30)
# Scala
scala> Array("10", "20", "30").map(Integer.parseInt)