Python Cherrypy Server Sent Event SSE (eventsource)

I hardly find a good example for server sent event using cherrypy (python).  So I wrote a simple one.

def systime(self):
  cherrypy.response.headers["Content-Type"] = "text/event-stream;charset=utf-8"
  def timedata():
    for ii in range (10):
      yield (bytes('id: {}\ndata:{{"time":"{}"}}\n\n'
return timedata()
systime._cp_config = {'': True}


You should also add some cache control so that the browser doesn’t cache your result.

Cherrypy is not a good tool to publish SSE as it is not an async server.  You may consider using an asyncio version of cherrypy (not official) or use some async servers like Tornado or Twisted.


Little Windows Batch to get yyyymmdd (year, month, day of month)

Do you need to write a windows batch and need to get yyyymmdd?  It is a nightmare if you deploy your batch file to multiple machines (e.g. different windows version, different locale setting, etc).

Unlike linux, windows build-in date command will output different format for different Windows version (e.g. xp, 2003, 2012) or different localized version.  And the user can also customize the output format.

In the old days, I’ll write a little program to do this.  But now there is a little tool, yyyymmdd.bat, which seems to work on different Windows versions.

Step by Step Guide on Setting Up git Server in Arch Linux (pushable)

Warning: This guide will create a git server readable/writable by everyone. That is no user/authentication control

# Login as root
pacman -S git

# If you want to push to the repository, do the following (2 steps).
vi /usr/lib/systemd/system/git-daemon\@.service
# Append –enable=receive-pack to the line of ExecStart

systemctl start git-daemon.socket

# If you want the git server starts on every reboot, do the following step
systemctl enable git-daemon.socket

cd /srv
mkdir git
chown git:git git
cd git

# Create a repository named project1.git
git –bare init project1.git
chown -R git:git project1.git

# at the working station (can be linux or windows machine), not root is required
# cd to your project base folder and clone the project1.git to local folder
cd /projects
git clone git://git_server_hostname_or_ipaddress/prject1.git cloned_project1
cd cloned_project1
git push origin master
# Now, you can do anything to the project (E.g. create a file file1.txt)
vi file1.txt
git commit -a
git push