úterý 20. května 2014

Chrome native messaging on windows

Problem:
When developing extension using native messaging you need to develop so called native messaging host - exe which is registered with chrome and  spawned by chrome when requested by the extension.
Chrome uses pipes to communicate with the host. The pipe is connected to stdin/stdout descriptors in the host process.
There is a drawback on windows - default stdin mode is TEXT. But in this mode once 0x1A is passed through, the C library closes the pipe and the host is terminated because 0x1A id end of file marker.

Solution:
Before reading attempt from the pipe set the mode to binary (defaults to text) using following code snippet:

_setmode( _fileno( stdin ), _O_BINARY )

Reference: http://msdn.microsoft.com/cs-cz/library/tw4k6df8.aspx

čtvrtek 10. dubna 2014

Convert SSH public key to a form for .authorized_hosts

Evary time i need this command it takes me minutes to retrieve the right form from my memory. Let's take a note :)

ssh-keygen -i -f pem -f ~/.ssh/id_rsa.pub

neděle 23. března 2014

Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt - Solved

No Visual Studio 2012 installed just SP1 of Visual Studio 2010.

Found this (no solution, but direction): http://stackoverflow.com/questions/10888391/error-link-fatal-error-lnk1123-failure-during-conversion-to-coff-file-inval

But it did not help.

Found this(almost solusion): http://social.msdn.microsoft.com/Forums/vstudio/en-US/d10adba0-e082-494a-bb16-2bfc039faa80/vs2012-rc-installation-breaks-vs2010-c-projects?forum=vssetup

It pointed me to the root cause - bad version od cvtres.exe which depends on missing msvcr100_clr0400.dll.

Solution: downloaded http://www.dll-files.com/dllindex/dll-files.shtml?msvcr100_clr0400

I downloaded the right version (32bit) of the file and stored it next to cvtres.exe and BINGO!!! compiling with no error.

Sahme on MS ... and shame on MS problem resolution culture. Searching the root cause is seldom seen. Uninstall/Reinstall is the only advice in most of dicussions.
 

 

neděle 8. září 2013

... chromcast like experience on smart tv

No dongle is needed to experience chromcast on SmartTV. In my case LG brand. The youtube app on the TV sucks. It's slow realllyyy sllooow. It's hard to use using only the tv remote. It's hard to use even using much better smart phone remote.       Now ... it is easy to send the youtube video from smart phone youtube app to she big screed of the smart tv.

Try it if you can!

pondělí 19. srpna 2013

... čajnafoun

... dorazil balík z dx.com obsahující telefon N6300. Cena podle kurzu Paypal 3814Kč ($184.60). Po připočtení služby České pošty v rámci celního řízení (180Kč, ale v balíku toho bylo víc, takže do ceny telefonu promítnuto jen částečně) a vyměřeného cla a DPH je reálná nákupní cena 4780Kč.

Telefon dorazil se dvěma kryty - jeden klasický "tenký" - jen zadní kryt. Druhý je pro "tlustší" variantu s větší baterkou a zkládá se ze zadního krytu a z přiklápěčího krytu displeje.

Telefon dorazil se dvěma bateriemi - jedna 1800mAh pro použití s "tenkým" krytem a druhá 2500mAh pro použití s "tlustším" krytem.

Balení dále obsahuje sluchátka, čínský nabíjecí adaptér, USB kabel a již nalepený screen protector.

UPDATE: Nevýhoda čajnafounu se ukázala díky mé nešikovnosti. A teď se nesmějte, protože to bude smutný příběh. Čajnafoun mi spadl do polevky. Fakt. A konektorem napred. A od te doby ... spise nefunguje, nez funguje. Takze jsem musel rychle hledat nahradu. A našel jsem téměř shodně vybavený trochu menší Gigabyte Aku A1. A při nákupu mi nabídli pojistku proti pohromám za 500Kč příplatek. A protože jsem stejnou pojistku využil nedávno u telefonu dětí, kývnul jsem na ni. V případě pádu do polévky by mi ho opravili za drobnou spoluúčast.

čtvrtek 8. srpna 2013

Installing GlusterFS 3.4 on Fedora 19

I was trying to install GlusterFS on Fedora 19. There were some problems which I describe here.

At first ... disable SeLinux on every Gluster node by changing /etc/selinux/config and set entry SELINUX=disabled

Packages of GlusterFS are part of Fedora 19 repository. Installation is easy.
I used following command:

sudo yum install glusterfs glusterfs-api glusterfs-fuse \
   glusterfs-server glusterfs-geo-replication 

After the packages are installed glusterd service is started. To connect the cluster nodes following command need to be issued:

sudo gluster peer probe the-other-node-ip 

But the command failed:

peer probe: failed: Probe returned with unknown errno 10

After some research using resources mentioned bellow I found the source of the problem (as usually): the firewall. Fedora 19 (and 18 already) includes firewalld.

Thing twice before changing your firewall settings. As I use virtualization and host only networking, I moved my host-only interface to the trusted zone:

sudo firewall-cmd --permanent --zone=trusted --add-interface=p7p1
sudo firewall-cmd --permanent --zone=trusted --change-interface=p7p1
sudo systemctl restart firewalld.service

To verify interface move submit:
 
sudo firewall-cmd --zone=public --list-all
sudo firewall-cmd --zone=trusted --list-all



References:

středa 7. srpna 2013

Psycho v letním kině

Dnešní promítání Psycho v letním kině mělo neopakovatelnou atmosféru. Ve chvílích, kdy film graduje se zvedl vítr přicházející bouřky .... ve scéně s Normanovou matkou ve sklepě se plátno divoce vlnilo ve větru a umocňovalo tak atmosféru filmu. Těsně před koncem plátno poryvům větru neodolalo a padlo. Úplně poslední scény s detailním záběrem do tváře Normana jsme sledovali na stěně domu daleko za původním plátnem a obličej byl tudíž obří .... nádhera.

neděle 4. srpna 2013

Convert Windows 7 Professional SP1 image from VMWare Workstation 8 to VirtualBox

I tried to  convert Windows 7 Professional SP1 running as guest in VMWare Workstation 8 to Oracle VirtualBox. The suggested scenario is to use ovftool from VMWare distribution to create OVF machine and VMDK disk image.

At the VirtualBox side the scenario suggests to Import appliance. Unfortunatelly the process fails with message "Could not find a storage controller named 'SCSI Controller'."

After some research following steps lead to working Windows guest in VirtualBox based on exported VMWare image.

I created VirtualBox machine from scratch with all settings left with their default values except memory (enlarged to 1GB) and I attached existing VMDK disk image created with ovftool (see above). Windows guest boot failed in BSOD until the disk was attached using SAS controler with LsiLogic type.

neděle 7. července 2013

Convert XML to CSV example

Input CSV

 <?xml version="1.0" encoding="utf-8"?>  
 <detail id="1243">  
  <nazev>Praktický lékař pro dospělé</nazev>  
  <jmeno>MUDr. Nomen Omen</jmeno>  
  <adresa>Street 1/234, 18000 City 8</adresa>  
  <telefon>89879076</telefon>  
  <fax/>  
  <ico>8908078</ico>  
  <poradove-cislo>000</poradove-cislo>  
  <poradove-cislo-det-prac>000</poradove-cislo-det-prac>  
  <nazev-zrizovatele>Fyzická osoba</nazev-zrizovatele>  
  <druh-zz>320 Samost.ordinace prakt.lék.pro dospělé</druh-zz>  
  <email>nomen-omen@mailer.ru</email>  
  <www/>  
 </detail>  

XSLT template file - takes one parametr output-header - when true, header is output first, output is Tab separated, no escaping nor quoting is done

 <xsl:stylesheet version="1.0"  
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
  <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>  
  <xsl:param name="output-header" value="false"/>  
  <xsl:template match="/">  
   <xsl:if test="$output-header='true'">  
    <xsl:value-of select="concat('id','&#x09;')"/>  
    <xsl:value-of select="concat('type','&#x09;')"/>  
    <xsl:value-of select="concat('nazev','&#x09;')"/>  
    <xsl:value-of select="concat('jmeno','&#x09;')"/>  
    <xsl:value-of select="concat('adresa','&#x09;')"/>  
    <xsl:value-of select="concat('telefon','&#x09;')"/>  
    <xsl:value-of select="concat('fax','&#x09;')"/>  
    <xsl:value-of select="concat('ico','&#x09;')"/>  
    <xsl:value-of select="concat('poradove-cislo','&#x09;')"/>  
    <xsl:value-of select="concat('poradove-cislo-det-prac','&#x09;')"/>  
    <xsl:value-of select="concat('nazev-zrizovatele','&#x09;')"/>  
    <xsl:value-of select="concat('druh-zz','&#x09;')"/>  
    <xsl:value-of select="concat('email','&#x09;')"/>  
    <xsl:value-of select="concat('www','')"/>  
    <xsl:text>  
 </xsl:text>  
   </xsl:if>  
   <xsl:for-each select="//detail">  
    <xsl:value-of select="concat(@id,'&#x09;')"/>  
    <xsl:value-of select="concat('detail','&#x09;')"/>  
    <xsl:value-of select="concat(nazev,'&#x09;')"/>  
    <xsl:value-of select="concat(jmeno,'&#x09;')"/>  
    <xsl:value-of select="concat(adresa,'&#x09;')"/>  
    <xsl:value-of select="concat(telefon,'&#x09;')"/>  
    <xsl:value-of select="concat(fax,'&#x09;')"/>  
    <xsl:value-of select="concat(ico,'&#x09;')"/>  
    <xsl:value-of select="concat(poradove-cislo,'&#x09;')"/>  
    <xsl:value-of select="concat(poradove-cislo-det-prac,'&#x09;')"/>  
    <xsl:value-of select="concat(nazev-zrizovatele,'&#x09;')"/>  
    <xsl:value-of select="concat(druh-zz,'&#x09;')"/>  
    <xsl:value-of select="concat(email,'&#x09;')"/>  
    <xsl:value-of select="concat(www,'')"/>  
    <xsl:text>  
 </xsl:text>  
   </xsl:for-each></xsl:template>  
 </xsl:stylesheet>  

Customization: use your own element names, template matching rule and whatever to process more complex XMLs. Keep the structure (spaces, line ends) of the  tailing <xsl:text> to get proper line ends at the right places.

pondělí 10. června 2013

Create independent distribution of certain cygwin utility

In some cases you can find some cygwin utility useful for windows and you don't want or can't fully install cygwin. There is a handy utility called cygcheck which you can use to extract information about  certain cygwin executable dependencies. You can use the information to create standalone distribution directory of the utility. Following command extracts xmllint utility into /tmp/distro with all dependant DLLs.

mkdir /tmp/distro && cygcheck $(which xmllint) | \
grep cygwin |sed -e "s/^ \\+//" | \
cygpath -f - | \
while read x; do cp -v $x /tmp/distro; done


pátek 18. ledna 2013

... a way out of Windows symlink permission hell

For some reasons we needed to create symlinks on a Windows fileshare. Our environment was symlink ready (Win7 & WinServer 2008R2 & SMB2 everywhere). We started to try ... it sometimes worked sometimes not. Sometimes we received "You do not have sufficient privilege to perform this operation". Frustrating.
Finally we managed to make it working. We can now create symlinks from our server app directly in a shared folder.

Prerequisites
  • Windows 7+ and Windows Server 2008 R2 + and SMB2 enabled

Fileserver setup
  • the user willing to create symlinks must be 
    • granted "Create symbolic link" privilege (use Local Security Policy tool on the server)
    • granted modify right for the folder containing the symlink
Client setup
  • the user willing to create symlinks must be granted "Create symbolic link" privilege (use Local Security Policy tool on the client)
  • the right to  create symlinks must not originate from Administrators group -> the right must be granted directly to the user or indirectly via a security group
  • the user should not be a member of the Administrators group or the Administrators group should not bring the Create symlink permission (UAC disables the permission when it comes from the Administrators group --- UAC is EVIL)
  • depending on the link type used, the client computer must be able to resolve symlinks of certain type
    • turn symlink evaluation on using command (enables all kind of symlinks)
      • fsutil behavior set symlinkevaluation L2L:1 L2R:1 R2L:1 R2R:1 
If everything goes well you should be able to invoke following command to create directory symlink:

mklink /d \\server1\links-are-here\this-is-a-link \\server2\data-are-here\this-is-a-link-target

sobota 15. prosince 2012

... relativita v praxi

V roce 2009 zemřelo v USA 33 800 lidí při dopravních nehodách (zdroj). V průměru ~93 mrtvých denně. Málokdy si jich někdo všimne.

čtvrtek 29. listopadu 2012

Zákony pro lidi

... konečně ... asi pozdě jsem našel ...  už nějaký čas fungují http://www.zakonyprolidi.cz
je smutné, že podobnou aplikaci nevytvořila státní správa, ale komerční organizace. 

úterý 31. července 2012

... a pak že nerostou ....

Nestyďte se zaslabší zrak, a klidně si kliknětě pro plnou velikost fotky.



pátek 25. května 2012

Windows ACL hell solution

Error message "Access denied" makes me crazy. Whenever I see this message unexpectedly on windows computer I know that next few minutes/hours will be painful.

Windows access rights apparatus is overcomplicated for most uses. When advanced settings are combined with inheritance. When playing with ACLs man gets easily at the edge madness.

After several tries things are getting worse and worse. You can end up with a folder you can't do anything with. No rights left to you even if you are member of the Administrators group.

Following three steps should help in most cases (There are rare cases it will not help connected mainly to inability in taking ownership). Being administrator is the only prerequisite.

Steps to survive ACL hell:
  1. Taking the ownership - As a member of Administrators group you have all the power to own anything (any object) on a local system. And when there is another owner you can seize the object at your will. 
    • takeown /F file-or-folder 
    • you can use /R to do it recursively 
  2. Reseting rights - After membership is taken it is possible to get rid of all explicitly assigned ACLs using.
    • icacls file-or-folder /reset /T
  1. Test effective rights - using file Properties tab Security button Advanced tab Effective permissions - you can test whatever user you want and get his or here effective permissions.

Good luck!

 

čtvrtek 24. května 2012

...obětování plechovým bohům

... dnes před desátou na Jižní spojce probíhal obřad obětování plechovým bohům. V kruhu alegorických vozů s modrými blikajícími světly uprostřed rozpáleného asfaltového pruhu ležela oběť. Nehybná v paprscích zářícího slunce s nákrčníkem. U oběti v nábožné úctě v pokleku několik ceremoniářů dohlíželo na obřad. V obětišti jakoby se čas zastavil. Od obětiště se táhla dlouhá řada účastníků. Někteří ukrytí uvnitř svých plechových bohů, někteří poblíž.

středa 28. března 2012

... dsquery needs to be elevated to query memberOf

Today after an hour of pain I have discovered weird beavior od dsquery command. I was trying to reproduce my yesterday work. Yesterday I queried users based on their membership using following filter in dsquery *.

(&(objectClass=inetOrgPerson)(memberOf=GROUPDN))

Yesterday it worked. Today .. no user is found. After a fair ammount of time I found a solution. Queires containing memberOf as part of the filter need to be executed inisde ELEVATED prompt.

Let me scream again .. UAC on the server is EVIL.

pátek 2. března 2012

Arduino Uno serial communication

Disclaimer: following procedure worked for me. Obviously there is no  guarantee that it will work for you but there is pretty high probability of success. Improper handling can damage or destroy the board but it is unlikely. 

Great little Arduino has one drawback for "production" operation. After (USB)serial port is connected from PC, the unit resets.

The feature is suitable for development - each serial connect enables upload of the code. But it is annoying during production when you may need to connect to your Arduino to collect data. There is a HW solution.

There is a RESET-EN trace on the board (see below - it is located in the green circle marked with RESET-EN label). When the RESET-EN trace is cut (see the red line below - be rough enough when cutting to be sure it is cut) the serial communication initiated resets are disabled. The trace can be soldered again in the future (see Arduino.cc section Automatic (software) reset for reference).



After the RESET-EN trace is cut PC can connect and disconnect the serial and Arduino does not reset. On Linux simple shell scripts can be used to collect the data. Attention - uploading the new code to the Arduino might be a little less comfortable. To upload the new code use the following procedure (i can't find the link of the site where I have discover this procedure):
  1. prepare the sketch in the Arduino IDE
  2. place the mouse pointer at the upload button on the screen
  3. press and hold reset button on the Arduino board 
  4. fix your eyes on RX LED on the Arduino board
  5. click the upload icon in the Arduino IDE
  6. look at the RX LED and after it flashes once release the reset button
  7. look at the Arduino IDE to whether upload was successfull
  8. when the upload fails don't worry and try again with a little different timing of reset button release
  9. it needs little practising but it definitely works for me
  10. ... be patient :-)     
Or you can use alternative approach :
  1. prepare the sketch in the Arduino IDE
  2. place the mouse pointer at the upload button on the screen
  3. look at the status bar of the Arduino IDE
  4. press upload button 
  5. "Compiling sketch ..." will be displayed in the status bar
  6. After several seconds it changes to "Uploading ..."
  7. Press reset on the Arduino board as soon as possible after "Uploading .." comes up
  8. keep practising and you will succsseed

At first the correct serial setup is needed. To setup serial port to be readable using shell utilities use:

stty -F dev/ttyXXX cs8 9600 raw

And then you can use basci text utils to process Arduino output. To read 5 lines from Arduino to a file use:

cat /dev/ttyXXX | head -n 5 > data.txt

And to write command to Arduino just:

echo -n CMD > /dev/ttyXXX

Good luck ...



čtvrtek 22. prosince 2011

... telepatie na venkove

Ve venkovské hromadné dopravě se setkávám s řidiči telepaty. Nastoupím do autobusu, požádám o lístek a řidič kouka. A já koukám. A řidič kouká a mlčí a čeká, až zaplatím. A já mlčím a koukám a čekám, až sedozvím, kolik mám zaplatit. Snaží se mi řidič sfělit cenu ponocí mimosmyslového vnímání? Pokud ano, fatálně zklamu. Potupen prokázanou neschopností přijmout myšlenkovou zprávu použiji nakonec zastaralou metodu založenou na hlasivkami řízené rozechvívání vzduchu a vyslovím otázku. Když platím částku spíše tušenou ze zabručení šoféra, připadám si, nepatřičně, porušuji místní zvyky - nutím řidič mluvit. Snad mi teď v době ánoc bude odpuštěno.

středa 21. prosince 2011