7Zip Timestamp Archive in Explorer Context Menu

I sometimes create archives of folders I am working on when I am not sure if I’m going to break the folder.

I use 7Zip. It provides quite a few options for creating archives from folders via the Explorer Context Menu.

As this can get messy when you do this multiple times sometimes it would be nice if you could just use the context menu that creates an archive with the current timestamp.

That’s what I did! And you can get it now, too!

 

Prerequisites:

  • 7Zip Installation (if you use the  32 Bit version you might need to change some stuff in the script)
  • PowerShell
  • Probably admin rights for registry changes

Tested with:

  • Windows 10
  • 7Zip 64Bit
  • PowerShell 5.Something

Your results may vary.

Usage Example:

You are in the folder c:\temp and right-click the folder foo.

temp_foo

You left-click “TimestampArchive7z”.

contextmenu

A file named archive_foo_2016-09-28_104844.zip will appear in c:\temp.

archive_temp_foo

Installation

Manual Version
registry_edit.png

  • run regedit
  • 1) navigate to key HKEY_CLASSES_ROOT\Directory\shell
  • 2) right-click and add new key called TimeStampArchive7z or whatever you want to see in the context menu.
  • 3) right-click the new key and add sub-key called command
  • 4) Open the new sub-key, in the right lane double-click the (Default) entry
  • 5) Paste the following one liner:
    powershell.exe -NonInteractive -command "$v = '%v';$a = $v.split('\');$l = $a.length-1;$na = $a[0..($l-1)];$od = $na -join '\';$dn =$a[$l];$ts = $(get-date -f yyyy-MM-dd_hhmmss);$fn = -join('archive_', $dn , '_', $ts, '.zip');$alias = -join($env:ProgramFiles, '\', '7-Zip\7z.exe');set-alias sz $alias;$cp = -join($od, '\', $fn);sz a $cp $v"

 

Commented PowerShell code

The final line of the gist above (of course without the leading hashtag is also contained in the registry file in the automated installation below.

(this gist might be outdated at some point in time so preferably check https://github.com/timosperisen/TimestampArchive7z/blob/master/TimestampArchive7z.ps1 )

 

“Automated” Installation

Go to https://github.com/timosperisen/TimestampArchive7z

Get the archive ( clone or download)

Unzip it

Run the Install_TimestampArchive7z.reg to install the context menu entry.

Run the Uninstall_TimestampArchive7z.reg to remove it.

End of the tunnel

Q/A

  • Why short variable names?
    Because at the end the script is a big one liner separated by semicolons.
  • Why did you concatenate variables with -join?
    Because at the end the script is run with
    powershell -NonInteractive -command “[HUGE_ONELINER]” and escaping quotation marks there led to some problems.
  • The context menu appears but when I click it no zip archive appears
    If you haven’t installed 7Zip in the default location it might not work properly.
    You can change the -NonInteractive parameter in the call to -NoExit  in the install reg file. Then you need to rerun it and check what kind of error you see in the PowerShell window.

 

Ideas for extensions ( if you have nothing else to do)

  • Change the script to create a folder with the same name as the input folder somewhere on a different drive (or share ) and then always write the archive there.
    To avoid changes in the script use $env variables which you can easily change if you use a different location.
  • Use additional 7z arguments for compression rate, 7z files instead of normal zips, etc.

 

 

Brainfuck interpreter in JavaScript

“Brainfuck? Something wrong?”

Last week I somehow managed to come across brainfuck, the esoteric programming language,  again.  I had read about it some years ago and also had the idea once to make a brainfuck interpreter.

“Why??”

Why? Do we always need a rational reason? Maybe I just wanted to see if it will fuck up my brain or if I will stay mentally sane. Maybe I just thought it’s very funny. Maybe god decided I had to try to do it… nah… not in my reality… anyway…

“Yeah?”

Well… Last week I came across it again. Because I’m working much with PHP and Javascript these days I thought I could give it another try. Which language to pick? Well… PHP is a server side language. You need some sort of input for covering all commands of brainfuck. You could handle that with some Ajax-Requests. But what if something goes wrong (like an infinite loop?) . Well… PHP scripts get killed after 60 seconds or whatever the value in the ini-file or the override-setting in the source file is set to.  What about debugging? You could also handle that with Ajax. Anyway I didn’t even think about those questions until now. I just wanted to create a brainfuck interpreter and picked the language Javascript.

“So what is brainfuck?”

Brainfuck is a so called ‘esoteric programming language’ created by a Swiss guy named Urban Müller in 1993 (also check the wikipedia article).  A esoteric programming language is a fun thing. An instrument to practice logical thinking if you want. There’s even a ‘dialect’ of brainfuck for Orang-Utans called Ook!. Now that’s silly!

Brainfuck consists of 8 commands

  • You have two commands to move the pointer in memory ( > ,  < ) .
  • You have two commands to changed the values in the memory ( + , – ).
  • You have two commands to open/close loops ( [ , ] ). If memory[pointer] == 0 the loop will end. So you have to do some sort of loop-counter, else you will get an infinite loop.
  • You have two commands for output (.) and input (,) . The  dot “.”  will output the character based on the ASCII-value that is in the current memory location. The comma “,” will get a character from the user. The ASCII-value will be saved to the current memory location.

So …  you move around in memory and increase, decrease and display values. You can actually do very complex calculations like multiplication, division, etc. You just have to think how you can achieve that in brainfuck.

Examples

1)

++[>++<-]

++ Increase value of first memory cell two times = 2

[>++<-] loop until first memory cell is 0 , in every loop move to the second cell, add 2 to the second cell and then go back to the first cell and decrease its value with 1

In the end the first cell will be empty and the second cell will contain the value 4.

2)

We take example 1) and add some more code.

++[>++[>++<-]<-]

++ Increase value of first cell two times = 2

[>++ Move to second cell and increase value two times = 2

[>++<-] Move to third cell, increase value by 2, move back to second cell and decrease value by 1

<-] Move to first cell and decrease value by one.

These nested loops will increase the value of the third cell to 8. The other two cells will contain the value 0 because they were ‘used’ by the loops.

“Very interesting … bla bla bla …  and now?”


Now you can try this no my Javascript brainfuck interpreter here. The example program in the textarea displays a text. Just klick on the button “parse”.

If you find errors please tell me.

Happy coding. 😉


High Scalability

If you are interested in “How Things Are Done” then you maybe have thought about how some of the bigger websites work.

For a small, private website with a low number of page hits you don’t need big fancy systems.  One server or even a virtual server can be enough.

But what happens when you need to provide video-streaming like in Youtube, Daily Motion etc or all kinds of different services like you see them on Facebook? On the website http://highscalability.com/ you can have insight in some of those services. There’s a number of interviews with those people behind large websites. You get an idea what kind of problems can occur when you have more visitors on your website.

Have a look and enjoy.

from canvas-tag to captcha

canvas-tag

In the last month I asked myself if there was any possibility to draw primitives in JavaScript. There are no functions for that but as we all know people tend to get creative. They make things possible with the scarce resources they have. So there are people who have implemented Bresenham’s line algorithm (using DIV’s ) in JavaScript and built libraries for JavaScript to draw all kinds of primitives.

I searched further and then I came across a HTML-tag called <canvas> .  <canvas> is basically an unofficial (meaning, not yet standardized by W3C?) tag created by Apple some years ago. It is a canvas where you can draw on. You have several inbuilt functions for lines, rectangles, arcs, etc. There’s some examples online. One of the more awesome examples is http://canvaspaint.org/ . It basically is a Microsoft Paint in the web-browser. There’s a small tutorial about <canvas>at mozilla.org.

The first thing I tried to do was to make a simple drawing-example in JavaScript. I didn’t want to reinvent the complex Canvaspaint but to try it out and learn it. That’s how I started my ‘canvastest’-project. The whole thing is made using HTML, CSS and JavaScript. It’s very simple and doesn’t offer too many possibilities. You can draw Lines and Circles, change the line width and undo. In the lower part of the screen there’s a ‘logscreen’ which saves all actions for undo. If you have an idea how to extend it, feel free. Just take the source and extend it or transform it into something totally different. But if you do, please inform me. I’d like to see it!

canvastest screenshot:

canvas_test1

captcha

What does the <canvas>-tag have in common with captchas. But … what are captchas?

Captchas are those whirled up texts (which I often can’t decipher) and try to separate men (of course also women and children) from machines. The big web-companies (but not only) like Google, Yahoo, Myspace had to implement some sort of mechanism to sort out bots which create new accounts for spamming (remember this  monty python sketch?).

A human can decipher a whirled up text quite easily compared to a computer. But because new algorithms are created which offer better recognition it is getting harder to make good captchas. There’s even companies in India and China which offer captcha-solving for low rates. Some genius even started redirecting the captchas on porn-pages so those who want to see naked flesh first have to pump some blood in the brain and solve the captcha before ‘working out’. Not bad.

Anyway… what do I have to offer? While I played around with the canvastest I had the idea to make a graphical captcha. What about an image which displays a ‘path’ and needs to be clicked on each ‘waypoint’ to get a correct result. So the captcha basically is a bunch of connected dots and have to be clicked on in the right order to get the “Okay”. Sounds easy? I really don’t know how well the algorithms for detecting this are. Another idea was not to connect the dots but just place numbers near the dots so you know which to click first. You could also make a color code. Maybe that would be easily hacked but right now I have only made a working  version using simple dot’s connected with lines. The starting dot is colored white. Test  captcha test. I’ll maybe add a part of the code behind it in the near future.

Captcha test screenshot

captcha_test1

Bewitched Day

The beginning of today was nice. After 8 (yeah e-i-g-h-t!!!) hours of sleep I got up. I took a shower, drank a cup of coffee and took some spare batteries for my shitty old MP3-Player with me. I rode my bicycle  to the railroad station. I just got on the train. Feew. I almost got naked in the train to cool down. I wanted to change the batteries of my MP3-Player but… hooray. Wrong battery-size! No music for you! D’oh. At least I had my book with me and started reading. Opposite me there were younger people talking and talking and talking and I couldn’t ignore them. I checked my mobile phone and I couldn’t do anything. I turned it off, turned it on again and entered the wrong code 3 times. Hooray. In Bern I bought a 6-grain bun and took the bus to my working place. After work, I took the train home and switched to bicycle. In the middle of my way home the bicycle had a fatal error (the gear-changing unit or how ever it is called collided with the wheel.  I had to walk home. I thought .. huh … not the best day ever.. (There was also that school shooting in Finland).  But then I saw that I had gotten a postcard from a dear friend. And there was a late birthday present in a package, too. Hooray. The day wasn’t that bad after all. 🙂

HTML Codes, character encoding…

Have you ever had problems finding HTML codes for special characters like these (♠ ♣ ♥ ♦ ) fellas? Or have you searched for simple ASCII codes or unicode encoding? I found this page called lookuptables.com yesterday and it has quite a few different tables you can easily print out or visit when you need to know something. It even has stuff like encoding for braille. It’s quite handy because all those different code tables are on one website, easily accessable. Check it out.

deltaMouse 0.01

I was bored and had an idea for a small game.

The idea is to travel a target distance or at least approximate it very well with the mouse cursor. If you got it 100% you get 100 points for it. The less accurate your travel distance is the less points/score you get.Then you get a new target distance.

You can basically continue playing it forever if you want.  For the download check the quickly made homepage If you have ideas or find bugs just write a mail to deltamouse@kellerloch.org.

Here’s a screenshot of the game:

deltaMouse in action
deltaMouse in 'action' - click image to get to the homepage

PS: No, I don’t wanna win any beauty contests with this one 😛