Ways to invoke python and Spyder on OSX

To make spyder callable from Spotlight or Finder: Locate where your spyder executable is by running in Terminal: which spyder This should yield ~/anaconda/bin/spyder if you installed spyder via Anaconda, /opt/local/bin/spyder if you used MacPorts or something similar. Create a file called spyder in your Applications directory and make it executable. Then, fill it with … Read more

Django unique, null and blank CharField giving ‘already exists’ error on Admin page

None of the answers clearly describe the root of the problem. Normally in the db you can make a field null=True, unique=True and it will work… because NULL != NULL. So each blank value is still considered unique. But unfortunately for CharFields Django will save an empty string “” (because when you submit a form … Read more

Parsing a tweet to extract hashtags into an array

A simple regex should do the job: >>> import re >>> s = “I love #stackoverflow because #people are very #helpful!” >>> re.findall(r”#(\w+)”, s) [‘stackoverflow’, ‘people’, ‘helpful’] Note though, that as suggested in other answers, this may also find non-hashtags, such as a hash location in a URL: >>> re.findall(r”#(\w+)”, “http://example.org/#comments”) [‘comments’] So another simple … Read more

How to parse mjpeg http stream from ip camera?

import cv2 import urllib import numpy as np stream = urllib.urlopen(‘http://localhost:8080/frame.mjpg’) bytes=”” while True: bytes += stream.read(1024) a = bytes.find(‘\xff\xd8’) b = bytes.find(‘\xff\xd9’) if a != -1 and b != -1: jpg = bytes[a:b+2] bytes = bytes[b+2:] i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.CV_LOAD_IMAGE_COLOR) cv2.imshow(‘i’, i) if cv2.waitKey(1) == 27: exit(0) edit (explanation) I just saw that … Read more

How to get two random records with Django

The order_by(‘?’)[:2] solution suggested by other answers is actually an extraordinarily bad thing to do for tables that have large numbers of rows. It results in an ORDER BY RAND() SQL query. As an example, here’s how mysql handles that (the situation is not much different for other databases). Imagine your table has one billion … Read more

Issues in urls when running Django in subdirectory or say suburl

That’s the old format for urls.py. The current is this: “””monero URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.0/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path(”, views.home, name=”home”) Class-based views 1. Add an import: from other_app.views import … Read more

error code: 521