Skip to content

Instantly share code, notes, and snippets.

View Xion's full-sized avatar

Karol Kuczmarski Xion

View GitHub Profile
@Xion
Xion / playground.rs
Last active November 1, 2017 18:12 — forked from anonymous/playground.rs
Rust code shared from the playground
#[macro_use]
extern crate serde_derive;
extern crate toml;
use std::borrow::Cow;
use std::fs::File;
use std::io::Read;
#[derive(Debug, Serialize, Deserialize)]
pub struct Config<'a> {
#!/bin/sh
curl https://hackage.haskell.org/package/Chart-1.1/docs/Control-Lens-Operators.html | python -c '
import re, sys
for line in sys.stdin.readlines():
m = re.search(r"""class="def">([^<]+)</a> ::""", line)
if m:
print(m.group(1)[1:-1].replace("&lt;", "<").replace("&amp;", "&").replace("&gt;", ">"))
' | sort | uniq | wc -l
@Xion
Xion / setup_gae_virtualenv.sh
Created October 18, 2013 20:20
Setup virtualenv for a Google App Engine project
#!/bin/sh
# Script for setting up virtualenv to work correctly with Google App Engine projects
# @author Karol Kuczmarski "Xion"
DEFAULT_APPENGINE_SDK_PATH="/opt/google_appengine"
DEFAULT_PROJECT_LIB_PATH="./lib"
@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):
from collections import Mapping
import unittest
import warnings
from flask import get_template_attribute
from myapplication import app
class JinjaTestCase(unittest.TestCase):
@Xion
Xion / pytz_patch.py
Created May 6, 2012 09:50
Patching pytz with import hook to have usable generic timezones
"""
Import hook extending pytz package with usable, generic timezones:
GMT-14 up to GMT+12.
Note that pytz already has Etc/GMT+X timezones, but
(quoting Wikipedia):
"In order to conform with the POSIX style, those zones beginning with "Etc/GMT"
have their sign reversed from what most people expect. In this style,
zones west of GMT have a positive sign and those east have a negative sign."
@Xion
Xion / balls.kv
Created October 21, 2012 21:29
Bouncing balls experiment in Kivy
#:kivy 1.4.1
<Ball>:
size: 25, 25
canvas:
Color:
rgb: 1, 0, 1
Ellipse:
pos: self.pos
size: self.size
@Xion
Xion / sqla_regex.py
Last active May 13, 2021 05:16
Regular expression filters in SQLAlchemy
"""
Module implementing an enhanced string column type for SQLAlchemy
with a support for regular expression operators in Postgres and SQLite.
"""
import re
from sqlalchemy import String as _String, event, exc
from sqlalchemy.engine import Engine
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.expression import BinaryExpression, func, literal
@Xion
Xion / noop_import_hook.py
Last active December 22, 2021 23:45
"No-op" import hook
import imp
import inspect
import sys
__all__ = []
class PassthroughImporter(object):
"""Import hook that simulates the standard import flow
@Xion
Xion / listshellaliases.py
Created December 24, 2013 16:53
Mocking "the filesystem" by stubbing built-in open() in Python
"""
Example function that reads a file and does something with it.
"""
import re
import sys
def list_shell_aliases(script):
"""Find all command aliases defined in a shell script.
Aliases are created though the ``alias`` command::