Thursday, February 23, 2017

Run tests in background with golang

With the new "gogland" IDE there is no support(yet) for running tests on each save.

However, if you run ubuntu, you could use the following script to continously run the tests in the background and get notified when you a) break the tests b) fix the tests.

download the script:
wget https://gist.githubusercontent.com/nilsmagnus/8d5a431f19760ddcaa5d8c12d22b13f9/raw/c16fba1f9be83c395a3e4e493c72df8c715fe896/continous_gotest_notify.sh 
execute the script:
sh continous_gotest_notify.sh

Wednesday, January 25, 2017

Install ubuntu on lenovo yoga 900


Setting up lenovo yoga 900 with ubuntu is not straight forward. 

Get into bios by pressing the tiny circular button on the right side of the laptop with a toothpick when the computer is off.
  1. Enable back update in bios
  2. Boot to windows, dowload linux-specific bios update from lenovo, install it and follow instructions.
  3. Change configuration in bios under "configuration" from RAID to ACHI.
  4. Boot from your ubuntu usb-stick, pressing fn-f12 during restart.  
Happy linuxing.

Saturday, January 16, 2016

Timely For Android In Beta

After using the web ui for timelyapp for a while, I got fed up with the "IOS only" policy. So I made my own client using the api provided by timely. So if you want to track your time in timely using android, you are more than welcome to join the beta! Get the app using this link:> https://play.google.com/store/apps/details?id=no.bytecode.timelyappsimple Cheers!

Friday, December 4, 2015

Android installation issue, errorcode -505

Recently I have dealt with some installation-issues for an android app:

1st failure, duplicate permission

11-26 17:39:40.730 10166-10166/? E/Finsky: [1] PackageInstallerImpl$2.onReceive: Error -505 while installing com.something.else: INSTALL_FAILED_DUPLICATE_PERMISSION: Package com.something.else attempting to redeclare permission com.something.else.permission.C2D_MESSAGE already owned by com.something.else
11-26 17:39:40.730 10166-10166/? W/Finsky: [1] InstallerTask$3.installFailed: Install failure of com.something.else: -505 null
: This is probably due to an install of the same application on a different profile on your phone. Either make the user uninstall the app for ALL profiles on the phone or rename your C2D permission. This can be done without breaking the gcm-funcitonality by adding a middle-fix between your application-id and C2D_MESSAGE. In my case I renamed "com.something.else.permission.C2D_MESSAGE" to "com.something.else.permission.e.C2D_MESSAGE"

2nd failure, gms bug

 W/PackageManager(1007):  com.android.server.pm.PackageManagerException: Can't install because provider name com.google.android.gms.measurement.google_measurement_service (in package com.something.else) is already used by com.quoord.tapatalkpro.activity
: add applicationId to the main flavour of your build. Even if it is defined in AndroidManifest.xml, other libraries just reads the build.gradle file. If it is empty it will clash with other applications doing the same thing.

3rd failure, same name as provider in other(random) app

INSTALL_FAILED_CONFLICTING_PROVIDER.
: change authorities of your provider since it has the same authority as a random other app you have installed. E.g. add ${applicationId} as a prefix to your authorities where you declare your provider in the manifest like this:
provider
            android:name=".something.CommonManager"
            android:authorities="${applicationId}.commonmanager"
            android:readPermission=".commonmanager.read"
            android:writePermission=".commonmanager.write" /

Thursday, November 19, 2015

gradle maven-publish credentials

Make your gradle script publish to internal repo by setting password and username as follows:
apply plugin: 'maven-publish' 
apply plugin: 'java'

repositories { 
   maven { 
      credentials { 
            username 'myuser' 
            password 'mypassword' 
      } 
      url "http://myinternalrepo.intra" 
  } 
}

Monday, September 21, 2015

assertj java7

Do NOT use assertj v 3.x if you are developing for java 7 or android. You will end up with the error
error: cannot access CompletableFuture
Downgrade to assertj 2.x to fix it if you are using jdk7, use version 1.x if you are developing for android.

Saturday, September 5, 2015

Connecting to redis on heroku with golang

I have an app on heroku using the redis-addon provided by heroku ("Redis Heroku"). To connect to this instance using go-redis, I have found this to be a working solution:
  • The redis url is provided as an environment variable, REDIS_URL
  • To use redis from golang, I use redis-go.  I install this library by typing "go get github.com/gopkg.in/redis.v3"
  • Parse the url and extract the user before connecting(unless, you might end up with the error "dial tcp: too many colons in address redis://...")

Monday, September 22, 2014

gradle wsdl2java plugin released

In one of my earlier posts, I described how you can use gradle to generate java source-code from wsdls. This included writing your own tasks, managing dependency etc.

Now, I have written a plugin for this, available at the gradle plugin portal. Go fetch it while it's fresh!

Gradle plugin portal: http://plugins.gradle.org/plugin/no.nils.wsdl2java
How to use the plugin: https://github.com/nilsmagnus/wsdl2java/blob/master/README.md

If you have any issues, please register them at https://github.com/nilsmagnus/wsdl2java/issues

Saturday, September 13, 2014

Dropwizard + gradle + heroku

Note: all source code is available at https://github.com/nilsmagnus/gradledwheroku

Since the gradle build pack for heroku is still in beta, it is sometimes not straight forward to use gradle with heroku. This is how I did it with gradle, dropwizard and heroku.
  • Use gradle wrapper, the built in gradle in heroku is still using version 1.0-beta or something. When you use the wrapper, you decide the gradle version yourself. 
  • Use the gradle application plugin
  • For some reason, you must have the dropwizard as a submodule in your gradle project.
  • When deploying the app to heroku, you must tell the app to use the $PORT specified by heroku to listen to http traffic. You set this configuration by setting the WEBAPP_OPTS variable on heroku. This variable is used by the gradle application plugin when launching your java app. The value might vary, depending on your conf.yaml-file. 
heroku config:set WEBAPP_OPTS-Ddw.server.applicationConnectors[0].port='$PORT'
  • The Procfile must point to the shell script generated by the application plugin and the arguments for your application
web: webapp/build/install/webapp/bin/webapp server conf.yaml

  • The dropwizard application itself does not need to have any special config to run on heroku. You can even connect to a mongodb hosted at mongolab without any problems. 


If you want a working starting point for your application, have a look at my github project https://github.com/nilsmagnus/gradledwheroku which is "heroku-ready". Clone it, change it, make it your own and deploy to heroku. 

Monday, April 28, 2014

Cxf wsdl2Java: using binding file to rename a complextype

Sometimes there is need to rename a complextype from the wsdl when you use wsdl2java. For example if you want the generated code to be put in a specific package (-p option) and you do not want to use the '-autoNameResolution' option. Then the external bindings file comes to the rescue! Here is the file I have used to rename "VatNumber_Exception" into "VatNumException" Happy copying!

Sunday, February 16, 2014

Setting up a moving background with Corona SDK

I just created a simple moving background written in lua for Corona SDK. The source is as follows: Use it as you wish!

Monday, December 23, 2013

Using the executorservice to create new Threads on google appengine

Appengine actually allows you to spawn new threads, as long as you follow the rules defined in the docs. Here is how I did it, copy, paste and use it as you wish.

Tuesday, June 4, 2013

Using gae plugin with gradle (gradle + appengine)

Looking for an example project using gradle and appengine? I have used the gae plugin for gradle in this simple webapp and made the sourcecode available for you. Follow this link and build with gradle 1.6 .

Saturday, May 11, 2013

git store password

To make git store your password, simply type

"git config credential.helper store"

to store it locally (for just the current repo), type

"git config --local credential.helper store"

Next time you push to the repo, git will store your password permanently.

Friday, May 3, 2013

Speeding up my build with gradle and some paralell magic

Just posting the results here, will get back to the details and some explanation in a later post.

Multi-module java project, 10 sub-modules, about 10k(?) unit-tests.

mvn clean install:  Total time: 3:52.082s ~ 232 secs
gradle clean build: Total time: 3 mins 20.987 secs
gradle clean build: Total time: 2 mins 17.648 secs (module parallel)
gradle clean build: Total time: 2 mins 0.58 secs ~ 120 secs ( module parallell, 2 threads)
gradle clean build: Total time: 2 mins 26.935 secs ( module parallell, 3 threads)



Sunday, April 28, 2013

Raspberry pi WiFi : dongle and config


  • Buy this dongle from dealextreme. This dongle works out of the box with Raspbian “wheezy” and needs no additional drivers. The chip is the realtek 8188 chip and works perfectly with linux.
  • Edit /etc/networking/interfaces according to the gist below. Replace network name and password with your own:

Halt yor pi, remove any networking cables and restart. Congrats, your pi is wireless online!

Saturday, February 16, 2013

Generate java from Wsdl with gradle

UPDATE: I have made a plugin to do this, just follow the guide on https://github.com/nilsmagnus/wsdl2java .

 The plain simple way to generate java from wsdl is this: add a javaexec task to your wsdl and run. The following code snippet will help you out:

The "wsdlsToGenerate" contains all the arguments for the org.apache.cxf.tools.wsdlto.WsdlToJava class, in the right order.

However, if you have a project like I have with 58 different wsdls, this approach is very time consuming. This is because every time createJavaFromWsdl() is called, a new java process will be started, executed and stopped. Now you have 58 sequential java processes running in your build script(!). 

Instead, why not run everything in the same java process? This can be done with code snippet 2: 


Now, this adds some dependencies to the build-script, but I can live with that.
The runtime from snippet1 with 58 wsdls is 2min 58secons on my laptop. The runtime of snippet2 is 24seconds!

Friday, August 24, 2012

Struts2 Json: java.lang.IllegalStateException: STREAM


I recently got an uncomfortable exception in struts2 I could not resolve easily. The exception "java.lang.IllegalStateException: STREAM"  'suddenly' started appearing, and broke my ajax-requests. After some fiddling, I found that I had included one to many property in my action-super-class: servletRequest. A getter on this property made the JSONWriter try to parse the whole servletRequest to json, leading to a crash with java.lang.IllegalStateException: STREAM.

The solution for me was to add servletRequest to the excludeProperties-property in my struts-config:


<action class="personSearchAction" method="getPerson" name="personSearchApi">
            <result type="json">
                <param name="ignoreHierarchy" />false
                <param name="excludeProperties" />
                    servletRequest, actionErrors,actionMessages
            </result>
</action>


Sunday, June 3, 2012

Worklog source code

The worklog-project can now be found on Bitbucket, https://bitbucket.org/nilsmagnus/worklog .