Skip to content

Instantly share code, notes, and snippets.

View prettyirrelevant's full-sized avatar
💭
???

Isaac Adewumi prettyirrelevant

💭
???
View GitHub Profile
@prettyirrelevant
prettyirrelevant / clean_html.py
Created November 24, 2020 14:38
a python script to clean an input of html and return just text
class ParseHTML(HTMLParser):
def __init__(self):
super().__init__()
self.reset()
self.strict = False
self.convert_charrefs = True
self.text = StringIO()
def handle_data(self, d):
self.text.write(d)
@prettyirrelevant
prettyirrelevant / time_to_read.py
Created November 24, 2020 14:39
a python script that calculates the time it'll take to read a given text( i think it's buggy)
def get_time_to_read(text: str):
striped_text = strip_tags(text)
word_cleaned = re.sub(r" /[^\w ]/g", "", striped_text)
word_count = len(word_cleaned.split(" "))
reading_time = math.floor(word_count / 200)
if reading_time <= 1:
return f"{str(reading_time)} min"
else:
return f"{str(reading_time)} mins"
@prettyirrelevant
prettyirrelevant / trix_attach.js
Created November 24, 2020 14:42
my version of trix editor attachment.js
(function () {
const HOST = "/path/to/url/";
addEventListener("trix-attachment-add", function (event) {
if (event.attachment.file) {
event.attachment.file
uploadFileAttachment(event.attachment)
}
})
@prettyirrelevant
prettyirrelevant / zlib_scraper.py
Last active January 28, 2021 18:17
A script that scrapes b-ok.africa for books
import requests
from bs4 import BeautifulSoup
Z_LIB = "https://b-ok.africa"
def scrape_zlib(query):
response = []
url = f"{Z_LIB}/s/{query}"
page = requests.get(url)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@prettyirrelevant
prettyirrelevant / logger.ts
Created March 18, 2021 01:23
Express JS Logging Boilerplate
import morgan, { StreamOptions } from "morgan";
import winston from "winston";
const levels = {
error: 0,
warn: 1,
info: 2,
debug: 3,
};
@prettyirrelevant
prettyirrelevant / app.py
Last active December 6, 2024 02:55
Using Huey with Flask using application factory. For configuration, follow the djhuey format
# Due to the flexible nature of Flask. This might be __init__.py
from .extensions import huey
def create_app():
app = Flask(__name__)
# add your configurations
# app.config.from_object("settings.local")
huey.init_app(app)
def save_image_from_b64(b64_image):
file_name = secrets.token_hex(6)
file_data = b64_image.split(",")[-1].encode()
file_type = b64_image.split(",")[0].split(";")[0].split("/")[-1] or "png"
with open("{}/{}.{}".format(app.config["UPLOAD_FOLDER"], file_name, file_type), "wb") as f:
f.write(base64.decodebytes(file_data))
return "{}.{}".format(file_name, file_type)
@prettyirrelevant
prettyirrelevant / contracts...BallotWithModifier.sol
Created March 1, 2022 13:11
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.26+commit.4563c3fc.js&optimize=false&runs=200&gist=
pragma solidity ^0.4.0;
contract Ballot {
struct Voter {
uint weight;
bool voted;
uint8 vote;
address delegate;
}
package main
import (
"errors"
"fmt"
)
type KeyValueSlice map[string]float64
func main() {