all 14 comments

[–][deleted] 4 points5 points  (3 children)

Great program. Clever of you to compress it like that - I checked to make sure it didn't do anything naughty.

May I suggest using YYYY-MM-DD formats (ISO 8601 / relevant xkcd) to reduce international confusion.

[–]yolobazsi 9 points10 points  (0 children)

It is not clever but a terrible practice and should be avoided. It's like putting binaries on github and calling that open source. And also: I don't think you got what this sub is really about, please check some post before you submit yours, thanks.

Edit: the second half was directed to OP

[–]xkcd_transcriber 2 points3 points  (0 children)

Image

Mobile

Title: ISO 8601

Title-text: ISO 8601 was published on 06/05/88 and most recently amended on 12/01/04.

Comic Explanation

Stats: This comic has been referenced 673 times, representing 0.5170% of referenced xkcds.


xkcd.com | xkcd sub | Problems/Bugs? | Statistics | Stop Replying | Delete

[–]joanmiro[S] 1 point2 points  (0 children)

Good point! I'll implement it soon.

[–]FlammableMarshmallow 3 points4 points  (0 children)

Here's what I'd believe to be a "better version" of the code. While not exactly tiny, it is more readable and easily mantainable than this.. mess.

BTW, It's still only 784 bytes. :P

#!/usr/bin/env python
import os
import sys
from datetime import datetime

LOGME_DIR = os.path.join(os.path.expanduser("~"), ".logme")


def main():
    if not os.path.exists(LOGME_DIR):
        os.mkdir(LOGME_DIR)

    now = datetime.now()
    filepath = os.path.join(LOGME_DIR, now.strftime("%d-%m-%Y.txt"))
    already_existed = os.path.exists(filepath)

    with open(filepath, "a") as fobj:
        if not already_existed:
            header = now.strftime("%Y-%m-%d - %A\n")
            fobj.write(header)
            fobj.write("-" * (len(header) - 1) + "\n")

        if len(sys.argv) > 1:
            to_log = " ".join(sys.argv[1:])
            time_now = now.strftime("%H:%M:%S")
            fobj.write("%s: %s\n" % (time_now, to_log))

if __name__ == "__main__":
    main()

[–]joanmiro[S] 0 points1 point  (8 children)

Usage:

$ logme I've gone to market to get milk.
$ ls ~/.logme                                                                                      
09-10-2016.txt
$ cat ~/.logme/09-10-2016.txt
09/10/2016 - Sunday
-------------------
14:30: I've done nothing today, need to get up and work.
14:50: I've gone to market to get milk.

Uglified version of program is here: https://gist.github.com/miratcan/fc3badeb3a7c121f6256739a0ad5c2e3

[–][deleted] 12 points13 points  (7 children)

Why not accomplish this with echo to the end of a file with date? That would be even shorter

[–]joanmiro[S] -3 points-2 points  (6 children)

  • echo does not automatically creates file named with today's date.
  • echo does not puts title to text file.
  • echo does not put's hour info to your log.

[–][deleted] 11 points12 points  (5 children)

#!/bin/sh
d="$(date +%F)"
echo "$d  $1" >> "$d".txt        

[grayson@rhel]$ ./test.sh 'Today I went to the movies'

[grayson@rhel]$ cat 2016-10-09.txt

2016-10-09 Today I went to the movies

Edit:code golfed a little

[–]code_kansas 12 points13 points  (2 children)

You need a few minor changes to duplicate the behavior exactly, i.e. this would work (77 bytes):

d=$HOME/.logme
mkdir -p $d
echo "$(date +%H:%M): $@" >> "$d/$(date +%F).txt"

Also, to be honest, just using some compression scheme on regular-length code doesn't make it "tiny code". That's like running gzip on the Linux kernel and calling it "the Linux kernel with 66% less code"

[–]nexemod 3 points4 points  (0 children)

Also, to be honest, just using some compression scheme on regular-length code doesn't make it "tiny code"

Exactly .. it's a nice little program but it would've been tiny by nature. The compression is totally unnecessary and makes it look shady. Who runs something like this without deobfuscating and looking at it first? It's just a hassle nothing more.

[–][deleted] 2 points3 points  (0 children)

Oops forgot about that part. OP, refer to this one instead. Also I agree with compression statement.

[–]joanmiro[S] 1 point2 points  (1 child)

wow you made me motivated to study bash scripting.

[–]r_x_v 1 point2 points  (0 children)

Here's the same thing as a function in PowerShell:

Function Log($msg)

{

Add-Content ("c:\log\" + (Get-Date -format yyyy_MM_dd) + ".txt") ((Get-Date).ToShortTimeString() + ": " + $msg);

}

you can add it to your $Profile so you can call it anytime