Skip to content

Instantly share code, notes, and snippets.

View scalactic's full-sized avatar

scalactic scalactic

  • Apple Inc.
View GitHub Profile
@scalactic
scalactic / base64_encoder_decoder.scala
Created June 28, 2021 13:21
Scala base64 encoder decoder
// Base64 encode
new String(java.util.Base64.getEncoder.encode("hello".getBytes()),java.nio.charset.StandardCharsets.UTF_8)
// Base64 decode
new String(java.util.Base64.getDecoder.decode("aGVsbG8=".getBytes()),java.nio.charset.StandardCharsets.UTF_8)
@scalactic
scalactic / python-multiprocessing-multiple-queue.py
Created June 26, 2021 19:33
Python multiprocessing multiple queue implementation
from multiprocessing import Pool, Process, Manager
import time
import logging
import os
logging.basicConfig(level=logging.INFO, format='[%(levelname)s] [%(asctime)s] [%(process)s] %(message)s', datefmt='%d/%m/%Y %I:%M:%S %p')
def writer(queue):
@scalactic
scalactic / python-process-return-value.py
Last active June 26, 2021 19:24
Getting python process return value
from multiprocessing import Process, Value
def func(val):
val.value = val.value * 2
return True
if __name__ == '__main__':
val = Value("l", 1, lock=False) # "l" -> typecode_or_type , 1 -> the value.
@scalactic
scalactic / python-multiprocessing-over-queue.py
Last active June 26, 2021 19:25
Python multprocessing implementation over multiprocessing.Queue
from multiprocessing import Pool, Process, Manager
import time
def writer(queue):
""" Queue writer worker """
# Produce data into the queue
for i in range(10000):
t = time.time()
print({'message': i, 'time': t, 'queue_size': queue.qsize()})