This file contains hidden or 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 | |
| from bs4 import BeautifulSoup | |
| def scrape(max_visits=10_000): | |
| seed, articles, visited = ['www.malaymail.com'], [], [] | |
| for _ in range(max_visits): | |
| if not seed: | |
| break | |
| link = seed.pop(0) |
This file contains hidden or 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
| """ | |
| Simple implementation of a finite state machine. | |
| Author: Tang U-Liang | |
| Date: 2 Oct 2020 | |
| """ | |
| import attr | |
| from enum import Enum | |
| import inspect |
This file contains hidden or 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 types import MethodType | |
| class FunctionWrapper: | |
| def __init__(self, func): | |
| self.func = func | |
| def __get__(self, obj, objtype=None): | |
| if obj is None: | |
| return self.func |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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, Dict, Union | |
| from spacy.tokens import Doc, Token | |
| from spacy.matcher import Matcher | |
| from srsly import read_json | |
| class FilterTextPreprocessing: | |
| def __init__(self, nlp, | |
| patterns: List[Dict[str, Union[str, List[Dict]]]]) : | |
| Doc.set_extension('bow', default=[]) |
This file contains hidden or 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
| """ | |
| Implementation of a simple currying decorator | |
| """ | |
| from inspect import signature | |
| def curry(f) : | |
| def wrapper(*args, **kwds) : | |
| sig = signature(f) | |
| ba = sig.bind_partial(*args, **kwds) |
This file contains hidden or 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
| def gcd(m,n) : | |
| m,n = sorted(abs(x) for x in (m,n)) | |
| while m: | |
| m, n = n % m, m | |
| return n | |
| def ord(x, p) : | |
| return p // gcd(x,p) | |
| for i in range(1, 101) : |
This file contains hidden or 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
| for i in range(1, 100) : | |
| if not any(i%5, i%3) : | |
| print("FizzBuzz") | |
| elif not bool(i%5) : | |
| print("Buzz") | |
| elif not bool(i%3) : | |
| print("Fizz") | |
| else: | |
| print(i) | |
This file contains hidden or 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
| const Application = Machine({ | |
| id: 'app', | |
| initial: 'ready', | |
| states: { | |
| ready: { | |
| initial: 'ok', | |
| on: { | |
| NewGame: "characterCreation", | |
| LoadGame: 'loadCharacter' | |
| }, |
This file contains hidden or 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
| // Available variables: | |
| // - Machine | |
| // - interpret | |
| // - assign | |
| // - send | |
| // - sendParent | |
| // - spawn | |
| // - raise | |
| // - actions |
NewerOlder