Skip to content

Instantly share code, notes, and snippets.

View Kwpolska's full-sized avatar

Chris Warrick Kwpolska

View GitHub Profile
@Kwpolska
Kwpolska / DESCRIPTION.rst
Created September 12, 2012 18:51
\b and \r magic
View DESCRIPTION.rst

Hello. Prompted by fosskers/aura#10 <fosskers/aura#10>, I did a quick analysis of behavior of \b and \r in various terminals.

Long story short, @fosskers <https://github.com/fosskers>, author of aura_, an AUR helper (and don’t forget I am a developer of one, too!) is using \b and \r in his code for doing magic like displaying progress messages in a row. Aura is written in Haskell, but I do not speak Haskell, so I used Python.

Other info

Expected output

@Kwpolska
Kwpolska / prime.py
Created January 28, 2013 18:08
Python prime number test
View prime.py
# A fancy way to test if a number is prime in Python.
# Copyright © 2013, Kwpolska. Free for any use if this clause is reproduced.
def prime(n):
for i in range(2, n):
t = float(n) / float(i) # if you need debug, just print t
if (t % 1) == 0:
return False
return True
View lxml-implementation.py
In [7]: lxml.html.fromstring(text).xpath("//*[@class='box']//form/input")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-7-0792823b10b8> in <module>()
----> 1 lxml.html.fromstring(text).xpath("//*[@class='box']//form/input")
/usr/lib/python3.3/site-packages/lxml/html/__init__.py in fromstring(html, base_url, parser, **kw)
663 return document_fromstring(html, parser=parser, base_url=base_url, **kw)
664 # otherwise, lets parse it out...
--> 665 doc = document_fromstring(html, parser=parser, base_url=base_url, **kw)
@Kwpolska
Kwpolska / lxml.ipynb
Created February 16, 2013 19:05
LXML Breakage
View lxml.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Kwpolska
Kwpolska / print.sh
Created February 16, 2013 19:30
Python print() — 2.7 vs 3.3
View print.sh
$ python2 -c 'print("python", "2")'; python3 -c 'print("python", "3")'
('python', '2')
python 3
$ python2 -c 'from __future__ import print_function; print("python", "2")'
python 2
View net.c
#include <stdlib.h>
#include <stdio.h>
int print_error(int errorcode) {
FILE *fp;
char cmd[100];
char out[1000];
sprintf(cmd, "NET HELPMSG %d'", errorcode);
fp = popen(cmd, "r");
@Kwpolska
Kwpolska / get_pygments_css.py
Created March 23, 2013 12:48
Pygments CSS generator
View get_pygments_css.py
import pygments.formatters
import pygments.styles
def get_pygments_css(pygments_style):
"""Get the CSS for a Pygments style."""
return pygments.formatters.HtmlFormatter(style=pygments.styles.get_style_by_name(pygments_style)).get_style_defs('.code')
@Kwpolska
Kwpolska / octal.ipynb
Created May 11, 2013 16:46
Octal numbers
View octal.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Kwpolska
Kwpolska / mdx_nikola-fix.ipynb
Last active December 27, 2015 04:39
mdx_nikola fix
View mdx_nikola-fix.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View mdx_nikola fix.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.