Skip to content

Instantly share code, notes, and snippets.

@PackmanDude
PackmanDude / update_proton.sh
Last active January 4, 2024 12:55 — forked from usrtrv/update_proton.sh
Update every game's proton version.
#!/bin/sh
set -eu
steam_dir="$HOME/.steam"
proton=
list=false
eval set -- "$(getopt -o d:p:l -l directory,proton,list -- "$@")"
while true; do
#!/usr/bin/env python3
import socket
import uuid
import paho.mqtt.client as mqtt
import trio
client_id = 'paho-mqtt-python/issue72/' + str(uuid.uuid4())
topic = client_id
print("Using client_id / topic: " + client_id)
@nickdavies
nickdavies / runners.py
Created June 11, 2019 17:55
Python 3.6 version of asyncio.runners
"""
Backport of the asyncio.runners module from Python 3.7.
"""
# Source:
# https://github.com/python/cpython/blob/a4afcdfa55ddffa4b9ae3b0cf101628c7bff4102/Lib/asyncio/runners.py
# Modifications:
# * removed relative imports of .coroutines, .events, .tasks
# * replaced `coroutines`, `events`, `tasks` with `asyncio`.
# * replaced `tasks.all_tasks` with `asyncio.Task.all_tasks` because it is
@natedileas
natedileas / redirect.py
Last active May 7, 2024 06:10
c-level stdout redirection on windows
""" Tested on Windows 10, 64 bit, Python 3.6
Sources:
https://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/
https://stackoverflow.com/questions/17942874/stdout-redirection-with-ctypes
"""
from contextlib import contextmanager
import ctypes
import io
import os, sys
@ValentinFunk
ValentinFunk / NetlifyServerPushPlugin.js
Last active May 4, 2024 04:24
Webpack - Generate Netlify HTTP2 Server Push _headers File when using the HtmlWebpackPlugin
/**
* Generate a Netlify HTTP2 Server Push configuration.
*
* Options:
* - headersFile {string} path to the _headers file that should be generated (relative to your output dir)
*/
function NetlifyServerPushPlugin(options) {
this.options = options;
}
@fokusferit
fokusferit / enzyme_render_diffs.md
Last active June 18, 2024 11:27
Difference between Shallow, Mount and render of Enzyme

Shallow

Real unit test (isolation, no children render)

Simple shallow

Calls:

  • constructor
  • render
@mweststrate
mweststrate / mobx-webcomponent.html
Last active January 22, 2024 08:25
MobX + webcomponents
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/mobx@2.6.0/lib/mobx.umd.js"></script>
<script>
var MobxDemo = Object.create(HTMLElement.prototype);
MobxDemo.attachedCallback = function() {
var state = mobx.observable({
counter : parseInt(this.getAttribute("counter"))
})
"""
twisted async/await with asyncio reactor and uvloop
"""
import asyncio
import uvloop
from asyncio.tasks import ensure_future
try:
# as per github source the asyncio reactor is intended to be released in future version
@joshlk
joshlk / faster_toPandas.py
Last active May 15, 2023 13:48
PySpark faster toPandas using mapPartitions
import pandas as pd
def _map_to_pandas(rdds):
""" Needs to be here due to pickling issues """
return [pd.DataFrame(list(rdds))]
def toPandas(df, n_partitions=None):
"""
Returns the contents of `df` as a local `pandas.DataFrame` in a speedy fashion. The DataFrame is
repartitioned if `n_partitions` is passed.
@kgriffs
kgriffs / self-host.py
Created February 5, 2016 18:28
Sample showing how to self-host a Falcon app
import falcon
app = falcon.API()
if __name__ == '__main__':
from wsgiref.simple_server import make_server
server = make_server('localhost', 8000, app)
print("Listening on localhost:8000")
server.serve_forever()