Got a sudden insight now :-)
x=[11,22,33,44]
To get last element, we use x[-1]
Instead of using the negative index directly, we can use the bitwise NOT operator ~, since ~0=-1 and ~1=-2 etc!
So you can simply say x[~0] to access the last element, x[~1] for last but one etc.
[Hacker News discussion]
Showing posts with label tip. Show all posts
Showing posts with label tip. Show all posts
Thursday, March 27, 2008
Monday, February 18, 2008
GNU date
I didn't know that you can use date strings with this tool
kiru@kiru-laptop:~$ date
Mon Feb 18 07:25:16 PST 2008
kiru@kiru-laptop:~$ date --date "ten years ago"
date: invalid date `ten years ago'
kiru@kiru-laptop:~$ man date
kiru@kiru-laptop:~$ date --date="ten years ago"
date: invalid date `ten years ago'
kiru@kiru-laptop:~$ date --date="10 years ago"
Wed Feb 18 07:25:57 PST 1998
kiru@kiru-laptop:~$ date --date="10 years and 12 days ago"
date: invalid date `10 years and 12 days ago'
kiru@kiru-laptop:~$ date --date="10 years 12 days ago"
Tue Feb 6 07:26:28 PST 2018
[more info]
Human friendly date strings are awesome. It would be a nice feature to have in my webapps. I need to wrap this GNU tool in Python/Javascript code. I wonder if there is one already.
kiru@kiru-laptop:~$ date
Mon Feb 18 07:25:16 PST 2008
kiru@kiru-laptop:~$ date --date "ten years ago"
date: invalid date `ten years ago'
kiru@kiru-laptop:~$ man date
kiru@kiru-laptop:~$ date --date="ten years ago"
date: invalid date `ten years ago'
kiru@kiru-laptop:~$ date --date="10 years ago"
Wed Feb 18 07:25:57 PST 1998
kiru@kiru-laptop:~$ date --date="10 years and 12 days ago"
date: invalid date `10 years and 12 days ago'
kiru@kiru-laptop:~$ date --date="10 years 12 days ago"
Tue Feb 6 07:26:28 PST 2018
[more info]
Human friendly date strings are awesome. It would be a nice feature to have in my webapps. I need to wrap this GNU tool in Python/Javascript code. I wonder if there is one already.
Subscribe to:
Comments (Atom)