24. May 2015

How to revert no-site-packages for virtualenv on Windows with Python 3.4

Python has support for virtual environment. It’s very handy to set up isolated space where you can store specific packages for the project. You can use command virtualenv to create virtual environment.

It’s very common to add option --no-site-packages which will isolate environment from packages installed in system.

Sometimes it is necessary to revert this option.

Linux and Mac users can control it by mechanism based on one file:

venv/lib/python3.4/no-global-site-packages.txt

When this file exists Python is ignoring packages from system.

In case of Windows there is configuration file stored in venv/pyenv.cfg and you can change configuration of global packages:

home = c:\Python34
include-system-site-packages = true
version = 3.4.3

Change the configuration and call Scripts\Activate.ps1 to load Python virtualenv to PowerShell.

23. May 2015

Flask OAuthlib Multiple Scope Values for calling Google API

Google provides myriad of APIs for invoking operations on Google App Platform. It’s possible to integrate this calls with custom app using OAuth.

One option is to write app based on Flask (Python Microframework) with OAuth support provided by Flask-OAuthlib.

There is simple example of web app in Lepture’s repo.

The key practice in OAuth world is to get user’s consent to access API on her/his behalf. Often implemented by simple consent screen.

google-consent

You need to perform two steps to display consent screen:

  • enable API in Developer Console
  • define scope in your application

The second step is straightdorward:

google = oauth.remote_app(
    'google',
    ...
    request_token_params={
        'scope': 'https://www.googleapis.com/auth/userinfo.email'
    },
    ...
)

It works perfectly. The only problem is that this solution provides access just to one API.

The question is: How to request access to multiple scopes?

You can find many hints about OAtuh for other frameworks, that you should separate scopes by comma. That won’t work.

Correct solution is to use white space as delimiter of scopes (as suggested for HTML forms).

google = oauth.remote_app(
    'google',
    ...
    request_token_params={
        'scope': 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/calendar.readonly https://www.googleapis.com/auth/tasks'
    },
    ...
)

9. May 2015

How to decode stereogram by GIMP

Sometime ago I wrote article How to decode stereogram by Photoshop.

I made small experiment and it’s possible to achieve similar results by GIMP.

Here is stereogram (Magic Eye Picture) created by Easy stereogram builder.

stereogram-sample

Open file in GIMP. Duplicate the layer.

gimp-duplicate-layers

Change layer mode to Difference.

gimp-difference

Select Move tool from GIMP toolbox (M).

gimp-move-tool

Start moving the layer to the right. You can use arrows to move the layer. If you prefer mouse then click, press and hold CTRL key to avoid shifting in both X and Y axes.

Here is the result:

gimp-stereogram-solution

 

6. May 2015

OpenRefine date conversions

One of common tasks for OpenRefine is conversion of dates from String.
Conversion could be performed by toDate function.

Source data:

11-04-15 9:28
12-04-15 8:56

Open Edit cell – Transform for the column and type following GREL:

value.toDate("dd-MM-yy h:mm")

Result (in Date format):

2015-04-11T09:28:00Z
2015-04-12T08:56:00Z

Another example. Source data

11/04/2015 09:28:25
13/04/2015 08:56:57

GREL:

toDate(value, "dd/MM/yyyy hh:mm:ss")

5. May 2015

C language in our world 2015 – slides

Slides available in formats: PDFSlideShare

Source code: GitHub/ysoftdevs/cpp-examples

30. December 2014

PF 2015

This year I have another special game for you as Pour Felicitér card.

Go to: http://www.ysofters.com/pf2015/

pf2015-play

You can enjoy PF games from previous years: PF 2014, PF 2013,PF 2012,PF 2011, PF 2010

8. December 2014

C++ in our world 2014 – slides


Slides available in formats: PDFSlideShare

Source code: GitHub/ysoftdevs/cpp-examples

4. December 2014

Problem: Any link on Drupal site shows the same page after upgrade to Apache 2.4 and PHP 5.6

Upgrading old Linux server is challenging task. Many things could break or stop working.

One of problems was that Drupal sites with htaccess file stopped working and any URL was pointing to the same main page.

htaccess file is often use to allow creation of nice URL. It typical content was:

RewriteRule .* %{DOCUMENT_ROOT}/index.php/$0 [L]

This rule is not working with new Apache and PHP. It was necessary to replace it by:

RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Reload Apache and Drupal site should work again.

30. August 2014

SimulANT+ Scripting Interface CHM – Windows help does not display content

I was testing SimulANT+ software from www.thisisant.com. Application was working without problem, but document with API was not readable. Only index was visible, but no content.

The API documentation is stored in file SimilANT+ Scripting Interface.chm. The problem with CHM content is classical gotcha on Windows.

When you download ZIP with CHM then Windows will automatically mark this file as downloaded from Internet. You have to unblock content of file manually.

simulant-chm-unblock

Other alternative is to use 7-zip or other extractor which does not keep this flag.

Note: SimulANT+ has Python API, hooray! :)

11. August 2014

Gradle PMD – Can’t find resource null

Gradle has support for PMD. You can find following example on internet:

apply plugin: 'pmd'

pmdMain {
  ruleSets = [ "basic", "strings" ]
}

This code is not working with Gradle 2.0. Here is error message:

:clean
:pmdMain FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':pmdMain'.
  Can't find resource null. Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: C:\Users\georgik\tmp\install\gradle-2.0\lib\gradle-launcher-2.0.jar

The reason is simple. In case of Gradle 2.0 you must add language prefix before name of rule. You must use java-strings instead of plain strings.

Here is correct example (available also on YSoftDevs Github):

apply plugin: 'pmd'

pmdMain {
  ruleSets = [ "java-basic", "java-strings", "java-braces" ]
}

You can find more rules for PMD in official documentation.

Thanks Matt Sicker for correct solution.

  • Where’s the fish?

  • Further info

  • Twitter

    Follow @jurajmichalek on twitter.

  • Babel fish

      Translate from:

      Translate to:

  • Tags

  • Topics

  • Comments