Skip to content

Instantly share code, notes, and snippets.

View Kwpolska's full-sized avatar

Chris Warrick Kwpolska

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Kwpolska
Kwpolska / KeyClass.py
Last active December 30, 2015 07:09
KeyClass — A class with an optional dict-like interface.
# Copyright © 2013, Chris “Kwpolska” Warrick <[email protected]>.
# Licensed under the 3-clause BSD license, see:
# https://github.com/Kwpolska/python-project-template/blob/master/LICENSE
class KeyClass(object):
"""
A class with an optional dict-like interface.
spam = KeyClass()
spam.eggs == spam['eggs']
## go from here
mylist = [{'pk':1, 'f_id':5,'bool':True}, {'pk':2, 'f_id':2, 'bool':True}, {'pk':3, 'f_id':2, 'bool':False}, {'pk':4, 'f_id':7, 'bool':True}, {'pk':5,'f_id':2,'bool':True}, {'pk':6,'f_id':7, 'bool':False}]
## to here
# mynewlist = [{'pk':1,'f_id':5,'bool':True}, {'pk':5,'f_id':2,'bool':True}]
### filter out Falsey elements
mynewlist = [i for i in mylist if i['bool']]
### dropped Falsey element f_id’s
dropped = [i['f_id'] for i in mylist if not i['bool']]
class Cleanable(object):
def __init__(self):
self.resources = []
def add_resource(self, name, obj):
setattr(self, name, obj)
self.resources.append(obj)
def close(self):
for res in self.resources:
@Kwpolska
Kwpolska / build.pl
Created December 31, 2013 20:37
PKGBUILDer — original perl vs bash
#!/usr/bin/perl
# PKGBUILDer
# Part of KRU
# Copyright Kwpolska 2010. Licensed on GPLv3.
# USAGE: ./build pkg1 [pkg2] [pkg3] (and more)
use warnings;
use strict;
use LWP::Simple;
use Archive::Any;
@Kwpolska
Kwpolska / for.py
Last active January 3, 2016 16:19
Poor Man’s `for` re-implementation in pure python
### original code:
for i in X:
if i != 0:
print(i)
else:
break
else:
print('done, no zeroes')
### re-implemented as:
@Kwpolska
Kwpolska / -
Created January 23, 2014 16:29
diff --git a/CHANGES.txt b/CHANGES.txt
index df8aab1..59318e3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -32,6 +32,8 @@ Features
* Add rel=alternate <link> elements to translations of the current page (Issues #988, #989)
* Added a INDEXES_PAGES_MAIN setting to show the page number on the index page
if desired (True) (Issues #210, #987)
+* Added a TRANSLATIONS_PATTERN setting to specify the format for
+ language-dependent filenames (Issue #990)
From 54477ea80d3be097cc84b37b0a61a8661eb7d03b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Chris=20=E2=80=9CKwpolska=E2=80=9D=20Warrick?=
<[email protected]>
Date: Thu, 23 Jan 2014 17:29:53 +0100
Subject: [PATCH] update documentation for TRANSLATIONS_PATTERN
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Chris “Kwpolska” Warrick <[email protected]>