Skip to content

Instantly share code, notes, and snippets.

View Xion's full-sized avatar

Karol Kuczmarski Xion

View GitHub Profile
@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 / interruptibleFadeOut.js
Created August 31, 2015 03:20
Interruptible fade-out DOM animation
function interruptibleFadeOut(element, options) {
if (typeof options === 'number') {
options = {fadeOut: options};
}
element = $(element);
return new Promise(function(resolve) {
// Event handlers used by the effect.
var events = {
mouseenter: function() { interruptAnimation(); },
@Xion
Xion / error.py
Created August 23, 2015 16:33
ErrorExtension for Jinja
"""
Jinja extension adding support for {% error %} tag
that allows to raise exceptions directly from templates.
"""
from jinja2 import TemplateAssertionError
from jinja2.ext import Extension
from jinja2.nodes import CallBlock, Const
class ErrorExtension(Extension):
@Xion
Xion / setup.py
Last active March 21, 2016 01:51
setup.py skeleton
#!/usr/bin/env python
"""
{project}
======================================
{description}
"""
import ast
import os
from setuptools import find_packages, setup
@Xion
Xion / Cell.java
Created December 28, 2014 14:28
Cell enum from Taphoo
package pl.org.xion.taphoo.logic;
/**
* An utility class to hold ranges of cells' values.
* @author Xion
*/
final class CellRanges {
/**
* Private constructor to prevent instantiation.
@Xion
Xion / preview.hs
Last active June 14, 2017 20:54
Preview structured text files (like Markdown) in the browser
#!/usr/bin/env runhaskell
-- Preview structured text files in the browser
-- Usage: $ preview FILE [BROWSER]
-- by Karol Kuczmarski "Xion" -- 25 August 2013
import Control.Exception (bracket)
import System.Environment (getArgs)
import System.Directory (getTemporaryDirectory)
@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
@Xion
Xion / list_tags.sh
Last active June 4, 2016 02:39
List "tags" (TODO etc.) found in inline comments
#!/bin/sh
# List code "tags" (TODO et al.) present in source files within given directory
#
# :author: Karol Kuczmarski "Xion"
# :license: Public Domain
TAGS="TODO FIXME XXX"
@Xion
Xion / gist:8624077
Created January 25, 2014 21:41
requirements.txt parser for setup.py
def read_requirements(filename='requirements.txt'):
"""Reads the list of requirements from given file.
:param filename: Filename to read the requirements from.
Uses ``'requirements.txt'`` by default.
:return: Requirments as list of strings.
"""
# allow for some leeway with the argument
if not filename.startswith('requirements'):
@Xion
Xion / debug_smtpd
Last active January 1, 2016 11:19
Debug SMTP server
#!/bin/sh
# Start a debug SMTP server using Python's smtpd module
show() {
echo 1>&2 "$@"
}
port=${1-25}
smtpd_args="-c DebuggingServer localhost:$port"