Skip to content

Instantly share code, notes, and snippets.

View Xion's full-sized avatar

Karol Kuczmarski Xion

View GitHub Profile
@Xion
Xion / deprecated.py
Created May 26, 2013 11:49
@deprecated decorator for Python classes
import functools
import inspect
import os
import warnings
class _DeprecatedDecorator(object):
MESSAGE = "%s is @deprecated"
def __call__(self, symbol):
@Xion
Xion / split.py
Last active December 22, 2021 23:45
split() for general iterables
import inspect
def split(iterable, by):
"""Generalized split function that works on any iterable."""
separator = by if inspect.isfunction(by) else lambda x: x == by
res = []
curr = []
for elem in iterable:
if separator(elem):
@Xion
Xion / l.py
Last active December 22, 2021 23:45
Chained list operations in Python
class L(object):
def __init__(self, iterable):
self.value = iterable
def map(self, fn):
self.value = map(fn, self.value)
return self
def join(self, s):
self.value = s.join(self.value)
return self
@Xion
Xion / missing_dict.py
Created April 5, 2012 21:49
dict with "missing" values
import collections
missing = object()
class MissingDict(dict):
"""Dictionary that supports a special 'missing' value.
Assigning a missing value to key will remove the key from dictionary.
Initializing a key with missing value will result in key not being
added to dictionary at all.
@Xion
Xion / compact.py
Created November 13, 2011 18:12
PHP compact() function in Python
def compact(*args):
''' compact() function, analoguous to the PHP version.
Converts a series of (possible nested) iterables containing variable names
into a dictionary mapping those names to variable values.
Example:
>>> x, y, z, a, b, c = 1, 2, 3, 4, 5, 6
>>> compact('x', ['y','z'], ['a', ['b'], [['c']]])
{'a': 4, 'b': 5, 'c': 6, 'x': 1, 'y': 2, 'z': 3}
'''
def _compact_arg(res, arg):
@Xion
Xion / keyword_stats.py
Created May 28, 2012 16:39
Analysis of keywords in few popular languages
"""
Analyzing keywords from different programming languages.
"""
def word_stats(words):
count = len(words)
len_sum = sum(map(len, words))
return {
'count': count,
'total_chars': len_sum,
@Xion
Xion / auth.py
Last active October 2, 2022 02:16
Query string authenticators for Requests
"""
Requests' authenticator that attaches given parameters
to the URL query string.
License: Public Domain.
"""
from requests.auth import AuthBase
class QueryStringAuth(AuthBase):
@Xion
Xion / count_bevy_plugins.rs
Last active October 18, 2022 18:00
Count installed Bevy plugins
// License: BSD-3
use std::io::{self, Write};
use std::string::FromUtf8Error;
use std::sync::Arc;
use antidote::RwLock;
use bevy::prelude::*;
use bevy::reflect::FromReflect;
use bevy::utils::tracing::{self, Dispatch};
@Xion
Xion / git-today
Last active February 14, 2023 21:39
Git command displaying work summary for today
#!/bin/sh
# git-today
#
# Usage:
# * Name it `git-today` and put somewhere inside a `$PATH` directory
# * Invoke as $ git today
LAST_BEFORE_TODAY=$(git log --oneline --until='yesterday 23:59:59' | head -1 | cut -d' ' -f 1)
git --no-pager diff ${LAST_BEFORE_TODAY}..HEAD --stat
EffectAsset {
name: "particle_swirl",
capacity: 8192,
spawner: Spawner {
num_particles: Single(
64.0,
),
spawn_time: Single(
1.0,
),