Please insert coin!

Archive for the ‘Misc.’ Category

Date Format Conversion

Sunday, June 11th, 2017

Shortcut: Javascript Date Format Conversion

I recently had trouble to convert a date column from a CSV file to another (sorting-friendly) format. In LibreOffice >=5.3.x. In my case I wanted to convert from M-D-Y with no leading zeros, “/” as separator and 2-digits year to something like “yyyy-MM-dd” (i.e. 4-digits year, leading zeros and “-” as separator) for importing the file to another CSV file. I wanted to sort this document by date which doesn’t work with the M-D-Y format.

What I had: M/D/Y, no leading zeros, slash-separator, only two-digits year)

What I wanted: Y-M-D, leading zeros, – as separator, 4-digits year

 

What I got (nothing happened at all… )

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I have tried numerous combinations of CSV import options and conversion parameters. I have spent some time googling for solutions, but most of them were dirty hacks and provided no permanent solution. Maybe it is related to the fact that my Ubuntu’s language is set to English(US) but the date/time/number formats are set to German. In the end I gave up.

And made this:

jdfc

Javascript Batch Date Format Conversion https://dfc.dennis2society.de

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Javascript Date Format Conversion



Yii 2 – Redirect / Reload on krajee DatePicker changeDate event

Saturday, March 5th, 2016

During my experiments with the Yii2 framework and krajee’s DatePicker widget I wanted to implement a pretty common use-case where the current page reloads with the newly selected date from the DatePicker as a $_GET parameter. It took a few hours to find the correct variant in the bootstrap docs (my initial mistake was to search in the jquery docs). So I am rewriting it here.

This is how I did it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
    // My auto-reloading DatePicker
    echo "<label class=\"control-label\">My Auto-Reload DatePicker</label>\n";
    echo DatePicker::widget([
        'name' => 'auto_reload_date_picker',
        'id'  => 'auto_reload_date_picker',
        'type' => DatePicker::TYPE_COMPONENT_PREPEND,
        'value' => Yii::$app->request->get('date'),
        'pluginOptions' => [
            'autoclose' => true,
            'format' => 'yyyy-mm-dd',
        ],
        'pluginEvents' => [
            'changeDate' => 'function (e){
                var date = $("#auto_reload_date_picker").val();
                location.href = "/index.php?r=site/my-action&date="+date;
             }',
        ]
    ]);

I had some trouble finding the correct expression for the contents of “function (e) { ….}”. This works quite well, even when there’s no $_GET parameter given initially. There’s a related question on krajee’s demo page asking for almost the same.

You probably have to adjust “my-action” in the “location.href” assignment.



Ubuntu 14.04 doesn’t recognize laptop battery ( Dell Inspiron 15 7537 )

Sunday, June 8th, 2014

UPDATE: Apparently this workaround is not working anymore. I gave up on searching any further.

This took a few weeks to figure out so this is again another reminder for myself:

Symptom:

On a fresh install of Ubuntu 14.04 on a Dell Inspiron 15 7537, Ubuntu fails to detect the laptop battery when running on battery, thus the battery indicator is missing. The only way to temporarily fix this was to connect the AC power supply for a few seconds. Even after removing the power supply the battery indicator remains where it should be. Confusingly “dmesg” still reports the battery “BAT0” as “absent”….

After digging around in discussion boards and Ubuntu’s Launchpad I have finally found a solution that works for me (the essential hint came from here: https://bugs.launchpad.net/ubuntu/+source/upower/+bug/1088146/comments/13 ):

Simply add the option acpi_osi=Linux to your GRUB commandline.
To make this a permanent solution you can edit the file /etc/default/grub and append the option to the line

GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”
so that it looks like this:
GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash acpi_osi=Linux”

Don’t forget to run update-grub2 to regenerate the grub menu.



OpenCV’s TextureFlow Example in C++

Friday, March 29th, 2013

OpenCV's TextureFlow example screenshot (C++ variant)

OpenCV’s TextureFlow example screenshot (C++ variant)

 

Since version 2.4.3 OpenCV has a nice example for generating a texture flow image from an input image. This generates a grid-like distributed edge-gradient image from the input. Unfortunately this example is in Python with no C++ translation available. A while ago I have made an attempt to translate this to C++. The result is not 100% identical to the Python variant, but close enough:

 

 

 

 

 

Read the rest



QTetraMesher – A Tetrahedral Mesh Generator for Windows and Linux using Qt

Thursday, March 7th, 2013

This is a Qt-based program for Windows and Linux to generate tetrahedral meshes for finite element simulation from various surface mesh formats. It also offers a fast and easy-to-use mesh viewer based on QGLViewer and allows basic mesh manipulations (currently only scaling is possible). Two different methods for tetrahedralization are possible: Delaunay Triangulation and Johnathan Shewchuk’s Isosurface Stuffing algorithm.

This project has its own page: http://qtm.dennis2society.de/

qtm_with_CGAL_options_small qtm_with_stuffing_options_small



Painless Tetrahedral Barycentric Mapping in C++

Sunday, August 14th, 2011

Screenshot of a liver surface mesh mapped to a tetrahedral mesh

This article provides a set of functions to generate barycentric coordinates for surface mesh vertices in relation to a tetrahedral mesh. Additionally I provide some more functions to find the closest tetrahedron to a certain point P. As barycentric coordinates are invariant to translation, rotation and scaling, barycentric mapping is especially useful for efficiently updating a surface mesh according to an underlying deformable tetrahedral mesh.

This article was born out of frustration as I could not find any comprehensive guide on how to do this and I didn’t just want to “borrow” someone else’s code without really understanding what it actually does ( e.g. from SOFA Framework or PhysX SDK). It is primarily meant as an extended reminder for myself, but might be useful for other people dealing with tetrahedral meshes. This article will mostly contain a lot of code and only very few theoretical background and no mathematical proofs! At least that’s what I regard as “painless”. The advantage of my approach is that it simply relies on Vec3f and Vec4f types and avoids funny constructions like “MeshHash” as seen in the PhysX SDK. This will allow easy adaption to different VecXf type implementations and simplify integration into different applications.

For best understanding you should at least be familiar with the following concepts:
Read the rest



[2. Update] Tetrahedral Mesh Generation (GMSH) for SOFA

Tuesday, March 22nd, 2011

Update:

There is now a better variant, for this reason (and to get rid of download-crawlers… ) the download has been disabled.

 

During the past few months I have spent lots of time doing experiments using the SOFA framework. In the course of my work I came to the point when I needed some more tetrahedral meshes than those that came included with SOFA. For this reason I started to do some reasearch on how to generate tetrahedral meshes from surface meshes (such as .obj). There are in fact lots of papers available on how to do this, but none of them provided a publically available executable. Furthermore, common programs for tetrahedral mesh generation either do not support the GMSH format (which is at least my own favorite due to good support in SOFA), or require manual work because of wrong order in the tetrahedra indices or additional information that is incompatible with the GMSH format. Anyway, none of those tools provided a solution for surface-to-tetramesh generation.

The solution for tetrahedral mesh generation from .obj files was found with PhysXViewer that is included in Nvidia’s PhysX SDK. It is available for free, but requires registration. The PhysXViewer allows you to import a surface mesh in .obj format and generate a tetrahedral mesh in different resolutions with a simple button and some sliders.

UPDATE: To generate solid meshes you have to activate the “Iso SIngle” mode. Otherwise there will be only an outer layer of tetrahedra.

The resulting tetrahedral mesh can be exported as an XML file in the NXUStream2 format. This format simply has some XML-nodes containing the vertices and the tetrahedra-indices . As the tetrahedra-indices are in correct order, it was pretty easy to write a PhysX_NXUStream2_to_GMSH_converter tool.

Physx NXUStream2 to GMSH converter usage

Download: Download disabled (see above)

The downloadable archive contains the sourcecode, the VisualStudio-2008 project, a compiled binary of the resulting program and some demo files (a simple sphere .obj file, the NXUStream2 tetrahedral mesh and the conversion result in GMSH format).

This tool is using the TinyXML library.



Read-only iPod in Ubuntu

Monday, May 17th, 2010

Symptoms: When connecting your iPod to your Ubuntu-machine the device will appear in Rhythmbox/gtkpod/etc. as expected but you cannot delete/add files, as it is mounted read-only. Probably due to some filesystem-errors….

Shortly after connecting the iPod the command “dmesg” will show you something like this:

[  706.925751] usb-storage: device found at 4
[  706.925755] usb-storage: waiting for device to settle before scanning
[  711.924249] usb-storage: device scan complete
[  711.939968] scsi 54:0:0:0: Direct-Access     Apple    iPod             1.62 PQ: 0 ANSI: 0
[  711.941113] sd 54:0:0:0: Attached scsi generic sg3 type 0
[  711.950199] sd 54:0:0:0: [sdc] 950209 4096-byte logical blocks: (3.89 GB/3.62 GiB)
[  711.951777] sd 54:0:0:0: [sdc] Write Protect is off
[  711.951786] sd 54:0:0:0: [sdc] Mode Sense: 68 00 00 08
[  711.951791] sd 54:0:0:0: [sdc] Assuming drive cache: write through
[  711.954581] sd 54:0:0:0: [sdc] 950209 4096-byte logical blocks: (3.89 GB/3.62 GiB)
[  711.955859] sd 54:0:0:0: [sdc] Assuming drive cache: write through
[  711.955868]  sdc: sdc1
[  711.959341] sd 54:0:0:0: [sdc] 950209 4096-byte logical blocks: (3.89 GB/3.62 GiB)
[  711.960760] sd 54:0:0:0: [sdc] Assuming drive cache: write through
[  711.960768] sd 54:0:0:0: [sdc] Attached SCSI removable disk
[  712.263430] FAT: Filesystem error (dev sdc1)
[  712.263438]     fat_free_clusters: deleting FAT entry beyond EOF
[  712.263444]     File system has been set read-only
[  712.838734] FAT: Filesystem error (dev sdc1)
[  712.838738]     fat_get_cluster: invalid cluster chain (i_pos 241679)
[  712.838741]     File system has been set read-only
[  712.838746] FAT: Filesystem error (dev sdc1)
[  712.838747]     fat_get_cluster: invalid cluster chain (i_pos 241679)

I ran in to this problem several times, and until now I always had to install iTunes to re-format the iPod.

Today I have discovered that you can easily fix the corrupt filesystem using “dosfsck”:

sudo dosfsck -a -w /dev/[device_identifier] # ( e.g. /dev/sdc1 )



Wiimote Accelerogramm

Saturday, March 1st, 2008

Wiimote-AccelerogrammDas Wiimote-Accelerogramm stellt den zeitlichen Verlauf der Messwerte des Accelerometers im Wiimote in Form dreier unterschiedlich farbiger Kurven dar.
Die Messung erfolgt in Echtzeit. Beim überschreiten des darstellbaren Bereichs für die Zeit t erfolgt ein automatisches Scrolling. Nach dem Beenden der Messung kann der sichtbare Bereich wieder zurückgescrollt werden.
Das ganze funktioniert auch für die Nunchuk-Erweiterung.
Eine neue Messung überschreibt die vorhergehende!
Read the rest