Skip to content

Instantly share code, notes, and snippets.

@Chris2048
Chris2048 / flask sse
Last active September 19, 2024 12:31
Server-Side Events in flask
#!/bin/python2.7
# -`*- coding: utf-8 -*-
"""
test for Server-Side events in flask
inspiration from:
http://www.html5rocks.com/en/tutorials/eventsource/basics/
https://github.com/niwibe/sse.git
https://github.com/niwibe/django-sse.git
@Chris2048
Chris2048 / handler idea
Last active October 9, 2015 23:48
handler function
#!/usr/bin/python2.7
# Simple example of using a 'handler' function
# -- Chris2048
def parseLine(line):
if line==True:
raise Exception()
return "foo"
@Chris2048
Chris2048 / san
Last active October 7, 2015 11:57
sed sanitise bash function
# Use this shell function to sanitise variables before using them with sed,
# or in another context where escapes might be substituted
funtion san {
echo "$1" | tr -d '\n' | xxd -plain | sed 's/\(..\)/\\x\1/g' | tr -d '\n'; }
# Use it like this
# somevar=$(san "$somevar")
(require 'benchmark)
(defun my-require (feat)
(if (featurep feat)
(message "erraneous usage: '%s'" feat)
(message "'%s' loaded in %.2fs" feat
(benchmark-elapse (load-library (symbol-name feat))))))
;; The Common Lisp library for Emacs Lisp gives us keyword arguments for defun*
(require 'cl)
(defvar projects (list) "This keeps track of all available projects.")
(defvar project (list) "And here's our current project.")
(defvar project-index (list) "This will store the project index of files.")
(defvar project-default-file-types '("ASCII.*"))
;; A project will have a name, a list of directories, (recursive and non),
;; and a list of file-types that we want to index.