]> ruderich.org/simon Gitweb - config/dotfiles.git/blobdiff - bin/calc
bin/calc: Add function to convert seconds to date.
[config/dotfiles.git] / bin / calc
index e70128a55569864291f797951ffcb54b4ecca3fc..c3641191956eded9510788bf714523669d360aac 100755 (executable)
--- a/bin/calc
+++ b/bin/calc
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright (C) 2011-2012  Simon Ruderich
+# Copyright (C) 2011-2013  Simon Ruderich
 #
 # 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
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-python -i -c 'from math import *;
+exec python -i -c '
+
+# Math functions.
+from math import *
 
 def ld(x):
     return log(x)/log(2)
@@ -24,6 +27,15 @@ def ld(x):
 def binom(n,k):
     return reduce(lambda a,b: a*(n-b)/(b+1),xrange(k),1)
 
+
+# Time/Date functions.
+import time
+
+# Convert time in seconds since epoch to readable string.
+def stime(seconds):
+    print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(seconds))
+
+
 print "Welcome to the ultimate calculator."'
 
 # vim: ft=python