Firefox HSTS Settings store

2015-10-31 by romanb firefox, hacks, https

So I've set HSTS on whole domain with subdomains, preloaded, cosmic max-age, like:

Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"

And now Firefox forces HTTPS on every subdomain. Even if I enter http:// directly into address bar.

Changing HSTS to:

Strict-Transport-Security "max-age=3600"

doesn't help because previous one is somehow cached for very long time.

Clearing cache and history doesnt help either, firefox still stores it somewhere. On clear profile everything is working OK.

So there is this file in your Firefox profile directory called SiteSecurityServiceState.txt.

Turn off Firefox so there's nothing using your profile directory and edit that file, remove your site from cache.

siege [error] socket: connection refused

2015-09-26 by romanb benchmark, hacks, linux

If you testing stuff with siege and it starts throwing socket: connection refused errors first check if you did not run out of ports for outgoing connections, then use this commands:

sysctl net.ipv4.tcp_tw_reuse=1
sysctl net.ipv4.tcp_tw_recycle=1

Bitbucket show hg commands button

2013-07-01 by romanb bitbucket, hacks, mercurial, ui

Steve Losh noted on Twitter that there's no usable URL to pull changes from pull request in your command line. Well, there is, sorta, pull request page html contain hidden "merge-commands" <pre> in case there are conflicts, all you have to do is show it.

I used greasemonkey to add "hg" button between "merge" and "edit" buttons on pull request page. It looks like this:

Here is script source:

Distinguishable colors for stack graphs

2013-06-29 by romanb hacks, ui

I needed to stack some data on single graph (like network traffic from multiple hosts).

Colors on such graphs should be distinguishable, best approach is evenly space (hue-wise) color palette. To enhance separation every odd color has lower brightness.

It will look something like this:

or this:

I needed it for RRDgraph so here's perl version:

Patch django form field for testing

2013-04-15 by romanb django, hacks, testing

In case you're wondering how to patch Django form field for testing purposes (like URLField that passes local uri: file://...) here's how:

from .forms import ThatForm
from django import forms

class MyTests(TestCase):
    def test_pass_url(self):
        orig_url = ThatForm.base_fields['url']
        ThatForm.base_fields['url'] = forms.CharField()

        # ... do your thing #

        # and just in case set original field back,
        # if other tests need it:
        ThatForm.base_fields['url'] = orig_url

Simplest memcached "top"

2013-03-12 by romanb hacks, linux

Simplest memcached "top" consist of watch, echo and netcat:

watch 'echo -e "stats\nquit\n" |nc 127.0.0.1 11211'
2011-07-01 by romanb django, hacks

smartspaceless w Django

2010-02-10 by romanb hacks, python

Wbudowany w Django tag spaceless jest dziwny, zjada wszystkie spacje między tagami i żadnych w środku. W większości zastosowań to wystarcza ale...

Czytaj więcej (en)...

Django smartspaceless

2010-02-10 by romanb django, hacks

Default django spaceless tag is weird, it consumes all spaces between tags and none inside of them. It's good for small parts of site but...

...But I like my html to be cleared of all unnecessary mess which in many cases end up like this:

<a href="...">link1</a> <a href="...">link2</a>
generates awful:
link1link2

In addition if you like having your templates indented it leaves awful things like:

<div>
                                Test text testt
                             </div>

Here's my "smart" version of strip_spaces_between_tags which can be used with overrided spaceless template tag:

def strip_multiple_spaces_between_tags(value):
    """Returns the given HTML with multiple spaces between tags removed."""
    def tagcheck(obj, prefix='', sufix=''):
        tag = obj.group(1).lower()
        if tag[0] == '/':
            tag = tag[1:]
        if tag != 'pre':
            return '%s<%s>%s' % (prefix, ''.join(obj.groups('')), sufix)
        return obj.group(0)
    def tagprecheck(obj):
        return tagcheck(obj, sufix=' ')
    def tagpostcheck(obj):
        return tagcheck(obj, prefix=' ')

    value = force_unicode(value)
    value = re.sub(r'<(/?[\w]+)([^>]*)>\s{2,}', tagprecheck, value);
    value = re.sub(r'\s{2,}<(/?[\w]+)([^>]*)>', tagpostcheck, value)
    value = re.sub(r'>\s{2,}<', '> <', value)
    return value
strip_multiple_spaces_between_tags = allow_lazy(strip_multiple_spaces_between_tags, unicode)

This does few things:

  • it removes all multiple spaces between tags,
  • it removes all multiple spaces at from "<tag> HERE text HERE </tag>" on all tags except pre.
If you find it useful or you have fix/extension to it (any other tag I should think of?) please feel free to comment.

pgrow czyli jak inaczej wyswietlić wiersz w psql

2009-02-15 by romanb hacks, pgrow, postgresql, psql

psql każdy używający postgresa znać powinien, wygodna konsola do bazy postgresql mająca masę możliwości. Niestety nie znalazłem rozwiązania jak poradzić sobie z sytuacją w której na wąskim terminalu wyświetlić trzeba wiersz tabeli mającej kilkanaście kolumn.

Próbowaliście? wygląda to m/w tak:

select * from klienci where id like '586_';
  id  | typ | kod  | s_kat |    imie    |     nazw     |                        nazwa_f
                        |      adr_ul      | adr_nr | adr_miasto | adr_kodp |   telefon
    |    tel_kom    |      nip      |          email          |
                   uwagi
------+-----+------+-------+------------+--------------+-------------------------------
------------------------+------------------+--------+------------+----------+----------
----+---------------+---------------+-------------------------+------------------------
-------------------------------------------------------------------
 5863 | i   | 7340 | now   | xxxxx      | xxxxxxxxxxxx |
                        |                  |        |            |          |          

    | xxxxxxxxx     |               |                         |
 5865 | i   | 7343 | now   | xxxxxxx    | xxxxx        | xxxxxxxxxx xxxxxxxxxxx xxxxxxx
 xxxxxxxxxxx x xxxxxxxx | ul. xxxx xxxxxxx | 6      | Kraków     | 31-547   | xxxxxxx
    | xxx xx xx fax | xxx-xx-xx-xxx | xxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxx
 lub ogólny sekretariat....;
Prawda, że piękne? Tylko szukaj tu człowieku danych...

Dlatego też, zainspirowany postem Huberta Lubaczewskiego, napisałem sobie skrypt którym pragnę się podzielić, powoduje on, że wynik tego samego zapytania wygląda tak:

--------------------
         id: 5863
        typ: i
        kod: 7340
      s_kat: now
       imie: xxxxx
       nazw: xxxxxxxxxxxx
    nazwa_f:
     adr_ul:
     adr_nr:
 adr_miasto:
   adr_kodp:
    telefon:
    tel_kom: xxxxxxxxx
        nip:
      email:
      uwagi:
--------------------
         id: 5865
        typ: i
        kod: 7343
      s_kat: now
       imie: xxxxxxx
       nazw: xxxxx
    nazwa_f: xxxxxxxxxx xxxxxxxxxxx xxxxxxx xxxxxxxxxxx x xxxxxxxx
     adr_ul: ul. xxxx xxxxxxx
     adr_nr: 6
 adr_miasto: Kraków
   adr_kodp: 31-547
    telefon: xxxxxxx
    tel_kom: xxx xx xx fax
        nip: xxx-xx-xx-xxx
      email: xxxxxxxxxxxxxxxxxxxxxxx
      uwagi: xxxxxxxxxxxxxxxxxxxxxxx lub ogólny sekretariat....;
--------------------
Według mnie lepiej, a Wy jak myślicie?

Oto skrypt:

#!/usr/bin/perl
my $head = 0;
my $continue = 0;
while (<STDIN>) {
        if (/^\(\d+ row/) {
                print "-"x20 . "\n" . $_;
                $head = 0;
                $continue = 0;
                @data = undef;
                @data2 = undef;
                next;
        }
        s/[\n\r]+$//;
        if (!$head) {
                @order = split /\|/;
                $head = 1;

                foreach $t (@order) {
                        $head = length($t) if length($t) > $head;
                }
                $head++;
                next;
        }
        if ($continue) {
                @data2 = split /\|/;
                $data[$#data] .= '\n' . (shift @data2);
                push @data, @data2;
        } else {
                @data = split /\|/, $_, -1;
        }
        if ($#data < $#order) {
                $continue = 1;
                next;
        } else {
                $continue = 0;
        }

        printf("%s\n", "-"x20);
        for $i (0..$#order) {
                printf("%${head}s: %s\n", $order[$i], $data[$i]);
        }
}
Tak go należy użyć w psql:
-- włączenie unaligned output (\a) oraz przekierowania output (\o):
\a \o |./pgrow.pl
-- select
select * from;
-- wyłączenie unaligned oraz przekierowania output:
\a \o
Miłego używania...