Studying Revelation File Format: header
I used to have Revelation as Password Manager, on my loved debian laptop. Now I would love to hack on it to have a command line version to retrieve some password of the services I don’t use often and I don’t remember (actually some of them were auto generated and I never tried to remember them).
I started from the official wiki page with the file specs: https://bitbucket.org/erikg/revelation/wiki/FileFormatSpec
But I found this is not enough.. So I started looking at the source code..header format:
temp dir cleaner
I’ve just released one of the my scripts I use on my computers (laptops and servers).
I developed the first version of this simple script some years ago.. it was useful to keep clean a shared temporary directory of an internal server we used for file transfers.
Then, for some reasons, I simply lost it. Some months ago I decided to rewrite it, to automatically delete old temporary files on my laptop, since I started using “sleep” over “shut down”..
Now it’s hosted on github!
Code refactoring is “disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior
—Code refactoring from Wikipedia
S3 FILEMANAGER
I will republish here my blog post on mashape’s official blog regarding a software I’ve released today
——
Since the beginning we added the possibility to upload a logo to visually identify you and your API. To add this simple feature, from a code point of view, we designed an interface defining basic operations on the uploaded images: load, save, move and delete.
The first implementation was simple and fast to deliver: an abstraction of the local filesystem.
This is fine during the development phase, on our laptops, but obviously, you can’t scale with this solution: every server would have, locally, his own copy of the files.
So I’ve developed a new implementation, S3FileManager (based on he S3 library provided by http://www.jets3t.org ) to store data directly on the awesome Amazon service that we are already using for our static web part (css/images/javascripts).
We haven’t changed a single line of code on our website, except for a configuration file (filemanager.properties). To achieve this goal (and to allow us to change again, in case) this is our design (that can be improved):
Singleton design pattern on FileManagerFactory, with a single static instance that creates an instance of FileManager based on the class name found in a text file (a Properties configuration file).
In this way when we create different Tomcat instances, each of them will have a static FileManagerFactory to access to the same storage.
This simple library fits in our project, in our needs, so it’s not the best fit in every case. But it can be useful for other fellow developer, so here it is: https://github.com/Mashaper/file-manager
For example in other scenarios woule be better a dependency injection pattern instead of a singleton or maybe to avoid the fallback to the default filename ”filemanager.properties” when a getInstance() is called.
Just in case…fork it
Weather in London?
I’m leaving in minutes and going to London, for a couple of meetings and tomorrow’s PHP meetup.
So, I do not have much time, but I would like to take a look to forecasts in London.
I could browse to some websites, sure..but I’m a nerd and if something doesn’t involve coding it’s not fun and, moreover, Mashape has a beatutiful Weather API! :)
So:
- go to that API url http://www.mashape.com/component/Weather
- download PHP client library (or ruby, or python, or java, or objective-c or use it in json.. as you prefer.. I’m going to a PHP meetup, so I will use PHP!)
- unzip it in a directory of your choice
- enter the path where you unzipped it (you will see a Weather.php)
- open your favourite text editor
- this is the code I’ve written:
<?php
include “Weather.php”;
$w = new Weather(your-mashape-api-key);
$result = $w->getForecasts(“london”)->result;
foreach($result as $day) {
print $day->day_of_week.”: “.$day->condition.”\n”;
}
?>
Obviously, you have to put your Mashape API Key.. you will find it in the “account settings” section.
I’ve saved this file as client.php.. so I’m ready:
michele@erakis:~/Downloads/mashape-Weather-v1$ php client.php
Wed: Chance of Rain
Thu: Chance of Rain
Fri: Clear
Sat: Chance of Rain
Sh*t.. where is my umbrella?
simple mongo db backup script
Yesterday I was developing a new feature on Mashape and I wanted to backup my local DB.
So I wrote a small script to backup data of a list of sb (variable $DB) in a folder db-20110115 and to have it replicated on another pc in my LAN (just in case..) via ssh (with rsa key to be scheduled in cron).
#!/bin/bash
# CONFIGURATION
DBS=”db1 db2”
DUMP_LOCATION=~/backup
DIR_NAME=db-`date +%Y%m%d`
DIR_NAME_ABS=$DUMP_LOCATION/$DIR_NAME
COPY_SSH_DEST=server1:$DIR_NAME_ABS
##—
echo “Starting backup `date`”
for DB in $DBS
do
echo “Backup: $DB”
mongodump —db $DB —out $DIR_NAME_ABS
done
scp -r $DIR_NAME_ABS $COPY_SSH_DEST
echo “Backup Finished `date`”
If anyone is interested I plan to add compression and auto delete of data after two months
Adding disabled support to jquery.filestyle.js
We are using the filestyle jquery plugin to apply style to our input type=”upload” elements.
I needed to display in a properly way a disabled element, this is the diff of my small contribution:
49c51,53
<
—-
> if($(self).attr(“disabled”)) {
> $(filename.attr(“disabled”, “disabled”));
> }
57,58c61
< “display”: “inline”,
< “cursor”: “pointer”,
—-
> “display”: “inline”,
61c64,68
<
—-
> if(!$(self).attr(“disabled”)) {
> $(self).css({
> “cursor”: “pointer”
> });
> }
Two simple operations: I pass the attribute disabled to the “filename” variable, i.e. the input text box used as an overlay to the real upload element and i set the pointer cursor only if the original element wasn’t disabled