Skip to content

Instantly share code, notes, and snippets.

View yozx's full-sized avatar
🎀
Duck Typing

Z yozx

🎀
Duck Typing
View GitHub Profile
@mikeyb
mikeyb / beam_solo_mining.md
Last active January 15, 2020 12:08
BEAM Solo Mining Guide

BEAM Solo Mining Guide

  • Adapted from Raskul's guide
  • With help from Freshminer (sunpool.top)

Installation

  • From BEAM Downloads download the following
    • beam-wallet-cli
    • beam-node
  • Extract downloads into a folder called beam-mining
@yozx
yozx / bitly_shorten_app.py
Created July 12, 2020 18:11
bitly_shorten_async
# Non-blocking script for shorten link via https://bit.ly Api
import asyncio
import logging
from typing import Dict, Optional
from aiohttp import ClientSession
logger = logging.getLogger('bitly_app')
@thehesiod
thehesiod / async_worker_pool.py
Last active June 30, 2023 11:01
Asynchronous Worker Pool, allows for limiting number of concurrent tasks
import asyncio
from datetime import datetime, timezone
import os
def utc_now():
# utcnow returns a naive datetime, so we have to set the timezone manually <sigh>
return datetime.utcnow().replace(tzinfo=timezone.utc)
class Terminator:
pass
@fonylew
fonylew / install-local-server.sh
Last active August 31, 2023 12:50
A bunch of script to install Nvidia with CUDA10, CUDNN 7.4 and so on.
#!/bin/bash
# First sudo command
sudo whoami
# Update and upgrade
sudo apt update
sudo apt upgrade -y
# Utility
@TariqAHassan
TariqAHassan / PandasConcatWorkaround.adoc
Last active November 6, 2023 22:57
Fast Alternative to pd.concat() for row-wise concatenation

Pandas DataFrames are fantastic. However, concatenating them using standard approaches, such as pandas.concat(), can be very slow with large dataframes. This is a work around for that problem.

Note: this approach assumes that: (a) the goal is a row-wise concatenation (i.e., axis=0) and (b) all dataframes share the same column names.

If these assumptions are not met, this approach could still work…​but it will likely need to be modified.

@bogdan-kulynych
bogdan-kulynych / install-cuda-10-bionic.sh
Last active December 5, 2023 10:26
Install CUDA 10 on Ubuntu 18.04
# WARNING: These steps seem to not work anymore!
#!/bin/bash
# Purge existign CUDA first
sudo apt --purge remove "cublas*" "cuda*"
sudo apt --purge remove "nvidia*"
# Install CUDA Toolkit 10
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
@hest
hest / gist:8798884
Created February 4, 2014 06:08
Fast SQLAlchemy counting (avoid query.count() subquery)
def get_count(q):
count_q = q.statement.with_only_columns([func.count()]).order_by(None)
count = q.session.execute(count_q).scalar()
return count
q = session.query(TestModel).filter(...).order_by(...)
# Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ...
print q.count()
@IanHopkinson
IanHopkinson / lxml_examples.py
Created November 24, 2015 19:42
Examples of xpath queries using lxml in python
#!/usr/bin/env python
# encoding: utf-8
import lxml.etree
import lxml.html
import requests
xml_sample = """<?xml version="1.0" encoding="UTF-8"?>
<foo:Results xmlns:foo="http://www.foo.com" xmlns="http://www.bah.com">
<foo:Recordset setCount="2">
@lars-tiede
lars-tiede / asyncio_loops.py
Last active April 3, 2024 15:28
asyncio + multithreading: one asyncio event loop per thread
import asyncio
import threading
import random
def thr(i):
# we need to create a new loop for the thread, and set it as the 'default'
# loop that will be returned by calls to asyncio.get_event_loop() from this
# thread.
loop = asyncio.new_event_loop()
@stefansundin
stefansundin / requests_api.py
Last active April 11, 2024 16:23
Reusable class for Python requests library.
# http://docs.python-requests.org/en/master/api/
import requests
class RequestsApi:
def __init__(self, base_url, **kwargs):
self.base_url = base_url
self.session = requests.Session()
for arg in kwargs:
if isinstance(kwargs[arg], dict):
kwargs[arg] = self.__deep_merge(getattr(self.session, arg), kwargs[arg])