Skip to content

Instantly share code, notes, and snippets.

View Kwpolska's full-sized avatar

Chris Warrick Kwpolska

View GitHub Profile
@Kwpolska
Kwpolska / README.md
Created February 15, 2015 17:29
Fix index hack for Nikola

This hacky plugin adds a post list to a file in post-processing, useful when you want post text out of a post list.

Use with care.

Usage:

Here is my hacky post list:

.. listofpostsgoeshere
for key, value in (
("host", host,),
("port", port,),
("user", username,),
("password", password,),
):
if True:
if True:
for key, value in (("host", host,),
("port", port,),
("user", username,),
("password", password,),):
pass
@Kwpolska
Kwpolska / if-elif.py
Created April 19, 2015 16:43
Python if/elif/else instructions
input = ['foo deinstall 1', 'foo install 2', 'bar install 3', 'bar deinstall 4', 'foo bar 5']
for i in input:
# If the lines start or end with (de)install, you could try startswith/endswith instead.
if 'deinstall' in i:
print("Will deinstall:", i)
elif 'install' in i:
print("Will install:", i)
else:
print("Unrecognized:", i)
# Don’t use this, use itertools.zip_longest() instead!
def alternate_all(*args):
ls = [iter(i) for i in args]
stops = 0 # cheat and get 9 LOC by making this a keyword argument
while stops != len(ls):
stops = 0
for l in ls:
try:
yield next(l)
except StopIteration:
#!/usr/bin/env python3
from passlib.hash import bcrypt_sha256
print('u/u', end='')
try:
bcrypt_sha256.verify('admin', '$bcrypt-sha256$2a,12$St3N7xoStL7Doxpvz78Jve$3vKfveUNhMNhvaFEfJllWEarb5oNgNu')
print(' +')
except TypeError:
print(' F')
#!/usr/bin/env python3
from passlib.hash import bcrypt_sha256
print('u/u', end='')
try:
v = bcrypt_sha256.verify('admin', '$bcrypt-sha256$2a,12$St3N7xoStL7Doxpvz78Jve$3vKfveUNhMNhvaFEfJllWEarb5oNgNu')
print(' +' if v else ' -')
except TypeError:
print(' F')
@Kwpolska
Kwpolska / nikola-manpage.txt
Created June 23, 2015 15:40
Nikola manpage
NIKOLA(1) User Commands NIKOLA(1)
NAME
Nikola - A Static Site and Blog Generator
SYNOPSIS
Create an empty site (with a setup wizard):
nikola init mysite
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Kwpolska
Kwpolska / markdown-doc-parser.py
Last active August 29, 2015 14:23
Markdown document parser (via #python@freenode)
#!/usr/bin/env python3
import re
data = """# Foo
Print a string.
```sh
echo "foo"
```