This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List, Tuple | |
from pprint import pprint | |
import random | |
def empty_slots(board: List[List[int]]) -> List[Tuple[int, int]]: | |
result = [(x//8, x%8) for x in range(64)] | |
for i, row in enumerate(board): | |
for j, slot in enumerate(row): | |
if slot != 0: | |
for k in range(8): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code by Farooq Karimi Zadeh under MIT/X11 | |
import random | |
from typing import List, Tuple | |
Fitness = float | |
class Chromosome: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# By Farooq Karimi Zadeh under CC0. | |
import wave | |
import struct | |
from dataclasses import dataclass | |
from typing import List | |
@dataclass | |
class SoundClip16b: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code by Rust beginner, Farooq Karimi Zadeh | |
// Under CC0 1.0 | |
// Warning! Code might not be idiomatic | |
fn main() { | |
let mut bin_matrix = [ | |
[0, 1, 0, 0], | |
[1, 0, 1, 0], | |
[0, 0, 0, 1], | |
[0, 0, 0, 0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Warshall algorithm | |
This calculates transitive closure for a given binary matrix | |
Author: Farooq Karimi Zadeh | |
Code is under CC0 1.0 | |
""" | |
from pprint import pprint | |
def pretty_print_matrix(matrix): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Customer: | |
account = Account() | |
name = "Far the chickenkiller" | |
... | |
class Account: | |
no = ... # some big integer | |
rials = 10000 # 1000 toman | |
dollars = 1.0 # one dollar only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code by Farooq Karimi Zadeh <[email protected]> | |
# Under CC0 1.0 | |
from html.parser import HTMLParser | |
class MyParser(HTMLParser): | |
def handle_starttag(self, tag, attrs): | |
attrs = dict(attrs) | |
if tag == "img": | |
src = attrs["src"] if "src" in attrs else "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import requests | |
import networkx as nx | |
import pygraphviz as pgv | |
MAX_DEPTH = 3 | |
ADDR_PATTERN = re.compile("[a-zA-Z0-9\-]+\.blog\.ir", re.M) | |
G = nx.DiGraph() | |
def add_all_links(addr, d=0): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cherrypy # <3 | |
import time | |
class Time: | |
@cherrypy.expose | |
@cherrypy.tools.caching(delay=30) | |
def index(self): | |
return time.ctime(time.time()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code is by Farooq Karimi Zadeh | |
# and it is under CC0 which means | |
# Public Domain and no copyright :) | |
import cherrypy # <3 | |
@cherrypy.tools.register('before_handler') | |
def myauth(): | |
sess = cherrypy.session | |
if sess.get("login?"): | |
return "Mooo" # It should just return, not important what it returns |
NewerOlder