Skip to content

Instantly share code, notes, and snippets.

View alairock's full-sized avatar

Skyler Lewis alairock

View GitHub Profile
@alairock
alairock / lastfm_cleaner.py
Last active December 20, 2023 04:07
Clean out comedians from lastfm
import pylast
import secretstorage
import requests
from pycookiecheat import chrome_cookies
##########
# CONFIG #
##########
# You have to have your own unique two values for API_KEY and API_SECRET
# Obtain yours from https://www.last.fm/api/account/create for Last.fm
@alairock
alairock / block.py
Created January 7, 2019 02:46
Simple Python Decentralized Ledger
import hashlib as hasher
class Block:
def __init__(self, index, timestamp, data, previous_hash):
self.index = index
self.timestamp = timestamp
self.data = data
self.previous_hash = previous_hash
self.hash = self.hash_block()
import time
# Everyone in queue, and their desired order
customers = [('Bob', 'Ham Sandwich'), ('Paul', 'Grilled Cheese'), ('Sally', 'Chicken Croissant')]
# make a sandwich, but pause(yield) to deliver it
def make_sandwiches():
for customer in customers:
time.sleep(1) # making the sandwich for our customer
def employees():
for y in ['Bob', 'Sally', 'Jake']:
yield y
def customers():
for ex in ['James', 'Ted', 'Kent']:
yield ex
def retrieve_all_users():
yield from employees()
@alairock
alairock / generatory_pipe_hard.py
Created July 30, 2018 22:57
Generator pipelining hard
def employees():
for y in ['Bob', 'Sally', 'Jake']:
yield y
def customers():
for ex in ['James', 'Ted', 'Kent']:
yield ex
def retrieve_all_users():
for employee in employees():
def make_sandwich():
customer = yield 'No Customer'
print(customer)
action = make_sandwich()
print(next(action))
print(action.send(13))
@alairock
alairock / generatory_next.py
Last active July 31, 2018 16:19
Generator Next
import time
def make_sandwich(customers):
for customer in customers:
time.sleep(1) # let's pretend this is the time it takes to make the sandwich
yield customer
maker = make_sandwich(['Bob', 'Paul', 'Sally'])
print('Just made a sandwich for:', next(maker))
@alairock
alairock / generators-yield.py
Last active August 14, 2018 16:58
Generators Yield
import time
# As people enter the queue, take their order, but pause(yield) to make their sandwich
def get_next_customer():
# people are going to be adding themselves to this queue and it will grow quickly
list_of_customers = [('Bob', 'Ham Sandwich'), ('Paul', 'Grilled Cheese'), ('Sally', 'Chicken Croissant')]
for an_order in list_of_customers:
yield an_order
@alairock
alairock / generators_heavy.py
Last active August 3, 2018 17:06
Generators
import time
# Everyone in queue, and their desired order
def get_customers():
return [('Bob', 'Ham Sandwich'), ('Paul', 'Grilled Cheese'), ('Sally', 'Chicken Croissant')]
customers = get_customers()
# make the sandwiches for all the customers, then deliver
headers = {
"Rest-Impersonate-User": userid,
"Rest-User-Token": "XXXXXXXXXXXXXXXXXXXXXXX",
}
try:
json = {
'ThreadId': thread_id,
'ForumId': 21,
'Body': data['raw'],
'PostDate': data['created_at'].strftime("%Y-%m-%d %H:%M:%S")