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 os | |
import sys | |
from typing import * | |
def is_prime(n: int) -> bool: | |
if n < 2: | |
return False | |
return all(n % i for i in range(2, int(math.sqrt(n)) + 1)) | |
def get_prime_factors(n: int) -> List[int]: |
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 os | |
import sys | |
from typing import * | |
TaskReturn = NewType("TaskReturn", Union[Any, TaskException]) | |
class TaskException(Exception): | |
pass | |
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 os | |
import sys | |
from typing import * | |
import multiprocessing | |
class Process(multiprocessing.Process): | |
def __init__(self, id: int, task_queue: Iterable, results: Iterable): | |
super(Process, self).__init__() | |
self.id = id | |
self.task_queue = task_queue |
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 os | |
import sys | |
from typing import * | |
import multiprocessing | |
class ProcessManager: | |
def __init__(self): | |
self.task_queue = multiprocessing.JoinableQueue() | |
self.results = multiprocessing.Queue() | |
self.processes = [Process(i, self.task_queue, self.results) for i in range(self.num_cpus())] |
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 os | |
import sys | |
import random | |
from typing import * | |
N_TASKS = 20 | |
UPPER_BOUND = 10e12 | |
LOWER_BOUND = 10e10 | |
def sequential_factorization(): |
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
Type | Timeit Iters | Tasks | Factor Range | Threads | Seconds | CPU Usage | |
---|---|---|---|---|---|---|---|
sequential | 1000 | 10 | 10e5 - 10e8 | 1 | 46 | 100% | |
concurrent | 1000 | 10 | 10e5 - 10e8 | 2 | 57 | 50% | |
sequential | 1000 | 20 | 10e10 - 10e12 | 1 | 816 | 100% | |
concurrent | 1000 | 20 | 10e10 - 10e12 | 2 | 391 | 7% |
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
// app/core/model-builder.js | |
class ModelBuilder { | |
// still using a wrapper function over `defineAttribute`, that | |
// creates default options via instance chanining. this will | |
// reduce boiler plate in the model manager files | |
formAttribute(attr, options) { | |
return this.defineAttribute(attr, options) | |
.certifiable() |
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 Direct: | |
def __init__(self, native_key, foreign_key): | |
""" | |
Represents a direct relationship from one 'native' | |
model, to one 'foreign' model | |
""" | |
self.native_key = native_key | |
self.foreign_key = foreign_key | |
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 peewee import ( | |
BaseModel, | |
ForeignKeyField, | |
TextField, | |
IntegerField, | |
DateTimeField, | |
CharField | |
) | |
from peewee_extensions import ( |
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 peewee_extensions import PeeweeExtensions | |
class BaseManager: | |
def __init__(self, name): | |
self.model_name = name | |
self.exts = PeeweeExtensions(self) | |
self.model = BaseManager.model_for(self.model_name) | |
self.relations = self.model._meta.relations | |
@staticmethod |
OlderNewer