Skip to content

Instantly share code, notes, and snippets.

🔥
flamed

ralston3 ralston3

🔥
flamed
Block or report user

Report or block ralston3

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ralston3
ralston3 / attrs-demo.js
Last active Nov 11, 2019
model attributes rfc
View attrs-demo.js
// 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()
@ralston3
ralston3 / results.csv
Created Nov 5, 2019
Results of sequential vs concurrent compute tasks
View results.csv
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%
@ralston3
ralston3 / main.py
Created Nov 5, 2019
Compare factorization sequentially vs concurrently
View main.py
import os
import sys
import random
from typing import *
N_TASKS = 20
UPPER_BOUND = 10e12
LOWER_BOUND = 10e10
def sequential_factorization():
@ralston3
ralston3 / manager.py
Last active Nov 9, 2019
A process manager used to manage individual processes
View manager.py
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())]
@ralston3
ralston3 / process.py
Created Nov 5, 2019
A task processor abstraction wrapping multiprocessing.Process
View process.py
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
@ralston3
ralston3 / task.py
Created Nov 5, 2019
A concurrent task object
View task.py
import os
import sys
from typing import *
TaskReturn = NewType("TaskReturn", Union[Any, TaskException])
class TaskException(Exception):
pass
@ralston3
ralston3 / prime-factorization.py
Last active Nov 9, 2019
Prime number factorization function
View prime-factorization.py
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]:
You can’t perform that action at this time.