Skip to content

Instantly share code, notes, and snippets.

;; 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.
(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))))))
@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")
@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 / 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 / sse example
Last active October 10, 2015 12:08
example use of sse
#!/bin/python2.7
# -`*- coding: utf-8 -*-
from gevent import monkey
monkey.patch_all()
import flask
app = flask.Flask(__name__)
app.debug = True
app.secret_key = 'asdf'
#!/bin/bash
#
# Usage: ./make-lsLR.sh
#
# Purpose:
# to make a file that is parseable for recovering
# a filled /lost+found directory by parsing
# filesize, md5sum, permisions and path+filename
#
# Author: Ingo Juergensman - http://blog.windfluechter.net
#!/usr/bin/python
#
# usage: check_lostfound.py <pathtolost+found> [make_it_so]
#
# Purpose: to find files in lost+found and trying to restore
# original files by comparing ls-md5sum-files.txt (generated by
# make-lsLR.sh
# Option make_it_so cause the data actually being written/moved
# whereas the script runs in dry mode per default.
#
@Chris2048
Chris2048 / meetuprss_to_palcal
Created April 7, 2013 16:34
meetup.com personal rss to pal calendar format
#!env python2.7
import feedparser
from datetime import datetime, timedelta
d = feedparser.parse("http://www.meetup.com/events/atom/MEETUP_RSS_URL/all")['entries']
def getDate(content):
from bs4 import BeautifulSoup
@Chris2048
Chris2048 / getHN
Created July 16, 2013 22:18
getHN
#!/usr/bin/python2.7
import requests
def getItems(from_date, to_date):
api_root = 'http://api.thriftdb.com/api.hnsearch.com/items/_search'
url = api_root + '?filter[fields][create_ts]=[{}+TO+{}]'.format(from_date, to_date)
payload = {
'limit': 100,
'sortby': 'create_ts desc',