Monday, November 7, 2016

10 Criterias to Judge a Good Milk Container

#1
Openability
BAD
This container is difficult to open. It require, at first to remove the blue cap. Then there is a small handle that need to be pulled. Sometime it breakes and the pulling action, due to the strenght required, may make you spill some milk
GOOD
This container is Easy to open knowing the method. Can be opened with two single steps using one hand while the other hold the bottle. The moviment are slow and would not cause any spill
#2
Closability
BAD
The cup net to be screwed to close so it requires some work. It is a separate object that can get lost. It doesn't seal the container ermetically but it gives the false impression that it does so someone may try to store it horizzontally causing milk to spill
GOOD
To close the container it is enough to fold it back. It doesn't seal ermetically but it is close enough

Tuesday, November 1, 2016

GPS nmea GPX (or KLM) converter for Google Maps

This script take large amount of GPS data in nmea format and convert into gpx format to import into Google maps.

I had large amount of data coming from a trip to Iceland and I wanted quicly import it on Google My Maps.

Google has a limit of 5 MB but my data was 90 MB.

To reduce the data the script

  • only export latitude and longitude
  • approximae the latitude and longitude values reducing the number of decimal digit
  • skeep points

There are two variables that you can adjust to get an putput file smaller than 5 MB. In my case the best compromise was

  • savePointsEvery = 4
  • precision = 6

This generate an ouput file of 4,5 MB

Using instead

  • savePointsEvery = 4
  • precision = 6

The output file was 6 MB

The output files are in the folder data.

Source

Find the source at https://github.com/lucamug/gps-converter

Example

This is the result after imported in Google Maps:


Thursday, October 20, 2016

Minimal List of Recipes

This is a minimal list of recipes that we all should learn

Italian

  • Frittata di patate
  • Frittata di zucchine
  • Rostinciana
  • Pollo con funghi secchi
  • Pollo con uovo e limone (fricassea)
  • Baccala con patate in umido
  • Fagiolini in umido
  • Arista
  • Braciole con limone
  • Crostini di fegatini
  • Insalata russa
  • Panzanella
  • Carciofi con pomodor e farina
  • Uova ripiene con tonno
  • Ribollita
  • Fagioli uccelletto (e salsiccia)
  • Crostini salsiccia e crostini
  • Minestra
  • Minestra di fermaggio e uova (stracciatella)
  • Palline di ricotta e spinaci
  • Sugo di Cinghiale
  • Trippa
  • Carciofi crudi con limone e parmigiano
  • Porcini pasta
  • Aspara pasta
Japanese
  • Shikoku Nabe
  • Ramen
  • Yakiniku salada
  • Oden
  • Kuri spaghetti
  • Yaki sakana
  • Yasai tame
  • Ika daikon
  • Shogayaki
  • Nikujaga
  • Shabu shabu
  • Tempura
  • Demiglas souce meet
  • Pilaf
  • Chahan
  • Shitakegohan
  • Tonjiro
  • Kozuyu
  • Osekihan
  • Daikon Sote
  • Corn Broccoli Becon

Monday, October 10, 2016

Downloading Google Spreadsheets with Javascript to Json

A small script to download a Google Spreadsheet with multiple worksheet in Javascript.

This is the script and the output in Json format



This is the test Spreadsheet

 

Sunday, October 2, 2016

CSS Responsive Mini-framework with Resizable sections

This is an experimental Sass/CSS mini-framework for building responsive sites with Resizable (Zoomable?) sections.

Resizable sections enlarge proportionally with the viewport size. These areas are based on relative CSS units as explained in Building Resizeable Components with Relative CSS Units.

I also wanted to have a minor-font-size-scaling, a small font increase that would apply to everything in the page.

Breakpoints are at regular interval. They can be customized but for the example below I have the first breaking point at 34em (544px) and the next with interval of 14em (224px).

The other breaking points are at 48em (768px), 62em (992px), 76em (1216px) and 90em (1440px).

Tuesday, September 27, 2016

Are all html element closed? Testing it with Javascript

This small snippet check if all html tags are properly closed.

The html can be passed as a string or as an array containing html strings. It is based on the work of Jonathan Aquino that has an online form that has a similar script implemented: http://jona.ca/blog/unclosed-tag-finder

The script run both in NodeJS and in the browser console. I added also a function that allow to test the html coming from a server using the URL.

The usage is:

凸.checkHtml("your html here")

or

凸.checkHtml(["your html here", "and here"])

If you want to check a page served by a server:

凸.buildGetPageFunction()('http://example.com', function(data){console.log(凸.checkHtml(data))})

Saturday, September 24, 2016

Wait for Something - When Javascript onload event is not enough

Recently I needed to take actions on certain element of the DOM that would be created by other script and I also needed to take actions when images contained in these element where completed loaded.

The onload event seemed not fitting completely this purpose so I wrote this small function.
  • The function simply check the existence of the element (or any other condition) and when the condition is met, it execute the callback function.
  • If the condition is not met, it sets a timer to call itself again.
  • If after certain number of attempts the condition is still not met, the function stops.
Here some example on the usage.

Sunday, September 4, 2016

Minimum Font Size Checker

Simple script to highlight text that is rendered with a font smaller than certain threshold. .
Copy and paste the snippet in the console of any website and run the following commands.
To highlight the small fonts run:
凸.SmallFontChecker.highlight()
This will highlight in purple color all the text that is smaller than 14 pixels.
Is also possible to add two parameters: Minimum font size and color. For example:
凸.SmallFontChecker.highlight("13px", "red")
To restore to the original version you can run the command
凸.SmallFontChecker.reset()
After restoring the page you can run the highlight command with different parameters.
If the page adjust fonts size using proportional units (rem, em, vw, vh, vmin or vmax) you need to re-run the highlight command at every screen size that you would like to check.

How it Works

  • First the script traverse the entire DOM and check all elements to see if the font size is under the threshold. To do so it uses the global method getComputedStyle (Documentation: https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle)
  • If the font is under the threshold, it saves the inline style in "sfc-originalStyle" attribute so that the original style can be restored
  • Second it traverse the DOM again and change the font size and font color adding inline stiles.
  • It is two steps process because children elements are influenced by parent element the script would fail detecting small font in children
  • The recursive function to traverse the DOM is inspired by (copied from?) a script of Douglas Crockford (video)

Sunday, August 21, 2016

Balanced Responsive Grid

I needed to create a responsive grid of logos and this is what I have done.

Step 1

I started creating a simple html with the img nested in couple of divs. Then I used the old fashioned float left. Is possible to use flex boxes for a better result. The first result was horrible due to the fact that images have all sort of pixel size and ratio.


Step 2

To adjust the things I decided to go with the padding-bottom-trick. Having padding-bottom equal 100% insure that the hight of the div is always square because it relate to the width of the parent div.

The just making the image position absolute and adding some style fix the rest. I used max-width and max height = 75% because I wanted to leave some margin around the logo.


The page is much better but I want to limit the max-size of the logo to a certain value, let's say 200px.

Step 3

So I added some math to the Sass that would generated media queries. I started with logos occupying 100% of the screen, so as soon the screen reach 200px I needed to add a media query that would the logos going in two columns.

The media query is
@media (min-width: 200px) {
  .logo {
    width: 50%;
  }
}
When those two logos reach again the maximum width, the screen will be at 200px * 2 = 400px. Time to add a new media query:
@media (min-width: 400px) {
  .logo {
    width: 33.33333%;
  }
}
And so on. To simplify the list of media queries I first created a mixin like
@mixin mediaQuery($lev)
 @media (min-width: $max-element-size * $lev)
  width: percentage( 1 / ( $lev + 1 ) )
Then I created a loop that generate the media query with the mixin
@while $level < $max-levels
 @include mediaQuery($level)
 $level: $level + 1
Now the page adjust itself beautifully and logos width is never wider than 200 pixels.

This would be the conclusion of the exercise until I noted that some font look larger than other. It is just a feeling because the logo share all the same container. Well, probably not just a feeling but it depends on the shape of the logo and eventually on the area of the logo.


Step 4

So I was thinking to calculate the area of the logo to compensate the size but calculating the are may be not trivial as it depend on the shape of the logo and not just the size of the image. Round logos have less area compare to the squared one.

So I decided to use the aspect ratio to influence the size of the logo. I eventually came out with this formula:
Size of the image (percentage) = minPerc + 
    ((( maxPerc - minPerc ) / ( maxRatio - 1 )) * ( r - 1 ) );
Dove r is the ratio of the image that can go from 1 for squared logos to a very large number for rectangular logos. A logos of size 100px horizontal and 50px vertical would have a ratio of 100/50 = 2. The ratio in this case ignore if the logo is bigger horizontally or vertically. So, to calculate the ration I used this formula:
r = Math.min( Math.max(x,y) / Math.min(x,y), maxRatio );
Where maxRatio is the maximum ratio that I will take in consideration. In my example I use 4 so that all logos that have a side longer more than 4 times the other side will all be treated in similar way.

The calculation of a new percentage of the image require width and height of the logo. These values are available once the image is loaded so it would be reasonable to apply the new percentage on the onload event for each image.

Unfortunately the onload event for image has several issues so I decided to go for a much more inelegant way of just waiting, using timers, for when the sizes are ready. There are probably better solutions than this.

While waiting for the new percentage to kick in, I let the css style to resize logos to an average size. So, in my example I will change the size of images from 90% to 50%, depending on the ratio.

Logos contained in a squared shape with a ratio of 1 will have a percentage of 50%; rectangular logos that have one side 4 times or more longer than the other will have a percentage of 90%. Everything else goes in between these two limit cases.

This is the final result (note how the rectangular logos shrink and the square logo enlarge):



Saturday, July 23, 2016

Small Node/Javascript code to upload a file using sftp

This script upload a file using sftp. Before running it be sure to
  • Install NodeJS
  • Install ssh2 (npm install ssh2)
  • Fill the parameters at the top of the file
The script also list all the file in the folder before and after the uploading

Tuesday, May 3, 2016

A way to embed html in javasript

If you are not working with React and JSX, this could be a quick way to embed html inside Javascript...

Sunday, February 7, 2016

Intentional or not?

Happened to me several time that I buy food in a box with a nice picture on it and the content is very different from the picture.

Today I found a product with an actual window in the box where I could see the real product. So, no surprises!



But... it seems that the only two nuts inside were just in the position of the window.

Wednesday, May 13, 2015

Shortcut

I took this video along the path from the train station to my office. This path require walking through a Konbini (Convenience Store).

I found it very hilarious and I could not help laughing the first time I was walking it. I think it was a good business for the shop. They need to clean the floor more often but they would get many extra customers every day.

Sunday, November 9, 2014

SL只見線紅葉号 - Steam Locomotive in Japan

"Densha Otaku" (train nerd) while hunting a Steam Locomotive in Aizu. There are 36 type of densha otaku.

Friday, June 15, 2007

Yamanote Minuto - 山手線

The Yamanote Line is one of the busiest train lines in the world. Running in a circle around the heart of Tokyo, it carries 3.5 million passengers a day.




Tuesday, April 5, 2005

Mapping Topic Maps on Relational Databases

Abstract

Topic maps are a new ISO standard for describing knowledge structures and associating them with information resources, a solution for organizing and accessing large and continuously growing information pools (1). They are dubbed as the 'GPS of the information universe'. One possibility to permanently store Topic Maps is using Relational Databases. In this document I present a possible database schema that allows to store Topic Maps.
There are general rules to map DTDs to databases (2) but here I tried to build something ad hoc for Topic Maps. The result is a bit naive and cluttered (Figure 1). I was hoping I could find out a more elegant solution. If you have any suggestion or you know better database model please let me know.