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

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
# 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
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
Loading
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
$ 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
#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
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
Loading
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
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.