Tag:python

Git fork and NPM install git-URL in your own version

Sometimes, you want to in stall an NPM package, but it isn't complete enough, or there isn't a TypeScript definition. You can extend it, by git fork -- and then npm install <URL>.git. -- You might need to edit git fork in your own computer first, though.

Not only NPM. Python's PIP can do this as well.

After extending the fork, you might consider git merge to contribute to the main branch.

Customizing JSON parser and stringifier

I have always wanted JSON.parse and JSON.stringify to deal with custom objects, such as Date and Set.

BTW, I have successfully done so in two languages, Python and JavaScript (TypeScript).

Python and Ruby is pre-installed in macOS, but ...

Just don't install anything into System's programming languages, unless you have a virtual environment. Also, you can manage Python and Ruby's versions.

For Python, pyenv and there is Virtual Environment, which is quite opinionated. I use poetry, though. I also tried to fit /.venv/ into the project folder, which requires additional settings.

Sharing Python project that works in another computer!

I find that the issue may includes:-

  • Module dependencies
  • This can be solved by using virtualenv since the very beginning of the project
  • Different python version
  • This can be managed very beautifully with tox
  • Requiring something else outside the first two. For example, brew install phantomjs
  • I don't yet know how to manage this oneā€¦
  • Perhaps Docker

[Python-web.py] Turning website into a desktop app

This is what I have got:

from ui.mainWindow import MainWindow
from webview.controller import initServer

from PyQt5.QtWidgets import *
import sys
import httplib2
from time import sleep

if __name__ == '__main__':
    initServer().start()

    h = httplib2.Http()
    while True:
        try:
            resp = h.request("http://0.0.0.0:8080/", 'HEAD')
            break
        except ConnectionRefusedError:
            sleep(1)
            continue

    app = QApplication(sys.argv)
    window = MainWindow()
    window.showUI()
    window.setBaseSize(1000, 600)
    window.move(QDesktopWidget().rect().center().x()-window.rect().center().x(), window.rect().y())
    sys.exit(app.exec_())