Skip to content

Instantly share code, notes, and snippets.

View codeliger's full-sized avatar

Ben codeliger

  • Canada
View GitHub Profile
items = range(0,10001)
def iter_group(iterable, batch_size:int):
iterable_type = type(iterable)
length = len(iterable)
start = batch_size*-1
end = 0
while(end < length):
start += batch_size
end += batch_size
seconds_verb = (
(29030400,'year'),
(2419200,'month'),
(604800,'week'),
(86400,'day'),
(3600,'hour'),
(60,'minute'),
(1,'second')
)
{
"breadcrumbs.enabled": true,
"debug.inlineValues": true,
"editor.cursorWidth": 0,
"editor.fontFamily": "Roboto Mono",
"editor.fontLigatures": true,
"editor.lineHeight": 30,
"editor.minimap.enabled": true,
"editor.multiCursorModifier": "alt",
"editor.renderWhitespace": "none",
from PIL import Image
import os
thumbnails = [
'D:\\preview\\chunks\\chunk_1534553190947880169_2_a.jpg',
'D:\\preview\\chunks\\chunk_1534553245644680292_13_a.jpg',
'D:\\preview\\chunks\\chunk_1534553646530284521_150_a.jpg',
'D:\\preview\\chunks\\chunk_1534553786142238979_199_a.jpg',
'D:\\preview\\chunks\\chunk_1534553810117674683_209_a.jpg',
'D:\\preview\\chunks\\chunk_1534554004357423981_277_a.jpg'
@codeliger
codeliger / asyncio.py
Last active May 19, 2018 04:56
An example showing how asyncio shares timing in an event loop.
import asyncio
import functools
STATE = 0
async def count_to_10(loop,future):
for i in range(1,11):
print('#1 : {}'.format(i))
await asyncio.sleep(1)
future.set_result(0)
@codeliger
codeliger / upgrade_all.pip.py
Created May 19, 2018 02:06
Upgrades all pip packages
import subprocess
import json
CMD_LIST = 'pip list --outdated --format json'
CMD_UPDATE = 'pip install --upgrade {}'
result = subprocess.run(CMD_LIST.split(),stdout=subprocess.PIPE)
packages = json.loads(result.stdout)
@codeliger
codeliger / gameoflife.py
Created May 17, 2018 13:45
An object oriented attempt at game of life
import sys
'''
Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
Any live cell with two or three live neighbours lives on to the next generation.
Any live cell with more than three live neighbours dies, as if by overpopulation.
Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
'''
class Cell:
@codeliger
codeliger / recorder.py
Created May 17, 2018 13:44
NOT WORKING - JUST A DEMO
import sys, os
import json
import asyncio, aiohttp
from time import time
PLAYLIST_RETRIEVAL_FREQUENCY = 1
BASE_PATH = os.path.join('.','broadcasts')
async def request_and_save_chunk(loop:asyncio.AbstractEventLoop,session:aiohttp.ClientSession,server_url,chunk_name,broadcast_id):
chunk_path = os.path.join(BASE_PATH,broadcast_id,chunk_name)
import sys
import requests
import json
import asyncio, aiohttp
from async_timeout import timeout
from timeit import default_timer as timer
import multiprocessing
import os
from urllib.parse import urljoin
import logging
import json
import requests
import sys
import os
import multiprocessing
from PIL import Image
from math import ceil
import logging
logging.basicConfig()