Updates from October, 2018 Toggle Comment Threads | Keyboard Shortcuts

  • penguin 11:06 on 2018-10-17 Permalink | Reply
    Tags: , , ,   

    Misc Django I – forms 

    Custom form errors

    If you want to validate something in the view, and return with a custom error message in the same form, you can use the “Form.add_error(fieldname, errorstring)” method. And then, of course, return to the previous template.

    class MyView(View):
        def get(self, request):
            data = form.cleaned_data
            if len(res) > 0:
                form.add_error(
                    'login', 
                    "Diese Personalnummer existiert bereits!")
                return render(
                    request, 
                    'my_template.html',
                    {'form': form})

    Dynamic choice fields in forms

    You want a form which fills its choice field from the database? And if the database changes, if you reload the page, the form should change as well? Of course! Django got you covered.

    class UserForm(forms.Form):
    
        def __init__(self, *args, **kwargs):
            super(UserForm, self).__init__(*args, **kwargs)
            self.fields['site'] = forms.ModelChoiceField(
                label="Site",
                queryset=Site.objects.all().order_by('name'),
            )
            for field in ('department', 'office', 'phone'):
                self.fields.move_to_end(field)
    
        login = forms.CharField(label="Login")
        email = forms.EmailField(label="Email")
        site = None             # this is set in __init__() :)
        department = forms.CharField(label="Department")
        office = forms.CharField(label="Office")
        phone = forms.CharField(label="Phone")

    … now, why the “for field in (‘department’ …)” line you ask?

    Simple. The fields dict is an OrderedDict. If you replace a field it is appended to the end again. So in the form the “Site” input box would be displayed last, although it makes more sense to display it where it is in the original definition.

    Using “.move_to_end()” you can re-adjust this. If someone knows a better method … feel free to tell me.

    (Sources: here)

     
  • penguin 16:34 on 2018-10-16 Permalink | Reply
    Tags: , ,   

    Django, psql & “permission denied” on migrate 

    I got this error:

    psycopg2.ProgrammingError: permission denied for relation django_migrations

    … when I wanted to do a “python manage.py migrate”. This post had the solution. In short: You have to change the owner of the tables to the one specified in the Django configuration.

    This is how my script looks:

    #!/usr/bin/env bash
    
    echo "ALTER TABLE public.django_admin_log OWNER TO <new_owner>;" | psql -U <current_owner> <database>
    # ...
     
  • penguin 18:59 on 2018-09-26 Permalink | Reply
    Tags: ,   

    Firefox close tab buttons on mouse hover 

    I used to have Firefox’s TabMix Plus addon installed. And the feature I missed most – surprisingly – is to have the “close tab” buttons appear on a tab when you hover the mouse over it.

    Googling a little bit told me how to bring it back:

    .tabbrowser-tab:not([selected]):not([pinned]) .tab-close-button {
      visibility: hidden !important;
      margin-left: -16px !important;
    }
    .tabbrowser-tab:not([selected]):not([pinned]):hover .tab-close-button { visibility: visible !important; margin-left: 0px !important; display: -moz-box !important; }
     
  • penguin 18:55 on 2018-04-18 Permalink | Reply
    Tags: osx,   

    Mac three finger gestures in browsers 

    Well, I *love* my three-finger-jump-to-top gesture in Firefox. It was gone.

    It took me about 2h to get it back by googling. And I blog so I don’t forget.

    Here’s where I should look next time straight away: System setting – Trackpad – rightmost tab – first setting.

     
  • penguin 20:11 on 2017-07-27 Permalink | Reply
    Tags: , cups,   

    CUPS is … weird 

    CUPS is the printing system developed by Apple which is now also in use on pretty much every other Linux / Unix / *BSD box there is. Unfortunately, the process of managing printers is way more painful than the process on Arch Linux. At least with my setup, which is i3 running in a weirdly crippled GNOME session.

    This is what you have to do to get CUPS working on your machine:

    The magic is line 2 – adding your user to the sys group. If you don’t do this, you won’t be able to use the web interface at all. Which is a shame, since then you can’t do anything useful (install printers, manage jobs, etc …).

     
  • penguin 10:52 on 2017-01-21 Permalink | Reply
    Tags: blog, code, wordpress   

    Syntax highlighting with wordpress 

    This is just a test for syntax highlighting. Which I really really really wanted to have. Even if it’s WordPress and not something cool like hugo.

    So, let’s try:

    That doesn’t look so bad, right?

    How to do this

    • install the crayon syntax highlight plugin
    • when writing posts, your toolbar will have a new icon looking like this: <>
    • press it, and an “add code” dialog will open
    • do your thing
    • save
    • done

    Like.

    Dislikes

    • I don’t know which JS engine this thing uses (if any public one in particular)
    • I like highlight.js

    (So, none really)

    Alternative plugins (untested)

    To be honest, the only real contender in installation base and features seems to be Syntax Highlighter Evolved. I have not tried it, but if you don’t like crayon, that looks like the one to go.

     
  • penguin 11:27 on 2016-01-29 Permalink | Reply
    Tags: ,   

    Really annoying thread properties 

    This sucks monkey ass, mainly because I didn’t think of that before. And that’s just one example why multi-threaded (soon to be -processing, probably) applications are hard.

    [code]import subprocess as sp
    import time
    import os
    from threading import Thread

    class MyThread(Thread):

    def __init__(self, mydir):
    super().__init__()
    self.mydir = mydir

    def run(self):
    os.chdir(self.mydir)
    time.sleep(2)
    print("I’m (%s) in directory %s"
    % (str(self), os.getcwd()))

    if __name__ == "__main__":
    MyThread("/tmp").start()
    time.sleep(1)
    MyThread("/").start()
    [/code]

    Result is:

    [code]I’m (<MyThread(Thread-1, started 140195858716416)>) in directory /
    I’m (<MyThread(Thread-2, started 140195850323712)>) in directory /[/code]

     
  • penguin 17:32 on 2015-12-25 Permalink | Reply  

    Mac software essentials 

    Well, after the Firefox Essentials, here’s my list of Mac essentials:

     
  • penguin 10:43 on 2015-12-07 Permalink | Reply
    Tags: , cloud, services   

    CI / CD solutions 

    Everyone wants free candy. Or a CI/CD solution, that …

    • auto-deploys container-based servcies
    • auto-updates (roll-forward, roll-back) those services on keypress and “triggers”
    • has one-click-deployment of services.

    My definition of “service” here is “A set of containers working together in a certain way, automatically load balanced where needed”. Example: A n worker nodes, loadbalanced from a web endpoint, and a database container. All deployed at the same time. Including one-click-deployment of environments (“Oh, I’d like to test this revision again, let’s deploy it quickly”…). Note that this is mostly CD (continuous deployment), cause CI is being done for a while now with – mostly – Jenins and other tools.

    What I have found so far that seems to satisfy those requirements:

    And the service-only solutions without a tools tack which you can deploy locally:

    This is kinda it. I would love to evaluate  all those tools, but most of are not really AWS-deploy-friendly, and in the Shippable and Tectonic case they are paid full stack services without local (cloud-owned) deployment anyway. And most are in beta. But the scenery is becoming interesting …

    I will try to post my findings here, as well as the final choice I made for my current client, along with the reasons.

    And for now: Mesosphere and Rancher looks really cool. And I mean “looks” – the UI is just pleasing (which is the most important selection criteria, I know 😉

    Update 2015-12-10: Added Vamp, Kubernetes

     
  • penguin 09:50 on 2015-11-19 Permalink | Reply  

    InsufficientCapabilities on AWS 

    New project. I can play around as much as I want, as long as on day X I am done.

    Really frightening, and really cool.

    Anyway, first operation: Create a bunch of S3 buckets and IAM roles to interface with them. Which is kinda not-so-easy.

    Beacause when you create IAM capabilities with cloudformation, you get this error:

    … which is a fancy way of saying “do this”:

    … which you don’t really find easily with google. Or everybody knows, but me. Gnaah.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel