среда, 15 мая 2019 г.

View CSV from browser on MacOS

To quickly view the content of CSV file from browser it is possible to use builtin mac os file preview.
This will work for any browser. Tested on firefox.

Create an application in Automator
  • open Automator
  • add shell script
  • paste code qlmanage -c public.plain-text -p "$@" 1>/dev/null 2>/dev/null
  • set pass input: as arguments
  • save as preview-text app to Applications
  • open csv file in browser
  • select open with
  • choose preview-text app

суббота, 6 апреля 2019 г.

Unvolume in docker

Sometimes there is a need to use base image, but without any defined volumes. For example store some test data to database as image to easily revert it.
Currently and any time soon docker do not support removing volumes, ports and other image properties.
There is no UNVOLUME and UNEXPOSE and UNSETENV.

Several workarounds exists.

Edit image tar file

Just remove volumes from metadata.
There even tool for that
https://github.com/gdraheim/docker-copyedit

multistage build

Copy content of original image, without metadata
Use next dockerfile


# Dockerfile
FROM mysql as orig

FROM ubuntu:bionic as image
# care must be taken, this will not preserve fs ownership
COPY --from=orig / / # this will copy all files, without metadata.

ENV ... # include all commands that are not file related

ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 3306
CMD ["mysqld"]

вторник, 12 марта 2019 г.

Mac os ignore itunes update

To ignore some update for mac in terminal do:

sudo softwareupdate -l

Software Update Tool

Finding available software
Software Update found the following new or updated software:
   * Security Update 2019-001-10.13.6
    Security Update 2019-001 (10.13.6), 1768180K [recommended] [restart]
   * iTunesX-12.8.2
    iTunes (12.8.2), 273564K [recommended]


Then ignore it

sudo softwareupdate --ignore iTunesX

Note that X in the end. Just iTunes will not work.

четверг, 7 июня 2018 г.

Debug django code without server restart

It is nice to debug new function or whole django API without need to rebuild or restart server. Just copy/paste your code to django shell and test it there.

вторник, 5 июня 2018 г.

To my surprise, pep8 style guide check tool was renamed to pycodestyle in 2016. The package is deprecated now.
Thought autopep8 not.

pep8 has been renamed to pycodestyle (GitHub issue #466)
Use of the pep8 tool will be removed in a future release.
Please install and use `pycodestyle` instead.

пятница, 1 июня 2018 г.

Debug django rest API from shell

It is possible to debug step by step Django rest framework API in pdb/ipdb debugger.
  • Import API on line (1)
  • Replace root@root with valid email of user with correct permissions on line (2)
  • Paste code in shell and run
  • Execution will start on Django internal code. To go to your API use breakpoints.

import ipdb #or pdb
_user = User.objects.get(

email__contains='root@root')#(2)valid user email
from rest_framework.test import APIRequestFactory
from rest_framework.test import force_authenticate
_factory = APIRequestFactory()

_request=_factory.post('', {})
force_authenticate(_request, _user)
from project.apps.users.api import ApiMySettingsView as api # (1)
_view=api.as_view()

responce=ipdb.runcall(_view,_request) #debug
#responce=_view() #just run
vars(responce)


http://www.django-rest-framework.org/api-guide/testing/
https://docs.python.org/3/library/pdb.html

среда, 15 ноября 2017 г.

Automate check for a new Nvidia or Intel drivers

Sometimes you need to know when a new version of graphics driver is available and do not want to install constantly running in background tools from a manufacturer. Like Nvidia experience or Intel driver assist tool. Or you need notifications for the remote machine.

Luckily there is exists packages for Nvidia and Intel in the chocolatey project repository. And they updated pretty quickly. So using API it is possible to poll them for a new version.

https://github.com/kotofos/check-chocolatey-package-version

code example:

import xml.etree.ElementTree as ET
import zipfile
from io import BytesIO
from urllib.request import urlretrieve, urlopen

driver_url_map = {
    'nvidia': 'https://chocolatey.org/api/v2/package/nvidia-display-driver',
    'intel': 'https://chocolatey.org/api/v2/package/intel-graphics-driver',
}


def download(url):
    f = BytesIO()
    response = urlopen(url)
    f.write(response.read())
    return f


def get_current_version(name):
    url = driver_url_map[name]
    archive = download(url)
    zip = zipfile.ZipFile(archive)

    string = zip.read(url.rpartition('/')[-1] + '.nuspec').decode()
    string = "\n".join(string.split("\r\n"))
    root = ET.fromstring(string)

    tag_name = ('{http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd}' 
                'version')
    for elem in root.iter():
        if elem.tag == tag_name:
            return elem.text


if __name__ == '__main__':
    for name in ('nvidia', 'intel'):
        res = get_current_version(name)
        print('version for', name, res)