Skip to main content

Posts

Dart: List directory recursively (tree, ls)

Dart: List directory recursively (tree, ls) ls(String where, [String prefix]) { if(prefix == null) { prefix = ''; } var dir = new Directory(where); print(where); List contents = dir.listSync(); for (var fileOrDir in contents) { if (fileOrDir is File) { print(fileOrDir.path); } else if (fileOrDir is Directory) { print(fileOrDir.path); ls(fileOrDir.path, prefix + '-'); } } }
Recent posts

Git branch in bash

append to ~/.bashrc: # git branch in terminal parse_git_branch () { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' } export PS1= "\[\e]0;\u@\h: \w\a\]\[\033[01;34m\]\w\[\033[00m\]:\033[01;32m\] \$ (parse_git_branch)\[\033[00m\]$ " ------------ Add this to /env/bin/activate befoe export PS1 PS1="env,$_OLD_VIRTUAL_PS1"

Solve the Downcasting-Problem of Django Models

In Django, I cannot downcast (attributes are missing). Any trivial solution breaks the Open-Closed Principle. This Solution not: from django.db import models class ParentModel ( models . Model ): type = models.CharField( max_length = 255 , default = 'item' ) class Meta : abstract = True def save (self, *args, **kwargs): self .type = self .type_str super ().save(*args, **kwargs) @ staticmethod def register_subtype (clazz): the_type = clazz.type_str if not hasattr (ParentModel, 'subclasses' ): ParentModel.subclasses = {} ParentModel.subclasses[the_type] = clazz def downcast (self): if self .type not in ParentModel.subclasses: return self return ParentModel.subclasses[ self .type].objects.get( pk = self .pk) With the example Item: class Item ( ParentModel ): """Stuff you can purchase""" type_str = 'item' ...

Traveling with the speed of light

Traveling with the speed of light is only possible if we can sperate our mind from our body. Downloading and uploading. Before using clones or other bodies we have to be able to upload it to a robot. The singularity comes before the speed of light traveling. Separating our minds from our bodies is the key to human survival.