Skip to content

Instantly share code, notes, and snippets.

@ieure
Created September 14, 2012 16:01
Show Gist options
  • Save ieure/3722869 to your computer and use it in GitHub Desktop.
Save ieure/3722869 to your computer and use it in GitHub Desktop.
;;; sts-mode.el --- Safe-to-Spend
;; Copyright (C) 2012 Ian Eure
;; Author: Ian Eure <ian.eure@gmail.com>
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'json)
(defgroup sts nil
"Safe-to-Spend™"
:prefix "sts-"
:group 'net)
(defcustom sts-user-id nil
"Your Simple userId.")
(defvar sts-timer nil)
(defvar sts-object " ")
(defun letify (balances)
(mapcar (lambda (p) (list (car p) (/ (cdr p) 10000.0))) balances))
(defmacro sts-with-balances (balances &rest body)
`(let ,(letify (eval balances))
,@body))
(defun sts-parse (&rest args)
(goto-char (point-min))
(re-search-forward "\n
?\n
?")
(sts-with-balances (json-read)
(setq sts-object (format " |$%.2f<™" safe_to_spend))))
(defun sts-refresh ()
(let ((url-show-status nil))
(url-http
(url-generic-parse-url
(format "http://int-api.banksimple.com/txs-api/users/%s/balances"
sts-user-id)) 'sts-parse nil)))
(defun sts-enable ()
;;(setq sts-timer (run-at-time "1 min" (* 60 60) 'sts-refresh))
(add-to-list 'mode-line-modes '(t sts-object))
(sts-refresh))
(defun sts-disable ()
(setq mode-line-modes (remove '(t sts-object) mode-line-modes))
(ignore-errors
(cancel-timer sts-timer)
(setq sts-timer nil)))
(define-minor-mode sts-mode "Show Safe-to-Spend™ in your modeline"
nil nil nil
(cond (sts-timer (sts-disable))
(t (sts-enable))))
(provide 'sts-mode)
;;; sts-mode.el ends here
@zzz6519003
Copy link

what's this language...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment