tag:blogger.com,1999:blog-87874581205277584992024-03-14T18:23:26.825+01:00Herikstad SolutionsSolutions to technical problems that I come across. Keywords: The Web, Ubuntu, Windows, JavaScript, jQuery, AngularJS, PHP, Java, C++, mySQL, noSQL, and more.Unknownnoreply@blogger.comBlogger130125tag:blogger.com,1999:blog-8787458120527758499.post-37859511370950032742019-03-26T13:13:00.001+01:002019-03-26T13:13:47.966+01:00Prevent and Mitigate Stack OverflowWhen programming micro-controllers you usually have to be more careful with your memory usage and also for smaller devices you often don't get any help from the hardware.<br />
<br />
On ARM micro-controllers the memory layout is such that the stack is placed at the higher address range of the memory and writes 'downwards' towards the lower memory addresses. While the heap fills up memory from the lower to the higher addresses. In cases of high use of static/program memory use, heap use and stack use, the stack can overflow and overwrite heap memory. This may result in weird and undefined behavior. This is bad.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBqmzo_QUHK1RX1sBPFovjL2pMLpNLnvRUT-T1jHNB3FHXJxsu5DgDS-iKtQ3tlg7JqQ5SfeUwaZQDCpvm2uN4QZ8MwEp54m0J7sJBPtEuQZPm-XOBjt3nfhU3TbZfdWE0FnCob7thECkD/s1600/stack_overflow.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="411" data-original-width="759" height="173" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBqmzo_QUHK1RX1sBPFovjL2pMLpNLnvRUT-T1jHNB3FHXJxsu5DgDS-iKtQ3tlg7JqQ5SfeUwaZQDCpvm2uN4QZ8MwEp54m0J7sJBPtEuQZPm-XOBjt3nfhU3TbZfdWE0FnCob7thECkD/s320/stack_overflow.png" width="320" /></a></div>
<br />Some methods that can be used to prevent this:<br />
<ul>
<li>Use the <b>HW memory protection unit</b>: HW unit that causes an interrupt or fault if stack is written passed a defined address.</li>
<li><b>Canary</b>: Write a unique value to address designated as top of stack and check that this value is still written to top of stack address in main loop.</li>
<li>Add <b>stack protection code</b>: GCC can add functionality to check wether writes to stack would overflow. Results in larger program binary and higher overall stack usage.</li>
<li><b>Stack depth analysis</b>: Compile time or static analysis of code to determine how much stack each function will use and combinations that would result in stack overflow. Some tools:</li>
<ul>
<li>GCC -fstack-usage, doesn't work in combination with -lto (link time optimization). </li>
<li>ARM compiler, with Keil microvision (uvision), but gives only one number for each interrupt level.</li>
</ul>
<li><b>Water mark</b>: Fill stack with pattern for each main loop to, check stack usage after each automatic test. Create tests that you think will cause the most high stack usage functions to execute (preferably simultaneously/interrupted).</li>
</ul>
<br />
Well known case of this: <a href="https://developers.slashdot.org/story/14/02/21/2349204/stack-overflow-could-explain-toyota-vehicles-unintended-acceleration">https://developers.slashdot.org/story/14/02/21/2349204/stack-overflow-could-explain-toyota-vehicles-unintended-acceleration</a> <br />
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-90280782180995366922016-04-18T13:36:00.000+02:002016-04-18T13:36:56.355+02:00Kerberos with groups on Tomcat 7To provide Single-SignOn (SSO) to your web service on a linux server
in a windows environment (Active Directory) you can add a login filter
to tomcat to accept Kerberos tokens. It's really quite simple, if you
set it up correctly, which is not simple to figure out.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdXcApdYreRVDbTg3qoyCvPz-RagUT2m8TM3kY9w6ZXgd6RJuXVIfUFpte82Y5bvoZ3C1ixSSd7L9p3Cb7Cov6nIvg6irMtQAU6xUeMl9mZxX_ADYYxQoT4LsogMFWRdipkVeFfk9yWXPB/s1600/kerberos-pac.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="293" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdXcApdYreRVDbTg3qoyCvPz-RagUT2m8TM3kY9w6ZXgd6RJuXVIfUFpte82Y5bvoZ3C1ixSSd7L9p3Cb7Cov6nIvg6irMtQAU6xUeMl9mZxX_ADYYxQoT4LsogMFWRdipkVeFfk9yWXPB/s320/kerberos-pac.png" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: #0000ee;"><u>Ack: Co<span style="color: #0000ee;"><u>mp<span style="color: #0000ee;"><u>iled from http://portlandlanguagecraft.com/ and https://pixabay.com/en/chain-gold-power-connection-rights-307886/</u></span></u></span> </u></span></td></tr>
</tbody></table>
<div style="text-align: center;">
<br /></div>
I did it using a custom SPNEGO filter to also extract AD groups from the kerberos tokens.<br />
<br />
Mostly follow <a href="https://tomcat.apache.org/tomcat-7.0-doc/windows-auth-howto.html">https://tomcat.apache.org/tomcat-7.0-doc/windows-auth-howto.html</a> but with many additional tweaks.<br />
<br />
You will need to create/edit the following files (On Ubuntu):<br />
<br />
<code>/etc/tomcat7/web.xml</code><br />
/etc/tomcat7/login.conf<br />
/etc/tomcat7/krb5.conf<br />
/etc/tomcat7/mykeytab.keytab<br />
/usr/share/tomcat7/libs/spnego-r7.jar<br />
<br />
(These files are also found in /var/lib/tomcat7/conf).<br />
<br />
Step-by-step (First section just for login and second section for getting groups too):<br />
<br />
<h4>
<b>AUTHENTICATION (Login):</b></h4>
<br />
Download the Spnego HTTP filter:<br />
Available from <a href="https://sourceforge.net/projects/spnego/">https://sourceforge.net/projects/spnego/</a>. Put the file under /usr/share/tomcat7/libs/spnego-r7.jar to make tomcat load it on startup.<br />
<br />
<b>On the Active Directory (AD) / Kerberos Key Distribution Center (KDC) / Windows server:</b><br />
<br />
Add service user:<br />
Add a service user to let you linux server "log in" and validate kerberos tokens.<br />
<br />
Link SPN to service user:<br />
SPN
(Service Principal Names) are identifiers for users or hosts. We need
to add the ones representing our server. NOTE: The SPN is case sensitive
and you must use the same case everywhere. The command is on the form:<br />
<span style="color: black; font-size: 10.5pt;"><code>setspn.exe -A HTTP/<HOSTNAME> DOMAIN\<SERVICE USER></code></span><br />
<br />
So on your windows/AD server enter the following <br />
<br />
<div class="MsoNormal">
<span style="color: black; font-size: 10.5pt;"><span style="color: black; font-size: 10.5pt;"><code></code></span>setspn.exe -A
HTTP/myserver DOMAIN\myserviceuser</span></div>
<div class="MsoNormal">
<span style="color: black; font-size: 10.5pt;">setspn.exe -A
HTTP/</span><span style="color: black; font-size: 10.5pt;"><span style="color: black; font-size: 10.5pt;">myserver</span>.domain.local DOMAIN\</span><span style="color: black; font-size: 10.5pt;">myserviceuser</span><span style="color: black; font-size: 10.5pt;"></span></div>
<br />
to link the SPN HTTP/myserver to the user myserviceuser.<br />
<br />
Generate keytab:<br />
The keytab is file which stores SPNs/usernames and password for them.<br />
<br />
According
to the apache tutorial you should do this on your windos/AD server
using the ktpass tool. I found it was better to use the ktab.exe that
comes with java on windows:<br />
<span style="color: black; font-size: 10.5pt;"><code>ktab -a HTTP/<HOSTNAME> <SERVICE USER PASSWORD> -k <OUTPUT FILE> -n 0</code></span><span style="color: black; font-size: 10.5pt;"></span><br />
e.g.<br />
<span style="color: black; font-size: 10.5pt;"><code></code></span>ktab -a HTTP/myserver.domain.local myservicepassword -k mykeytab.keytab -n 0<span style="color: black; font-size: 10.5pt;"></span><br />
<br />
Note the n 0 flag which sets key version number, it needs to be 0 for tomcat/Spnego to find the key.<br />
<br />
Put the mykeytab.keytab file under /etc/tomcat7/mykeytab.keytab on your linux server.<br />
<br />
<br />
We
also need to make the computers in the windows network trust our
server, to do this we can use Group Policy on the AD server. But we'll
get back to that later.<br />
<br />
<br />
<b>On the linux server (as sudo):</b><br />
<br />
Add a filter to /etc/tomcat7/web.xml:<br />
<br />
<code><!-- ======================== SPNEGO filter ==============================--><br /> <filter><br /> <filter-name>SpnegoHttpFilter</filter-name><br /> <filter-class>net.sourceforge.spnego.SpnegoHttpFilter</filter-class><br /><br /> <init-param><br /> <param-name>spnego.allow.basic</param-name><br /> <param-value>true</param-value><br /> </init-param><br /> <br /> <init-param><br /> <param-name>spnego.allow.localhost</param-name><br /> <param-value>false</param-value><br /> </init-param><br /> <br /> <init-param><br /> <param-name>spnego.allow.unsecure.basic</param-name><br /> <param-value>true</param-value><br /> </init-param><br /> <br /> <init-param><br /> <param-name>spnego.login.client.module</param-name><br /> <param-value>com.sun.security.jgss.krb5.initiate</param-value><br /> </init-param><br /> <br /> <init-param><br /> <param-name>spnego.krb5.conf</param-name><br /> <param-value>conf/krb5.conf</param-value><br /> </init-param><br /> <br /> <init-param><br /> <param-name>spnego.login.conf</param-name><br /> <param-value>conf/login.conf</param-value><br /> </init-param><br /> <br /> <init-param><br /> <param-name>spnego.preauth.username</param-name><br /> <param-value>SERVICE_USER_USERNAME</param-value><br /> </init-param><br /> <br /> <init-param><br /> <param-name>spnego.preauth.password</param-name><br /> <param-value>SERVICE_USER_PASSWORD</param-value><br /> </init-param><br /> <br /> <init-param><br /> <param-name>spnego.login.server.module</param-name><br /> <param-value>com.sun.security.jgss.krb5.accept</param-value><br /> </init-param><br /> <br /> <init-param><br /> <param-name>spnego.prompt.ntlm</param-name><br /> <param-value>true</param-value><br /> </init-param><br /> <br /> <init-param><br /> <param-name>spnego.logger.level</param-name><br /> <param-value>1</param-value><br /> </init-param><br /></filter></code><br />
<br />
You
need to replace SERVICE_USER_NAME and SERVICE_USER_PASSWORD with the
ones you use to create your keytab. spnego.allow.basic,
spnego.prompt.ntlm are true to let users who haven't logged into windows
to log in (WARNING: username and password are sent in cleartext/base64
to the linux server!). spnego.allow.unsecure.basic needs to be true if
you don't use https, which you should do.<br />
<br />
<code> <filter-mapping><br /> <filter-name>SpnegoHttpFilter</filter-name><br /> <url-pattern>*</url-pattern><br /> </filter-mapping></code><br />
<br />
To apply filter to all files.<br />
<br />
<br />
Create/edit the login.conf:<br />
<br />
<code>com.sun.security.jgss.krb5.initiate {<br /> com.sun.security.auth.module.Krb5LoginModule required;<br />};<br /><br />com.sun.security.jgss.krb5.accept {<br /> com.sun.security.auth.module.Krb5LoginModule required<br /> doNotPrompt=true<br /> useKeyTab=true<br /> principal="HTTP/myserver.domain.local@DOMAIN.LOCAL"<br /> keyTab="/var/lib/tomcat7/conf/mykeytab.keytab"<br /> storeKey=true<br /> isInitiator=false;<br />};</code><br />
<br />
Differently
from the apache tutorial, the initate object should only contain the
module, otherwise tomcat will throw a parse error on startup.<br />
<br />
<br />
Create/edit the krb5.conf:<br />
<br />
<code>[libdefaults]<br />default_realm = DOMAIN.LOCAL<br />default_keytab_name = FILE:/etc/tomcat7/mykeytab.keytab<br />default_tkt_enctypes = rc4-hmac,aes256-cts-hmac-sha1-96,aes128-cts-hmac-sha1-96<br />default_tgs_enctypes = rc4-hmac,aes256-cts-hmac-sha1-96,aes128-cts-hmac-sha1-96<br />forwardable = true<br /><br />[realms]<br />DOMAIN.LOCAL = {<br /> kdc = 192.168.1.5:88<br />}<br /><br />[domain_realm]<br />domain.local = DOMAIN.LOCAL<br />.domain.local = DOMAIN.LOCAL<br /><br />[login]<br /> krb4_convert = true<br /> krb4_get_tickets = false</code><br />
<br />
The
kdc parameter should support the hostname of the KDC/AD server e.g.
kdc.domain.local, but mine had trouble with DNS lookup for it, luckily IP
works fine.<br />
<br />
NOTE: Make sure time is within a few minutes of the AD server, consider installing a NTP client to keep in sync.<br />
<br />
<h4>
<b>AUTHORIZATION (roles/groups):</b></h4>
<br />
You will need to create/edit the following files (On Ubuntu):<br />
<br />
<code>/var/lib/tomcat7/webapps/ROOT/WEB-INF/web.xml</code><br />
/usr/share/tomcat7/libs/bcprov-jdk15on-147.jar<br />
/usr/share/tomcat7/libs/spnego-pac.jar<br />
<br />
Active
Directory adds a blob to their kerberos tokens called PAC (Privilege
Attribute Certificate), which includes a users roles. We can extract
these roles from our ticket so we don't have to do an additional LDAP
request (which is the normal way).<br />
<br />
To do this we need a custom build of the spnego library by Ricardo MartÃn Camarero (rickyepoderi) (see <a href="http://blogs.nologin.es/rickyepoderi/index.php?/archives/73-SPNEGOKerberos-in-JavaEE-PAC.html">http://blogs.nologin.es/rickyepoderi/index.php?/archives/73-SPNEGOKerberos-in-JavaEE-PAC.html</a>) which utilizes <a href="http://jaaslounge.sourceforge.net/">JaasLounge</a> and <a href="https://www.bouncycastle.org/">Bouncy Castle</a> ASN1 to extract the PAC roles.<br />
I've
added support for fetching a users kerberos token when using Basic Auth
as well as adding compressed PAC from another library.<br />
<br />
The spnego-pac source code is available from github (<a href="https://github.com/asmund1/spnego-pac">https://github.com/asmund1/spnego-pac</a>), and the final binaries used in this project from <a href="https://github.com/asmund1/spnego-pac/blob/master/jars/spnego-pac.jar">https://github.com/asmund1/spnego-pac/blob/master/jars/spnego-pac.jar</a> and <a href="https://github.com/asmund1/spnego-pac/blob/master/jars/bcprov-jdk15on-147.jar">https://github.com/asmund1/spnego-pac/blob/master/jars/bcprov-jdk15on-147.jar</a> (additional library needed).<br />
<br />
<b>On the linux server (as sudo):</b><br />
<br />
Copy spnego-pac.jar and bcprov-jdk15on-147.jar to
/usr/share/tomcat7/libs/ so that tomcat loads it on startup. NOTE:
Remove the original spnego jar if you have it there already.<br />
<br />
The
PAC contains only the numerical representation for each role for the
user, you can use this directly in your servlets, but I added some
aliases for my roles. I did this in the webapp web.xml, but it should
work in the global web.xml too (/etc/tomcat7/web.xml):<br />
<br />
<code> <context-param><br /> <param-name>myserver_write_role</param-name><br /> <param-value>S-1-5-21-123456789-1234567890-1234567890-1234</param-value><br /> <description>Alias for write access role</description><br /> </context-param></code><br />
<br />
To get the value for your roles, check your tomcat log (/var/lib/tomcat7/logs/catalina.out) after login using kerberos, the library prints the SIDs found for a user.<br />
You might have to change the log level since they are printed at FINER level. Do this by appending<br />
<code>net.sourceforge.spnego.SpnegoAuthenticator = FINER</code><br />
to the bottom of /etc/tomcat/logging.properties file and restarting tomcat.<br />
<h4>
<b>GET USER AND ROLES (CODE):</b></h4>
<br />
The username/SPN of the logged
in user and his/her roles are added to the request object, so to fetch
them in Java servlets / JSP use the following lines of code:<br />
<br />
<u>For Java Servlet:</u><br />
<code>import javax.servlet.http.HttpServletRequest;<br />import javax.servlet.ServletContext;<br /><br />public class MyServlet extends HttpServlet {<br /><br /> @Override<br /> public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {<br /><br /> // Fetches username of logged in user<br /> req.getRemoteUser()<br /><br /> // Check if user has write access<br /> ServletContext context = req.getServletContext();<br /> if (!req.isUserInRole(context.getInitParameter("myserver_write_role"))) {<br /> resp.sendError(resp.SC_FORBIDDEN);<br /> return;<br /> }<br /> }<br />}</code><br />
<br />
<u>For JSP:</u><br />
<code><%= request.getRemoteUser() %></code><br />
and<br />
<%= <code>request.isUserInRole(request.getServletContext().getInitParameter("myserver_write_role")) %></code><br />
<br />
<h4>
<b>TRUSTED SERVER:</b></h4>
<br />
To
get the kerberos token from windows you need to be on the trusted
server list. Chrome and IE use a common list while firefox and other
browsers have their own.<br />
<br />
To add you server as trusted
in IE (and Chrome) open Internet Options -> Security -> Local
intranet -> Sites button -> Advanced button<br />
Enter the url for your server and press the Add button.<br />
<br />
To do the same for firefox do the following:<br />
1. Open Firefox, and type "about:config" in the Address Bar.<br />2. In the Search field, type "negotiate".<br />3. Set the following fields:<br /> network.negotiate-auth.trusted-uris myserver.domain.local<br /> network.negotiate-auth.delegation-uris myserver.domain.local<br />
<br />
(<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=520668">https://bugzilla.mozilla.org/show_bug.cgi?id=520668</a>)<br />
<br />
To add your server for IE and Chrome for all windows machines in the intranet, you can use Group Policy: <a href="https://www.serverknowledge.net/group-policy/adding-trusted-sites-internet-explorer-using-group-policy-gpo/">https://www.serverknowledge.net/group-policy/adding-trusted-sites-internet-explorer-using-group-policy-gpo/</a><br />
<br />
<h4>
<b>TEST:</b></h4>
<br />
On the linux server (as sudo):<br />
Start/Restart tomcat server to load changes in config and load jars:<br />
<code>service tomcat7 restart</code><br />
<br />
Then tail the log output for any errors:<br />
<code>tail -f /var/lib/tomcat7/logs/catalina.out</code><br />
<br />Then
navigate to your server in IE/Chrome. You should not be prompted for
username or password. If you go to the server from a non-windows logged
on computer (e.g. mobile phone) you should get a popup asking you to
enter username and password. If you enter the incorrect password you
should get a white page, with correct credentials you should see your
content.<br />
<br />
<b>Sources:</b><br />
<br />
<a href="http://spnego.sourceforge.net/spnego_tomcat.html">http://spnego.sourceforge.net/spnego_tomcat.html</a><br />
<a href="http://spnego.sourceforge.net/pre_flight.html">http://spnego.sourceforge.net/pre_flight.html</a><br />
<a href="http://spnego.sourceforge.net/reference_docs.html">http://spnego.sourceforge.net/reference_docs.html</a><br />
<a href="http://spnego.sourceforge.net/client_keytab.html">http://spnego.sourceforge.net/client_keytab.html</a><br />
<a href="http://spnego.sourceforge.net/ExampleSpnegoAuthenticatorValve.java">http://spnego.sourceforge.net/ExampleSpnegoAuthenticatorValve.java</a><br /><a href="http://spnego.sourceforge.net/HelloKeytab.java">http://spnego.sourceforge.net/HelloKeytab.java</a><br />
<a href="https://sourceforge.net/p/spnego/discussion/1003769/thread/98e5ea01/">https://sourceforge.net/p/spnego/discussion/1003769/thread/98e5ea01/</a> <br />
<br />
<a href="http://jaaslounge.sourceforge.net/howto/SSO_Tomcat_Howto.pdf">http://jaaslounge.sourceforge.net/howto/SSO_Tomcat_Howto.pdf</a><br />
<a href="http://www.oracle.com/technetwork/articles/idm/weblogic-sso-kerberos-1619890.html">http://www.oracle.com/technetwork/articles/idm/weblogic-sso-kerberos-1619890.html</a><br />
<a href="http://stackoverflow.com/questions/20152000/get-ad-groups-with-kerberos-ticket-in-java">http://stackoverflow.com/questions/20152000/get-ad-groups-with-kerberos-ticket-in-java</a><br />
<a href="https://tomcat.apache.org/tomcat-7.0-doc/realm-howto.html#JNDIRealm">https://tomcat.apache.org/tomcat-7.0-doc/realm-howto.html#JNDIRealm</a><br />
<a href="http://docs.oracle.com/javase/7/docs/technotes/guides/security/jgss/lab/part6.html">http://docs.oracle.com/javase/7/docs/technotes/guides/security/jgss/lab/part6.html</a><br />
<a href="http://kerberos.996246.n3.nabble.com/kinit-Cannot-contact-any-KDC-for-realm-EXAMPLE-COM-while-getting-initial-credentials-td19145.html">http://kerberos.996246.n3.nabble.com/kinit-Cannot-contact-any-KDC-for-realm-EXAMPLE-COM-while-getting-initial-credentials-td19145.html</a><br />
<a href="http://serverfault.com/questions/166768/kinit-wont-connect-to-a-domain-server-realm-not-local-to-kdc-while-getting-in">http://serverfault.com/questions/166768/kinit-wont-connect-to-a-domain-server-realm-not-local-to-kdc-while-getting-in</a><br />
<a href="http://stackoverflow.com/questions/31877027/kerberos-cannot-find-key-of-appropriate-type-to-decrypt-ap-rep-rc4-with-hmac">http://stackoverflow.com/questions/31877027/kerberos-cannot-find-key-of-appropriate-type-to-decrypt-ap-rep-rc4-with-hmac</a> <br />
<a href="https://www.blogger.com/goog_1704211347"><br /></a>
<a href="https://docs.google.com/document/d/1G7WAaYEKMzj16PTHT_cIYuKXJG6bBcrQ7QQBQ6ihOcQ/edit#heading=h.yh8m8tkjdx9h">https://docs.google.com/document/d/1G7WAaYEKMzj16PTHT_cIYuKXJG6bBcrQ7QQBQ6ihOcQ/edit#heading=h.yh8m8tkjdx9h</a><br />
<a href="http://stackoverflow.com/questions/3568635/android-authenticating-with-kerberos">http://stackoverflow.com/questions/3568635/android-authenticating-with-kerberos</a><br />
<br />
<a href="http://stackoverflow.com/questions/2518256/override-intranet-compatibility-mode-ie8">http://stackoverflow.com/questions/2518256/override-intranet-compatibility-mode-ie8</a>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-8787458120527758499.post-15705784352946773402016-04-15T13:15:00.002+02:002016-04-15T13:27:01.104+02:00Share one fileFrequently I have two computers next to each other and I want to copy a file or directory from one to the other. What do you do? Mail it to yourself, sync it via some cloud service, set up samba? No just use woof (<a href="http://www.home.unix-ag.org/simon/woof.html">http://www.home.unix-ag.org/simon/woof.html</a>).<br />
<br />
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheGvDrDscaDlZ1Qr-g_l9z9M3vGLFx9oykgJSoFRmHkQ80rxJsr33InRFK-Xgvu3vUrpx8VwLVgg0k-htnpeEHG00lhwCVBHB6_ypAZUg5Q_eZICkgRQzVueWVtK8-vey7LhtURtuO-v4L/s1600/woof.png" imageanchor="1"><img border="0" height="102" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheGvDrDscaDlZ1Qr-g_l9z9M3vGLFx9oykgJSoFRmHkQ80rxJsr33InRFK-Xgvu3vUrpx8VwLVgg0k-htnpeEHG00lhwCVBHB6_ypAZUg5Q_eZICkgRQzVueWVtK8-vey7LhtURtuO-v4L/s320/woof.png" width="320" /></a> </div>
<br />
A tiny python server that serves one file and then shuts down as soon as the file has been downloaded. (You can also share a directory as a tar archive).<br />
<br />
Just do:<br />
<code>python woof.py 'file to share'</code><br />
<br />
Enter the resulting URL e.g.:<br />
<code>http://10.0.0.94:8080/IMG_0017.jpg</code><br />
in a web browser on the other machine<br />
and voila.<br />
<br />
<b>NOTE: </b>the computers need to be on the same network. + you need to be running linux/unix with <a href="https://www.python.org/downloads/">python 2.7.x</a>.Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-8787458120527758499.post-23470394575403559732016-04-06T18:59:00.001+02:002016-04-06T18:59:41.276+02:00Framebuffer screen dumps to PNG and backI've got a nice card with an Atmel AVR32 processor and a nice big 320x240 (monochrome!) screen. :)<br />
I can put data on the screen from <a href="http://buildroot.uclibc.org/">buildroot linux</a> by writing directly to the framebuffer, /dev/fb0. However the data there is in raw format. Here is how to dump from screen. Then convert, using <a href="https://www.ffmpeg.org/">ffmpeg</a>, the raw data to a PNG and then back to raw data after editing:<br />
<br />
<ol>
<li>Get a screenshot of the framebuffer using <code>cat /dev/fb0 > screendump.bin</code>.</li>
<li>Convert to PNG using ffmpeg: <code>ffmpeg -vcodec rawvideo -f rawvideo -pix_fmt monow -s 320x240 -i screendump.bin -f image2 -vcodec png screendump.png</code><br />This will read raw video from the screendump.bin, handle it as pixel monochrome data from a 320x240 screen and save as sreendump PNG file.</li>
<li>Next, open in Gimp or similar to edit. Save as PNG afterwards.</li>
<li>Convert
to rawvideo binary again using ffmpeg: <code>ffmpeg -vcodec png -i savedimage.png -vcodec rawvideo -f rawvideo -pix_fmt monow savedimage.bin</code></li>
<li>Put the data on the screen: <code>cat savedimage.bin > /dev/fb0</code></li>
</ol>
Use <code>ffmpeg -pix_fmts</code> to see other raw video types to convert from/to.<br />
<br />
Sources: Check out these great sites for more:<br />
<a href="http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs">http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs</a><br />
<a href="http://forum.videohelp.com/threads/334333-Help-with-lossless-ffmpeg-command-%5Bvideo-png-back-to-video%5D">http://forum.videohelp.com/threads/334333-Help-with-lossless-ffmpeg-command-%5Bvideo-png-back-to-video%5D </a><br />
<a href="http://stackoverflow.com/questions/3781549/how-to-convert-16-bit-rgb-frame-buffer-to-a-viewable-format">http://stackoverflow.com/questions/3781549/how-to-convert-16-bit-rgb-frame-buffer-to-a-viewable-format</a><br />
<a href="https://community.freescale.com/docs/DOC-100347">https://community.freescale.com/docs/DOC-100347</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-70936385740085269492016-04-06T18:57:00.002+02:002016-04-06T18:57:42.578+02:00Remote Desktop over the Internet using UltraVNC on WindowsHere is a HowTo for setting up a UltraVNC server on your computer, automatically open needed ports, and creating a configured UltraVNC single-click client to let you see someones desktop where all they have to do is start the client you send to them. No installations!<br />(A great alternative is <a href="https://www.teamviewer.com/">TeamViewer</a> which is free for personal use, but expensive for commercial use)<br />
<br />
Here is how:<br />
<br />
- Download UltraVNC and install:<br />
See bottom of: http://www.uvnc.com/downloads/ultravnc.html<br />
<br />
- Download UltraVNC SingleClick custom.zip package from:<br />
http://www.uvnc.com/pchelpware/sc/create.html<br />
<br />
- Extract helpdesk.txt file.<br />
<br />
- Edit to look like you want to.<br />
Example helpdesk.txt:<br />
<code> </code><br />
<blockquote class="tr_bq">
[TITLE]<br />
UltraVnc SC<br />
<br />
[HOST]<br />
My RDC connection<br />
-connect 158.158.158.158:5900 -noregistry<br />
<br />
[TEXTTOP]<br />
Double click to open connection<br />
<br />
[TEXTMIDDLE]<br />
<br />
[TEXTBOTTOM]<br />
<br />
<br />
[TEXTRBOTTOM]<br />
<br />
<br />
[TEXTRMIDDLE]<br />
<br />
<br />
[TEXTRTOP]<br />
<br />
<br />
[TEXTBUTTON]<br />
UltraVNC web<br />
<br />
[WEBPAGE]<br />
http://www.ultravnc.net<br />
<br />
[TEXTCLOSEBUTTON]<br />
Cancel<br />
<br />
<br />
[BALLOON1TITLE]<br />
Establishing connection ...<br />
<br />
[BALLOON1A]<br />
5 min connection attempt<br />
<br />
[BALLOON1B]<br />
If it fails, the software will close.<br />
<br />
[BALLOON1C]<br />
<br />
<br />
[BALLOON2TITLE]<br />
Connection active.<br />
<br />
[BALLOON2A]<br />
Warning, your desktop is visible remotely<br />
<br />
[BALLOON2B]<br />
You can break the connection any time<br />
<br />
[BALLOON2C]<br />
by using the close button</blockquote>
<br />
<br />
<br />
(remember to replace 158.158.158.158 with your external IP, e.g. from https://www.whatismyip.com/)<br />
<br />
- Create a ZIP file with only helpdesk.txt in it.<br />
<br />
- Go to:<br />
http://support1.uvnc.com/cgi-bin/upload4.pl<br />
<br />
- Enter user: foo<br />
- Enter password: foobar<br />
- Select Zip file containing helpdesk.txt <br />
- Click <i>Upload</i><br />
- Wait until you a link to download exe file appears. Then download the exe file.<br />
- Start it to see what it looks like.<br />
<br />
<br />
- Download UPnP PortMapper to open the needed port on your computer (if you havent done so manually on your router).<br />
https://sourceforge.net/projects/upnp-portmapper/files/latest/download<br />
https://github.com/kaklakariada/portmapper<br />
<br />
- Open PortMapper jar file (should need only double-click if you have Java installed).<br />
- Under the section "Port Mapping presets", select <i>Create </i>button.<br />
- Enter a description, e.g. UltraVNC.<br />
- Then click <i>Add </i>button.<br />
- Change port 1 to 5900 in both External Port and Internal Port columns.<br />
- Not sure if you also need UDP port open, but might be useful so click Add again and select UDP with port 5900 internal and external.<br />
- Click <i>save</i>.<br />
<br />
- Click <i>connect </i>to connect to your router.<br />
When successfully connected (you might get an error, but stuff seems to work regardless).<br />
- Select your UltraVNC entry in the list and press "Use".<br />
- Wait for ports to show up in the list above.<br />
<br />
Now you have ports open. You need to start VNC listener:<br />
- Open command line prompt (cmd in windows start menu) and navigate to where you installed UltraVNC and run it with flag -listen 5900 to tell it to listen on port 5900:<br />
<code></code><br />
cd "C:\Program Files\uvnc bvba\UltraVnc"<br />
vncviewer.exe -listen 5900<br />
<br />
<br />
- Finally, send the exe file you generated from helpdesk.txt (not the zip file) to the person you want to connect to. Get the person to open the file and double click on the top option and you should get a message on your computer asking you to accept the connection.<br />
<br />
<br />
Source:<br />
http://www.uvnc.com/docs/uvnc-sc/76-how-to-setup-and-configure-a-custom-Ultra%20VNC-sc.htmlUnknownnoreply@blogger.com1tag:blogger.com,1999:blog-8787458120527758499.post-23073950074214665292016-04-06T18:47:00.001+02:002016-04-06T18:47:50.272+02:00Sites to read about AngularJS and Ionic<b>Top 10 angularjs mistakes:</b><br />
<a href="https://www.airpair.com/angularjs/posts/top-10-mistakes-angularjs-developers-make#9-manual-testing">https://www.airpair.com/angularjs/posts/top-10-mistakes-angularjs-developers-make#9-manual-testing</a><br />
<br />
<br />
<b>Best practice dir structure angularjs/ionic:</b><br />
<a href="https://scotch.io/tutorials/angularjs-best-practices-directory-structure">https://scotch.io/tutorials/angularjs-best-practices-directory-structure</a><br />
I've tried both. Unsure which one I think is best. I think the most important point is to create a directory structure to group your files according to how they are used. So that other people can understand how you program is structured more quickly.<br />
<br />
<br />
<b>Tips for ionic:</b><br />
<a href="http://www.betsmartmedia.com/what-i-learned-building-an-app-with-ionic-framework">http://www.betsmartmedia.com/what-i-learned-building-an-app-with-ionic-framework</a> (<a href="https://web.archive.org/web/20150925034548/http://www.betsmartmedia.com/what-i-learned-building-an-app-with-ionic-framework">https://web.archive.org/web/20150925034548/http://www.betsmartmedia.com/what-i-learned-building-an-app-with-ionic-framework</a>)<br />
<br />
<br />
<b>Intro and how to use jasmine unit test framework:</b><br />
<a href="http://jasmine.github.io/edge/introduction.html">http://jasmine.github.io/edge/introduction.html</a><br />
Great test tool! Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-91443179757030299062016-04-06T18:25:00.002+02:002016-04-06T18:25:52.659+02:00Promises in AngularJS<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7FDo_ZnpujFnni2iYzQ8zFjMIpZNqyXokOB6PnSZv531R0rklL4xckwvZ8GeVbjBXnon-Es326LLbBuKLfLpafta2PYm9_oI2oB1287-DX2VSutp5bF4cKAmWq6irVWnUkgs5XRpsQuaK/s1600/promise_chaining.png" imageanchor="1"><img border="0" height="120" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7FDo_ZnpujFnni2iYzQ8zFjMIpZNqyXokOB6PnSZv531R0rklL4xckwvZ8GeVbjBXnon-Es326LLbBuKLfLpafta2PYm9_oI2oB1287-DX2VSutp5bF4cKAmWq6irVWnUkgs5XRpsQuaK/s320/promise_chaining.png" width="320" /></a> </div>
<br />
Introduction to AngularJS promises (as a cartoon):<br />
<a href="http://andyshora.com/promises-angularjs-explained-as-cartoon.html">http://andyshora.com/promises-angularjs-explained-as-cartoon.html</a><br />
<br />
Promise anti-patterns<br />
Flatten chaining, clean up, and broken chains:<br />
<a href="http://taoofcode.net/promise-anti-patterns/">http://taoofcode.net/promise-anti-patterns/</a><br />
<br />
HTTP promise not like Q promise, use deferred: <br />
<a href="http://weblog.west-wind.com/posts/2014/Oct/24/AngularJs-and-Promises-with-the-http-Service">http://weblog.west-wind.com/posts/2014/Oct/24/AngularJs-and-Promises-with-the-http-Service</a><br />
<br />
AngularJS Q:<br />
<a href="https://docs.angularjs.org/api/ng/service/$q">https://docs.angularjs.org/api/ng/service/$q</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-29114736159245692382016-04-06T18:18:00.000+02:002016-04-06T18:18:03.325+02:00Nice features to put on headless linux box<div style="text-align: center;">
<b><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQSEZ363DXXGkozkPWmtG5IWnGzzZXkqfxtqXQb4R3k26LocO4QJOGBm0QkDhFRxJroPDZgMdyzJ1V__NrCyK_ahqoQxa_Tnon_QiUuHOriyL-1pnQR1x54LvX5QDbuioH3eAPQ-LmWBhC/s1600/terminal_window_blur.png" imageanchor="1"><img border="0" height="167" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQSEZ363DXXGkozkPWmtG5IWnGzzZXkqfxtqXQb4R3k26LocO4QJOGBm0QkDhFRxJroPDZgMdyzJ1V__NrCyK_ahqoQxa_Tnon_QiUuHOriyL-1pnQR1x54LvX5QDbuioH3eAPQ-LmWBhC/s200/terminal_window_blur.png" width="200" /></a> </b></div>
<br />
<b>Unattended-upgrades:</b><br />
<br />
Automatically download and install stable updates.<br />
<br />
Install using:<br />
<tt>sudo apt-get install unattended-upgrades</tt><br />
Configure using:<br />
<pre>sudo dpkg-reconfigure -plow unattended-upgrades</pre>
<br />
Source:<br />
<a href="http://raspberrypi.stackexchange.com/questions/4698/how-can-i-keep-my-raspbian-wheezy-up-to-date">http://raspberrypi.stackexchange.com/questions/4698/how-can-i-keep-my-raspbian-wheezy-up-to-date</a> <br />
<a href="https://help.ubuntu.com/community/AutomaticSecurityUpdates">https://help.ubuntu.com/community/AutomaticSecurityUpdates</a><br />
<br />
<br />
<b>Fail2ban:</b><br />
<br />
<a href="http://www.fail2ban.org/wiki/index.php/Main_Page">http://www.fail2ban.org/wiki/index.php/Main_Page</a><br />
<a href="https://en.wikipedia.org/wiki/Fail2ban">https://en.wikipedia.org/wiki/Fail2ban</a><br />
<br />
<br />
<br />
<br />
<br />
<b>Imapgrab:</b><br />
<br />
To automatically backup email:<br />
<br />
<br />
<a href="http://www.linux-magazine.com/Online/Blogs/Productivity-Sauce/Back-up-Email-with-a-Single-Command">http://www.linux-magazine.com/Online/Blogs/Productivity-Sauce/Back-up-Email-with-a-Single-Command</a><br />
<a href="https://sourceforge.net/projects/imapgrab/">https://sourceforge.net/projects/imapgrab/</a> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-75651991176202014362016-04-06T18:04:00.001+02:002016-04-06T18:04:20.309+02:00Android LayerDrawable in HTML using CSSSo a neat feature for Android is the <a href="http://developer.android.com/reference/android/graphics/drawable/LayerDrawable.html">LayerDrawable</a> which lets you make an image compiled from other images. You define an array of images that shuld be drawn on top of each other and receive the resulting image.<br />
This feature exists in CSS too. It's called <i>background-image</i> and lets you define one or more images to be displayed as a background of a container.<br />
<br />
<code>background-image: url(front.png), url(behind.png);</code><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBPbg_sdByHWX2FgSyRrmdg4mzR476DXlavfvWHXmVVz7wL9vhmZLU7ew1v40gP6T_ttgMIFfE5Id7V3Qy-GoUqmrpTjP5jof5ma_RuzAwOASWVRDRee_CVVwrLj9E6ruN8_bk2kbaabQu/s1600/front.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBPbg_sdByHWX2FgSyRrmdg4mzR476DXlavfvWHXmVVz7wL9vhmZLU7ew1v40gP6T_ttgMIFfE5Id7V3Qy-GoUqmrpTjP5jof5ma_RuzAwOASWVRDRee_CVVwrLj9E6ruN8_bk2kbaabQu/s1600/front.png" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilO4Py9F_ZyjGLW5Zkp_LYEXrXuGwZOxYqMr5qxS6Sxmc3Y2_bpPPMwQ5RlgWbVIiIdYotsQep6Htup1vFFNQ4DCsaYCKZvVj2OXGH74xR5ueVHc7rt7oMwITHeuSKevxShodYGCrJA998/s1600/behind.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilO4Py9F_ZyjGLW5Zkp_LYEXrXuGwZOxYqMr5qxS6Sxmc3Y2_bpPPMwQ5RlgWbVIiIdYotsQep6Htup1vFFNQ4DCsaYCKZvVj2OXGH74xR5ueVHc7rt7oMwITHeuSKevxShodYGCrJA998/s1600/behind.png" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEja1QWEKRLVQq8Vw3618aeCUPovqJvxpkpgp78tvN0grqc7carTLGw2plPdxABVjW90hcTY1-82gdQrT5CTpFdghRP7pEWjLDCM9vSV21XyxlT8ObeQ3QO6UL2C-XuujxGJvOOBqYQxqiDp/s1600/combined_yellow_on_blue_checkbox.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEja1QWEKRLVQq8Vw3618aeCUPovqJvxpkpgp78tvN0grqc7carTLGw2plPdxABVjW90hcTY1-82gdQrT5CTpFdghRP7pEWjLDCM9vSV21XyxlT8ObeQ3QO6UL2C-XuujxGJvOOBqYQxqiDp/s1600/combined_yellow_on_blue_checkbox.png" /></a></div>
<span id="goog_1660209844"></span><span id="goog_1660209845"></span><br />
<br />
Remember to make the container a block element and if you don't have any content in it you should set the container <i>height </i>and <i>width</i> or a <i>padding-bottom</i> to give it size (Otherwise you will be shown approximately 0px of your background). See <a href="http://stackoverflow.com/questions/1495407/css-a-way-to-maintain-aspect-ratio-when-resizing-a-div">http://stackoverflow.com/questions/1495407/css-a-way-to-maintain-aspect-ratio-when-resizing-a-div</a><br />
<br />
<code><code>.container-with-background-image { <br /> width: 100%; <br /> padding-bottom: 75%;<br />}</code></code><br />
<br />
Source:<br />
http://www.css3.info/preview/multiple-backgrounds/<br />
http://stackoverflow.com/questions/5846637/why-an-inline-background-image-style-doesnt-work-in-chrome-10-and-internet-exUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-49266324754712870412015-09-23T14:17:00.002+02:002015-09-23T14:17:35.188+02:00Using gettext Library for TranslationsGNU gettext is a C library which lets you add translation support to
your program with fallbacks to original text if no translation is
available.<br />
<br />
Here's a list of links to how you use the different utils in the gettext package: <br />
<br />
See <a class="externallink" href="http://stackoverflow.com/questions/1003360/complete-c-i18n-gettext-hello-world-example" target="_blank" title="http://stackoverflow.com/questions/1003360/complete-c-i18n-gettext-hello-world-example">http://stackoverflow.com/questions/1003360/complete-c-i18n-gettext-hello-world-example</a> for a hello world example using gettext.<br />
<br />
See <a class="externallink" href="http://www.gnu.org/software/libc/manual/html_node/Locating-gettext-catalog.html" target="_blank" title="http://www.gnu.org/software/libc/manual/html_node/Locating-gettext-catalog.html">http://www.gnu.org/software/libc/manual/html_node/Locating-gettext-catalog.html</a> for selecting translation file in code.<br />
See <a class="externallink" href="http://www.gnu.org/software/libc/manual/html_node/Translation-with-gettext.html" target="_blank" title="http://www.gnu.org/software/libc/manual/html_node/Translation-with-gettext.html">http://www.gnu.org/software/libc/manual/html_node/Translation-with-gettext.html</a> for using gettext in code.<br />
See <a class="externallink" href="http://www.gnu.org/software/gettext/manual/html_node/lib_002fgettext_002eh.html" target="_blank" title="http://www.gnu.org/software/gettext/manual/html_node/lib_002fgettext_002eh.html">http://www.gnu.org/software/gettext/manual/html_node/lib_002fgettext_002eh.html</a>
for using gettext.h instead of libintl.h to get extended capabilities
such as pgettext (adds context) and support for replacing gettext
commmands with no-op if gettext is not installed on system.
See <a class="externallink" href="http://www.gnu.org/software/gettext/manual/html_node/PO-Files.html" target="_blank" title="http://www.gnu.org/software/gettext/manual/html_node/PO-Files.html">http://www.gnu.org/software/gettext/manual/html_node/PO-Files.html</a> for how PO files work (text files translations).<br />
See <a class="externallink" href="http://www.heiner-eichmann.de/autotools/using_gettext.html" target="_blank" title="http://www.heiner-eichmann.de/autotools/using_gettext.html">http://www.heiner-eichmann.de/autotools/using_gettext.html</a>, <a class="externallink" href="http://www.gnu.org/software/gettext/FAQ.html" target="_blank" title="http://www.gnu.org/software/gettext/FAQ.html">http://www.gnu.org/software/gettext/FAQ.html</a>, and <a class="externallink" href="http://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/xgettext-Invocation.html" target="_blank" title="http://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/xgettext-Invocation.html">http://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/xgettext-Invocation.html</a> for some information on using xgettext to extract strings for translation into a POT file.<br />
See <a class="externallink" href="http://www.gnu.org/software/gettext/manual/html_node/msginit-Invocation.html" target="_blank" title="http://www.gnu.org/software/gettext/manual/html_node/msginit-Invocation.html">http://www.gnu.org/software/gettext/manual/html_node/msginit-Invocation.html</a> on how msginit generates language specific translation files (PO) from POT file.<br />
See <a class="externallink" href="http://www.gnu.org/software/gettext/manual/html_node/msgmerge-Invocation.html" target="_blank" title="http://www.gnu.org/software/gettext/manual/html_node/msgmerge-Invocation.html">http://www.gnu.org/software/gettext/manual/html_node/msgmerge-Invocation.html</a> on how msgmerge generates updated language specific translation files (PO) from a changed POT file.<br />
See <a class="externallink" href="http://www.gnu.org/software/gettext/manual/html_node/msgfmt-Invocation.html" target="_blank" title="http://www.gnu.org/software/gettext/manual/html_node/msgfmt-Invocation.html">http://www.gnu.org/software/gettext/manual/html_node/msgfmt-Invocation.html</a> on how msgfmt generates binary translation files (MO) from human readable translation files (PO).<br />
<br />
<br />
See <a class="externallink" href="http://www.gnu.org/software/gettext/FAQ.html#integrating_noop" target="_blank" title="http://www.gnu.org/software/gettext/FAQ.html#integrating_noop">http://www.gnu.org/software/gettext/FAQ.html#integrating_noop</a> for troubleshooting missing translations<br />
<br />
<a class="editsectionlink" href="http://knotra01.emea.fs.utc.com/wiki/Edit.aspx?Page=Using-gettext-Library-for-Translations&Section=0"></a><br />
<h3 class="separator">
Simple example</h3>
<ol>
<li>Copy gettext.h from /usr/share/gettext/ to your component or project.</li>
<li>Set macro ENABLE_NLS to 1</li>
<li>Include gettext.h in your cpp file.</li>
<li>Example code:<br /><pre>::setlocale(LC_ALL, "");
// Set directory to search for translation files in (which contains
// en_US.UTF-8/LC_MESSAGES/hellogt.mo)
bindtextdomain("hellogt", ".");
// Set name of translation file to use (hellogt.mo)
textdomain( "hellogt");
std::cout << gettext("hi") << std::endl;
std::cout << pgettext("bob", "hello, world!") << std::endl;
</pre>
</li>
</ol>
<a class="editsectionlink" href="http://knotra01.emea.fs.utc.com/wiki/Edit.aspx?Page=Using-gettext-Library-for-Translations&Section=1"></a><br />
<h3 class="separator">
Generate translation files </h3>
<pre>#Common
find . -name "*.cpp" > files.txt
xgettext --package-name mygt --package-version 1.2 --default-domain mygt --output mygt.pot -f files.txt
#Spanish translations
sudo locale-gen es_MX.UTF-8
msginit --no-translator --locale es_MX --output-file mygt_spanish.po --input mygt.pot
mkdir -p ./es_MX.UTF-8/LC_MESSAGES
msgfmt --check --verbose --output-file ./es_MX.UTF-8/LC_MESSAGES/mygt.mo mygt_spanish.po
#Norwegian translations
sudo locale-gen nb_NO.UTF-8
msginit --no-translator --locale nb_NO --output-file mygt_norwegian.po --input mygt.pot
mkdir -p ./nb_NO.UTF-8/LC_MESSAGES
msgfmt --check --verbose --output-file ./nb_NO.UTF-8/LC_MESSAGES/mygt.mo mygt_norwegian.po
</pre>
<h3 class="separator">
Update translation files</h3>
Add changes in code to language specific translation file:
<br />
<pre>xgettext --package-name mytgt --package-version 1.2 --default-domain mygt --output mygt.pot -f files.txt
msgmerge mygt_norwegian.po_old mygt.pot --output-file=mygt_norwegian.po_new
</pre>
use <i>msgfmt</i> to generate new mygt.mo file from mygt_norwegian.po_new.
Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-8787458120527758499.post-29636578272801652552015-06-07T02:52:00.002+02:002015-06-07T02:52:45.011+02:00AirPlay from Windows PCIf you need to play audio or video using Apple AirPlay from a windows machine here's the way:<br />
Don't try AirParrot or TorrenTV as they don't work. And VLC streaming via Iphone/Ipad AirPlay is just silly.<br />
Unfortunately the solution is: Apple has supplied iTunes for Windows with AirPlay functionality, so use that.<br />
Or maybe we should just get a Chromecast. :)Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-59161022278756498542015-03-11T09:22:00.001+01:002015-03-11T09:24:02.639+01:00AngularJS vs Ionic abstract state<br />
<a href="http://ionicframework.com/">Ionic </a>is a wrapper for <a href="https://angularjs.org/">AngularJS </a>and one of the changes that they've done is to the abstract state of the <a href="https://github.com/angular-ui/ui-router/wiki">ui-router</a>. I tried to follow an AngularJS tutorial for abstract state and added the following code:<br />
<code>.state('myparent', {<br /> abstract: true,<br /> url: '/myparent',<br /> // Note: abstract still needs a ui-view for its children to populate.<br /> // You can simply add it inline here.<br /> template: '<ui-view/>',<br /> controller: 'MyParentController'<br />})<br />.state('myparent.mychild', {<br /> url: '/mychild',<br /> templateUrl: 'mychild.view.html',<br /> controller: 'MyChildController'<br />})</code><br />
<br />
Inside mychild.view.html I had:<br />
<br />
<code><ion-view><br /> <ion-content><br /> ...<br /> </ion-content><br /></ion-view></code><br />
<br />
This resultet in a blank page (although the controller was executed since it fetched the model from my backend). Also my navigation, for which I used $ionicHistory, was all messed up.<br />
<br />
The trick apparently is to use ion-nav-view instead of ui-view in the abstract state:<br />
<code>.state('myparent', {<br /> abstract: true,<br /> url: '/myparent',<br /> // Note: abstract still needs a ui-view for its children to populate.<br /> // You can simply add it inline here.<br /> template: '<ion-nav-view/>',<br /> controller: 'MyParentController'<br />})</code><br />
<br />
Lesson learned, use Ionic tutorials. :)<br />
<br />
Source:<br />
<a href="http://learn.ionicframework.com/formulas/navigation-and-routing-part-2/">http://learn.ionicframework.com/formulas/navigation-and-routing-part-2/</a><br />
<a href="https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views#abstract-states">https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views#abstract-states</a><br />
<a href="http://ionicframework.com/docs/api/service/$ionicHistory/">http://ionicframework.com/docs/api/service/$ionicHistory/</a>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-8787458120527758499.post-42056557580579970012015-03-06T10:09:00.001+01:002015-03-09T11:18:17.649+01:00Android 9-patch image in HTML5 CSS3<div class="separator" style="clear: both; text-align: center;">
</div>
One feature that Android has adopted is 9-patch images. The <a href="http://developer.android.com/tools/studio/index.html">Android Studio</a> contains a <a href="http://developer.android.com/tools/help/draw9patch.html">Draw 9-patch tool</a> which lets you 'create bitmap images that
automatically resize'. Basically you select areas of an image that can be repeated or stretched while others are kept at the same size. Giving you almost SVG functionality for bitmap images, especially great for buttons.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWgHQ8UIN6C_ZdK2ObK_M1aTYYGhRnWSr3nujpLC6FyaeL_vwdKqEbLEvw7qguD8uiNm5AWnHgUOso6ES4GW-7jsEhLv3nqASonJiH3VOvCo3u0O2wOjxBoowcy7syjTt16FXAylqZXgVR/s1600/nine-patch-image.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWgHQ8UIN6C_ZdK2ObK_M1aTYYGhRnWSr3nujpLC6FyaeL_vwdKqEbLEvw7qguD8uiNm5AWnHgUOso6ES4GW-7jsEhLv3nqASonJiH3VOvCo3u0O2wOjxBoowcy7syjTt16FXAylqZXgVR/s1600/nine-patch-image.png" height="172" width="320" /></a></div>
<br />
Now this feature would be great for web as well, e.g. responsive design pages. To achieve this we can use the CSS3 feature <b><a href="http://www.w3schools.com/cssref/css3_pr_border-image.asp">border-image</a></b> which combines <b>border-image-source, border-image-width, border-image-slice </b>and <b>border-image-outset</b>.<br />
<br />
<b><a href="http://www.w3schools.com/cssref/css3_pr_border-image-source.asp">border-image-source</a></b> defines which image to use.<br />
<br />
<b><a href="http://www.w3schools.com/cssref/css3_pr_border-image-width.asp">border-image-width</a></b> defines the width of the border image. Stretches or shrinks the image regions to fit the widths.<br />
<br />
<b><a href="http://www.w3schools.com/cssref/css3_pr_border-image-slice.asp">border-image-slice</a></b> divides the <b>image</b> into 9 regions, thereby the name (see the image above) deciding which parts can be repeated/stretched. The regions are: four
corners, four edges and a middle. The fill property decides if the middle should be filled in or kept transparent.<br />
<br />
<b><a href="http://www.w3schools.com/cssref/css3_pr_border-image-outset.asp">border-image-outset</a></b> decides how far out from the border the image
will appear. Together with <a href="http://www.w3schools.com/cssref/pr_border-width.asp"><b>border-width</b></a> this enables the border to not take up all the space inside the container caused by it having a wide border to fit the image inside (See <a href="http://www.norabrowndesign.com/css-experiments/border-image-frame.html#one">http://www.norabrowndesign.com/css-experiments/border-image-frame.html#one</a>). This is especially great for select/dropdown boxes as they can't work around this by using line-height (<a href="http://stackoverflow.com/questions/18613279/text-over-the-top-of-a-border-image-using-the-border-as-an-expandable-backgroun">http://stackoverflow.com/questions/18613279/text-over-the-top-of-a-border-image-using-the-border-as-an-expandable-backgroun</a>)<br />
<br />
<b>border-image</b> combines the four above properties, but I felt I had more control when splitting them up. However, as of right now browser support for <b>border-image</b> and especially <b>border-image-outset</b> is a bit limited. Most browsers support <b>border-image</b>, but might need browser-specific CSS (e.g. <span class="highATT">-webkit-border-image).</span><br />
<br />
<br />
Example:<br />
<code>border-style: solid;<br />border-width: 5px;<br />border-image-source: url(dropdown.png);<br />border-image-width: 25% 10% 25% 5%;<br />border-image-slice: 10 70 20 60 fill;<br />border-image-outset: 12px;</code><br />
<br />
<a href="http://border-image.com/">http://border-image.com</a> lets you generate border-image CSS from an image. but it doesn't put in border-image-outset.<br />
<br />
Source:<br />
<a href="https://github.com/chrislondon/9-Patch-Image-for-Websites/wiki/What-Are-9-Patch-Images">https://github.com/chrislondon/9-Patch-Image-for-Websites/wiki/What-Are-9-Patch-Images</a><br />
<a href="http://stackoverflow.com/questions/6806559/does-9-patch-png-can-work-somehow-with-css-on-browsers">http://stackoverflow.com/questions/6806559/does-9-patch-png-can-work-somehow-with-css-on-browsers</a><br />
<a href="http://stackoverflow.com/questions/3659457/nine-patch-images-for-web-development">http://stackoverflow.com/questions/3659457/nine-patch-images-for-web-development</a><br />
<a href="https://teamtreehouse.com/forum/borderimageslice-vs-borderimagewidth">https://teamtreehouse.com/forum/borderimageslice-vs-borderimagewidth</a> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-64106317527505486332015-02-13T13:15:00.000+01:002015-02-13T13:15:22.982+01:00Mockito for Play 2 FrameworkMocking is great! :)<br />
To use Mockito to mock stuff for your tests in Play 2 Framework do the following:<br />
<br />
1. Add mockito as dependency in Build.scala:<br />
<code>val appDependencies = Seq(</code><br />
...,<br /> "org.mockito" % "mockito-all" % "1.10.19"<br />
)<br />
Find latest version from <a href="https://github.com/mockito/mockito/blob/master/doc/release-notes/official.md">https://github.com/mockito/mockito/blob/master/doc/release-notes/official.md </a><br />
<br />
2. Add imports to your JUnit java file:<br />
<code>import org.mockito.Mock;<br />import org.mockito.runners.MockitoJUnitRunner;<br />import static org.mockito.Mockito.*;</code><br />
Note the static import of Mockito. This lets you call <code>mock</code> and <code>when</code> without "Mockito." prefix, like most of the tutorials do.<br />
<br />
3. Create mocks:<br />
Either by putting <code>@RunWith(MockitoJUnitRunner.class)</code> on your test class and using <code>@Mock</code> for class members. E.g.:<br />
<code>@RunWith(MockitoJUnitRunner.class)<br />public class HomeControllerTest {</code><br />
@Mock<br /> HomeForm mockHome;<br />
<br />
or by creating the mocks in your code:<br />
<code>HomeForm mockHome = mock(HomeForm.class);</code><br />
<br />
4. Set up mock behavior:<br />
<code>List<string> mockNames = (List<string>) mock(List.class);</string></string></code><br />
when(mockNames.get(0)).thenReturn("bob");<br />
when(mockCompany.getNames()).thenReturn(mockNames);<br />
<br /><br />
5. Run using <code>play test</code>, you might want to run <code>play clean</code> first to make sure mockito is downloaded.<br />
<br />
Nice feature:<br />
If you've used <a href="https://code.google.com/p/googlemock/">googlemock - Google C++ Mocking Framework</a> and miss the "Uninteresting function call encountered" messages, for example for debugging, you can get verbose output from mocks by adding <code>withSettings().verboseLogging()</code> like this:<br />
<code>HomeForm mockHome = mock(HomeForm.class, withSettings().verboseLogging());</code> <br />
<br />
Sources:<br />
<a href="http://www.javacodegeeks.com/2013/05/junit-and-mockito-cooperation.html">http://www.javacodegeeks.com/2013/05/junit-and-mockito-cooperation.html</a><br />
<a href="http://stackoverflow.com/questions/11802088/how-do-i-enable-mockito-debug-messages">http://stackoverflow.com/questions/11802088/how-do-i-enable-mockito-debug-messages</a><br />
<a href="http://www.baeldung.com/mockito-behavior">http://www.baeldung.com/mockito-behavior</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-24056800143648592302014-07-21T21:58:00.002+02:002014-07-21T21:58:34.812+02:00Make your Raspberry Pi wirelessMake your Raspberry Pi wireless and be able to hide it away wherever you have a power outlet handy, just follow these steps:<br />
<br />
1. Buy a <b>Edimax EW-7811Un 150M 11n Wi-Fi USB Adapter</b>, great plug and play adapter.<br />
2. Follow the steps on <a href="http://www.savagehomeautomation.com/projects/raspberry-pi-installing-the-edimax-ew-7811un-usb-wifi-adapte.html">http://www.savagehomeautomation.com/projects/raspberry-pi-installing-the-edimax-ew-7811un-usb-wifi-adapte.html</a><br />
3. Follow <a href="https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address">https://www.modmypi.com/blog/tutorial-how-to-give-your-raspberry-pi-a-static-ip-address</a> to set a static IP address<br />
<br />
Consider upgrading your software and firmware by following <a href="https://raspberrypi.stackexchange.com/questions/4698/how-can-i-keep-my-raspbian-wheezy-up-to-date">https://raspberrypi.stackexchange.com/questions/4698/how-can-i-keep-my-raspbian-wheezy-up-to-date</a><br />
<br />
Good luck! Have fun with your pi. :)Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-52774706139919278182014-06-24T16:08:00.002+02:002014-06-24T16:08:53.137+02:00Play 2 framework access files in WARSo you've created WAR files from your Play project, see <a href="http://www.herikstad.net/2014/06/play-2-framework-war-file.html">Play 2 framework WAR file</a>. But how to fetch files within you WAR file.<br />
<br />
I previously used:<br />
<code>new File(play.Play.application().path().toString() + "//mydirectory//myfile.txt");</code><br />
which works fine when running on the Play "stack".<br />
<br />
After exporting to WAR file the path ended up looking in the application home directory, e.g. /home/<runninguser>/.<br />
Still works for files not in the WAR, since they are expected to be found here anyways.<br />
<br />
Solution for my WAR files:<br />
<code>InputStream is = Play.class.getResourceAsStream("/mydirectory/myfile.txt"");</code><br />
StringWriter writer = new StringWriter();<br />IOUtils.copy(is, writer, Charsets.UTF_8);<br />writer.toString();<br />
<br /><br />
Source: <a href="http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string">http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string</a> and <a href="http://stackoverflow.com/questions/6888343/getting-a-resource-file-as-an-inputstream-in-playframework">http://stackoverflow.com/questions/6888343/getting-a-resource-file-as-an-inputstream-in-playframework</a><br />
<br />
Note: Jetty will unpack you WAR file to a temp directory, either /tmp or below you application path /home/<runninguser>/ so this is what you are accessing. Remember not to have a script deleting these files as this will crash your web application.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-85359233914236151882014-06-24T15:53:00.000+02:002014-09-24T16:27:55.311+02:00Play 2 framework WAR file<a href="http://www.playframework.com/">Play 2 framework</a> is a nice framework for writing web applications in Java/Scala. Play runs it's own <a href="http://netty.io/">netty</a> server so you get it up and running by just writing <code>play run</code>. It detects file changes and recompiles classes as needed upon page refresh in development mode.<br />
<br />
A small catch is that Play does not natively support running in a container, e.g. <a href="http://www.eclipse.org/jetty/">Jetty</a>, <a href="http://tomcat.apache.org/">Tomcat</a>, <a href="https://glassfish.java.net/">Glassfish</a>, or <a href="http://www.jboss.org/">JBoss</a>. In fact it doesn't support ServletContext at all as far as I can see. (See <a href="http://www.playframework.com/documentation/1.2.2/faq">http://www.playframework.com/documentation/1.2.2/faq</a> and <a href="http://guillaumebort.tumblr.com/post/558830013/why-there-is-no-servlets-in-play">http://guillaumebort.tumblr.com/post/558830013/why-there-is-no-servlets-in-play</a>)<br />
This is a minus when trying to get started with Play in existing server environments. Luckily Damien Lecan started an open source project to build WAR files from Play, <a href="https://github.com/play2war/play2-war-plugin">play2war plugin</a>.<br />
<br />
Follow <a href="https://github.com/play2war/play2-war-plugin/wiki/Configuration">https://github.com/play2war/play2-war-plugin/wiki/Configuration</a> to install the plugin.<br />
<br />
Basically your Build.scala file should look something like:<br />
<code>import com.github.play2war.plugin._<br />object ApplicationBuild extends Build {<br /> val main = play.Project(appName, appVersion, appDependencies)<br /> .settings(Play2WarPlugin.play2WarSettings: _*)<br /> .settings(<br /> // Add your own project settings here <br /> Play2WarKeys.servletVersion := "3.0"<br /> )</code><br />
}<br />
<br />
and your plugins.sbt:<br />
<code>// Use play2war for creating war files using 'play war'<br />addSbtPlugin("com.github.play2war" % "play2-war-plugin" % "1.2-beta4")</code><br />
And hopfully, magic! (Note currently (2014.06.24) only support Play 2.2.1)<br />
<br />
Once installed, just run <code>play war</code> and a war file is created for you. In addition you will need a config file for your application, the application.conf in your project folder, and any extra files/folders like the private folder of your project.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-76299959760738074762014-06-06T14:48:00.000+02:002014-06-06T14:48:06.729+02:00Wired network for Lenovo S540 on Ubuntu 14.04Installed Ubuntu 14.04 on a Lenovo S540 ultrabook. Wireless work fine, but had problems with the wired network!<br />
<br />
Fix turned out to be upgrading drivers for the Realtek rtl8111/8168/8411 card. Use <code>lspci | grep net</code> to find what network card you have.<br />
<br />
New drivers can be downloaded from Realtek:<a href="http://www.realtek.com/downloads/downloadsView.aspx?Langid=1&PNid=5&PFid=5&Level=5&Conn=4&DownTypeID=3&GetDown=false#RTL8111B/RTL8168B/RTL8111/RTL8168%3Cbr%3ERTL8111C/RTL8111CP/RTL8111D%28L%29%3Cbr%3ERTL8168C/RTL8111DP/RTL8111E%3Cbr%3ERTL8168E/RTL8111F/RTL8411%3Cbr%3ERTL8111G/RTL8111GUS">http://www.realtek.com/downloads/downloadsView.aspx?Langid=1&PNid=5&PFid=5&Level=5&Conn=4&DownTypeID=3&GetDown=false#RTL8111B/RTL8168B/RTL8111/RTL8168%3Cbr%3ERTL8111C/RTL8111CP/RTL8111D%28L%29%3Cbr%3ERTL8168C/RTL8111DP/RTL8111E%3Cbr%3ERTL8168E/RTL8111F/RTL8411%3Cbr%3ERTL8111G/RTL8111GUS</a><br />
<br />
Source: <a href="https://www.mail-archive.com/kernel-packages@lists.launchpad.net/msg49591.html">https://www.mail-archive.com/kernel-packages@lists.launchpad.net/msg49591.html</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-42519004050969917822014-05-28T11:49:00.001+02:002014-05-28T11:49:56.459+02:00Add new user in Linux/UbuntuTo add a new user using command line on an Ubuntu machine there are at least two commands that may be used: useradd and adduser<br />
<br />
Use adduser instead of useradd if you are not totally certain useradd is the tool you want to use because:<br />
1. useradd is a low level tool.<br />
2. useradd will not add home directory for new user.<br />
3. useradd will not add many other defaults for new user.<br />
4. adduser is more user friendly (but uses useradd in backend).<br />
5. adduser will create home directory.<br />
6. manpages of useradd recommends use of adduser. <br />
<br />
Use it like this:<br />
<code>sudo adduser <username></code><br />
<br />
and to add a system user which has no shell (cannot log in, but just run
programs):<br />
<code>sudo adduser --system <username></code><br />
instead of <br />
<code>sudo useradd <username> -s /bin/false</code> <br />
Using adduser, the system user a home directory will be created. <br />
<br />See http://askubuntu.com/questions/374870/home-directory-not-being-created and http://askubuntu.com/questions/345974/what-is-the-difference-between-adduser-and-useradd for good reasons with links to manpages.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-1586634331504533572014-05-28T09:33:00.000+02:002014-05-28T09:33:34.240+02:00Java Listeners and Adapters, almost anonymous functionsJava allows developers to easily add listeners to different events.<br />
e.g. <code>button.addMouseListener(this);</code><br />
However, often you don't want to implement a listener interface for your class or add an inner class<br />
<code>MyClass implements MouseListener</code><br />
<code>MyClass {<br /> private class ListenerClass implements MouseListener {<br /> public void mouseClicked(MouseEvent e) {} <br /> public void mouseEntered(MouseEvent e) {}<br /> .<br /> }<br />}</code><br />
With all the functions required by the interface cluttering up your code. Often you don't even need more than one or two of the functions.<br />
<br />
Enter Adapters.<br />
Adapters are classes which are made to match a listeners interface and only that. They do nothing when called, but the developer will override the function he needs:<br />
<code>button.addMouseListener( new MouseAdapter() {<br /> @Override<br /> public void mouseClicked(MouseEvent e) {<br /> }<br />}</code><br />
<br />
This adds flexibility to Java, almost like the anonymous functions of JavaScript.<br />
<br />
Source: https://blogs.oracle.com/CoreJavaTechTips/entry/listeners_vs_adapters<br />
http://docs.oracle.com/javase/tutorial/java/javaOO/innerclasses.htmlUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-25464975390705015552014-05-07T11:03:00.000+02:002014-05-07T11:03:19.876+02:00Play2 PersistenceExceptionYou might come across the error:<br />
<code>[PersistenceException: Error loading on models.Period.startYear] </code><br />
in Play 2 Framework.<br />
This is most likely caused by your database having a NULLable field which doesn't map to a nullable member in the model.<br />
E.g.:<br />
<br />
You database has the following fields:<br />
<code>ADD COLUMN `start_year` INT(11) NULL DEFAULT NULL;<br />ADD COLUMN `end_year` INT(11) NULL DEFAULT NULL;</code><br />
which means start_year may be (null) or an int.<br />
<br />
Your java model has the following members:<br />
<code>@Entity<br />public class Period extends Model {<br /> @Id<br /> public Long periodId;<br /><br /> @Required<br /> public int startYear;<br /> <br /> @Required<br /> public int endYear;<br />}</code><br />
Which means that startYear may be an int, but not null.<br />
<br />
To fix, make change the database fields to not be nullable.<br />
Or the java model members nullable also, by using the Integer object wrapper instead of int:<br />
<code>@Entity<br />public class Period extends Model {<br /> @Id<br /> public Long periodId;<br /><br /> @Required<br /> public Integer startYear;<br /> <br /> @Required<br /> public Integer endYear;<br />}</code><br />
<br />
See: <a href="http://stackoverflow.com/questions/18405141/persistenceexception-when-i-was-using-ebean-in-play-framework">http://stackoverflow.com/questions/18405141/persistenceexception-when-i-was-using-ebean-in-play-framework</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-66975136330981624072014-01-10T22:15:00.003+01:002014-01-10T22:15:49.184+01:00Installing ImapfilterI installed <a href="https://github.com/lefcha/imapfilter">Imapfilter</a> to sort mails on the imap server (imap.domeneshop.no) I connect to into folder (The server does not support <a href="https://en.wikipedia.org/wiki/Sieve_%28mail_filtering_language%29">Sieve</a> (and <a href="http://www.productionmonkeys.net/guides/qmail-server/content-filtering/sieve/sieve-plugins-roundcube">managesieve</a> or <a href="http://plugins.roundcube.net/packages/johndoh/sieverules">sieverules</a> plugins for Roundcube), which is an alternative that does not require a running program).<br />
<br />
Here is how:<br />
<br />
<code>
* Download imapfilter from github: <a href="https://github.com/lefcha/imapfilter/archive/master.zip">https://github.com/lefcha/imapfilter/archive/master.zip</a><br />
unzip -d imapfilter.master.zip<br />
cd imapfilter-master/src<br />sudo apt-get install libssl-dev<br />sudo apt-get install lua5.1-dev<br />
* Edit imapfilter.h, core.c, lua.c, pcre.c, and system.c and add lua5.1/ before lua.h, lualib.h, and lauxlib.h<br />sudo apt-get install libpcre3-dev<br />
* Update Makefile to say -llua5.1 instead of -llua<br />
make all<br />sudo make install</code><br />
<br />
<br />
Errors I got:<br />
<code>auth.c:4:11: fatal error: openssl/hmac.h: No such file or directory</code><br />
<br />
<code>lua.c:5:17: fatal error: lua.h: No such file or directory<br />compilation terminated.<br />make: *** [lua.o] Error 1</code><br />
<br />
<code>pcre.c:7:18: fatal error: pcre.h: No such file or directory</code><br />
<br />
<code>cc -o imapfilter auth.o buffer.o cert.o core.o file.o imapfilter.o list.o log.o lua.o memory.o misc.o namespace.o pcre.o regexp.o request.o response.o session.o signal.o socket.o system.o -lm -llua -lpcre -lssl -lcrypto<br />/usr/bin/ld: cannot find -llua<br />collect2: ld returned 1 exit status<br />make: *** [imapfilter] Error 1</code><br />
<br />
All fixed by the above procedure.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-10597419071724523262014-01-05T15:25:00.000+01:002015-04-04T23:21:28.150+02:00Roundcube Webmail with DomeneshopI just set up <a href="http://roundcube.net/">Roundcube</a> to fetch emails from my <a href="http://www.domeneshop.no/">Domeneshop</a> mail server and had some trouble getting it to work.<br />
Under step 3 of the Roundcube Webmail Installer I was checking that send and receive email worked correctly and got errors. Here is the settings I used and the corresponding error I got:<br />
<br />
<code>Server: smtp.domeneshop.no<br />
Port: 587</code><br />
<br />
Error: SMTP send: <span class="fail">NOT OK</span><span class="indent">(Connection failed: HELO was not accepted: )</span><br />
<br />
<code>Server: ssl://smtp.domeneshop.no<br />
Port: 587</code><br />
<br />
SMTP send: <span class="fail">NOT OK</span><span class="indent">(Connection failed: Failed to connect socket: fsockopen(): unable to connect to ssl://smtp.domeneshop.no:587 (Unknown error))</span><br />
<br />
<code>Server: tls://smtp.domeneshop.no<br />
Port: 587</code><br />
<br />
SMTP send: <span class="fail">NOT OK</span><span class="indent">(Connection failed: HELO was not accepted: )</span><br />
<br />
I discovered, after reading through the options of main.inc.php, that you could set host for HELO. This is usually the mail servers domain (e.g. domeneshop.no) if you have an email address using your email servers domain (e.g. asmund@domeneshop.no). But, I have my email using my own domain so setting it to:<br />
<br />
<code>$rcmail_config['smtp_helo_host'] = 'herikstad.net';</code><br />
<br />
Solved my problem. :)<br />
<br />
Sources: <a href="http://www.domeneshop.no/faq.cgi?id=48">http://www.domeneshop.no/faq.cgi?id=48</a> <br />
<a href="http://schoudhury.com/blog/articles/send-email-using-gmail-from-php-with-fsockopen/">http://schoudhury.com/blog/articles/send-email-using-gmail-from-php-with-fsockopen/</a><br />
<a href="http://stackoverflow.com/questions/13717225/email-sending-with-ci-using-hotmail">http://stackoverflow.com/questions/13717225/email-sending-with-ci-using-hotmail</a> <br />
<a href="http://www.imc.org/ietf-smtp/mail-archive/msg05499.html">http://www.imc.org/ietf-smtp/mail-archive/msg05499.html</a><br />
<br />
<a href="http://trac.roundcube.net/wiki/Howto_Config/Webservers">http://trac.roundcube.net/wiki/Howto_Config/Webservers</a><br />
<a href="https://www.howtoforge.com/running-roundcube-0.7.1-on-nginx-lemp-on-debian-squeeze-ubuntu-11.10">https://www.howtoforge.com/running-roundcube-0.7.1-on-nginx-lemp-on-debian-squeeze-ubuntu-11.10</a><br />
<a href="http://mylinuxlife.com/setting-up-roundcube-webmail/">http://mylinuxlife.com/setting-up-roundcube-webmail/</a> Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-46754349775294586262013-10-29T11:37:00.000+01:002013-10-29T11:37:39.285+01:00Strip HTML entities with PostablePostable is a great little page for translating HTML code in your text into non-interpretable characters so that you can easily blog about code without parts of it disappearing because it gets interpreted as HTML tags.<br />
Just enter the code snippet into the field. Press <code>Make it friendly</code> and copy/paste the result into your blog.<br />
Great! :)<br />
<br />
<a href="http://www.elliotswan.com/postable/">http://www.elliotswan.com/postable/</a><br />
<br />
<b>Note:</b> It is run through PHP, so no guarantees that your text isn't stored somewhere. But then again, you're about to blog it right?<br />
<br />
Sources: <a href="http://www.elliotswan.com/2006/03/24/allow-me-to-introduce-you-to-my-new-little-app-postable/">http://www.elliotswan.com/2006/03/24/allow-me-to-introduce-you-to-my-new-little-app-postable/</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8787458120527758499.post-57803357530255333572013-10-29T11:29:00.000+01:002015-04-14T14:25:25.428+02:00Linux command to take screenshotOn newer versions of KDE when you press the <code>PrintScreen</code> button, a dialog pops up asking you if you want to copy or save a screenshot.<br />
<br />
You can also do screenshots from Gimp: Open Gimp, select File -> Create -> Screen Shot...<br />
<br />
To be cool or on older versions of Linux you might want to be able to take screen shot using a command line terminal (virtual terminal, you still need to be in X Windows).<br />
<br />
Enter the following command:<br />
<code>import -window root <location to put image></code><br />
e.g.<br />
<code>import -window root ~/screenshot.jpg</code><br />
<br />
So then you can easily press Alt + F2, enter the command above. Then you won't get the terminal window in your screenshot.<br />
On my system, once you have done so once, the next time you start entering the text it autocompletes.<br />
<br />
Note: You need ImageMagick installed as <code>import</code> is included in that package.<br />
<br />
Source: <a href="http://www.linuxforums.org/forum/newbie/10213-print-screen-available-linux.html">http://www.linuxforums.org/forum/newbie/10213-print-screen-available-linux.html</a>
Unknownnoreply@blogger.com0