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.

13. June 2014

Gradle Summit 2014 Lightning talk: Bamboo + Gradle

I had an opportunity to be one of Lightning talks speakers at Gradle Summit 2014 in Santa Clara – California.

I’d like to share with you slides from my talk about Bamboo and Gradle integration which we successfully deployed in Y Soft.

Link to Speaker Deck

It was exciting to hear about experience with Gradle from other speakers from companies like Netflix, Prezi or JFrog.

10. April 2014

PowerShell in Terminal of IntelliJ Idea

IntelliJ Idea has neat feature – Terminal Window.

Unfortunately on Windows it’s set just to old school cmd. Good news is that it’s possible to change it to something better. E.g. PowerShell.

Go to project settings, type “terminal”. Change value in Shell path to powershell.exe.

intellij-idea-powershell

Then you can invoke Terminal:

idea-terminal

Note: If you’re using 32bit version of Idea then it will open 32bit version of PowerShell. This is important when you want to change Set-ExecutionPolicy. 32bit and 64bit PowerShell have two different settings.

29. June 2013

True/False gotcha Python vs Ruby vs PowerShell vs NodeJS vs PHP

Evaluation of conditions is very important part programming. True is ture, false is false…

Or not? It might surprise you, but not all languages evaluate numbers, empty strings or empty arrays in the same way.

Let’s examine several technologies. Python, Ruby, PowerShell, NodeJS and PHP.

Here is small code written in Python:

def test(value):
    if value:
        print "True"
    else:
        print "False"

test(0)
test(1)
test("")
test([])
test({})

Here is similar code written in Ruby:

def test(value)
    if value
        print "True"
    else
        print "False"
    end
end

test(0)
test(1)
test("")
test([])
test({})

Let’s compare it to PowerShell:

Function Test($value) {
    if ($value) {
        Write-Host "True"
    } else {
        Write-Host "False"
    }
}

Test(0)
Test(1)
Test("")
Test(@())
Test(@{})

Same logic in JavaScript for NodeJS:

function test(value) {
    if (value) {
        console.log("True");
    } else {
        console.log("False");
    }
}

test(0);
test(1);
test("");
test([]);
test({});

Code in PHP:

<?php 
function test($value) {
    if ($value) {
        echo "True";
    } else {
        echo "False";
    }
}

test(0);
test(1);
test("");
test(array());
test(array());
?>

Results are little bit surprising:

 

Python Ruby PowerShell NodeJS PHP
0 False True False  False False
1 True True True True True
“” False True False False False
[] False True True  True False
{} False True True  True False

You can test code on-line in Cloud9 IDE except PowerShell example 😉

26. May 2013

Python virtualenv and PowerShell

It’s quite easy to set up virtual environment with isolated packages for Python in PowerShell.

Creating virtual environment is the same like in any other shell. Let’s call this environment pyenv:

pip install virtualenv
virtualenv pyenv

The last step is to activate this environment in PowerShell (watch dots and spaces):

. .\pyenv\Scripts\activate.ps1

You should see name of your virtual environment in command line. Virtual environment is active.

26. May 2013

Useful tips for PowerShell users

You can find my new powershell-examples project at GitHub.

I store there small code snippets and support tool which could be useful for day to day life with PowerShell 😉

11. May 2013

Edge – invoke PowerShell from NodeJS

Project Edge allows seamless integration of NodeJS and PowrShell.

Just install packages:

npm install edge
npm install edge-ps

Create NodeJS application which contains PowerShell code:

var edge = require('edge');

var hello = edge.func('ps', function () {/*
"PowerShell welcomes $inputFromJS on $(Get-Date)"
*/});

hello('Node.js', function (error, result) {
 if (error) throw error;
 console.log(result[0]);
});

Start application and you’ll get output

PowerShell welcomes Node.js on 05/11/2013 07:14:38

Project Edge also allows integration of NodeJS with other technologies (e.g. Python)

18. November 2012

Vim – How to edit Unicode files produced by PowerShell

It’s possible to redirect output of PowerShell command into file. E.g.:

Get-ChildItem -Recurse  | Select-Object -ExpandProperty FullName >file-list.txt

If you want to open this file-list.txt by vim you may be little bit surprised by unreadable text:

If you open the same file in notepad, then everything is perfectly readable.

There is simple fix for vim suggested by Tony Mechelynck. Just open .vimrc in your home directory and add following lines:

if has('multi_byte')                   " multibyte features compiled-in 
  if &encoding !~? '^u'                " the OS locale is not Unicode 
    if &termencoding == ''             " empty means 'use &enc' 
      let &termencoding = &encoding    " avoid clobbering keyboard codes 
    endif 
    set encoding=utf-8 " we can do it, now that the kb is taken care of 
  endif 
  set fileencodings=ucs-bom,utf-8,latin1 " heuristics for existing files 
  setglobal bomb fileencoding=latin1   " defaults for new files 
                     " 'bomb' doesn't apply to latin1 
                     " it applies when 'fenc' is manually set to Unicode 
endif

Result:

5. August 2012

Console2 for Windows – semi-transparent NodeJS shell, PowerShell or cmd

Update: I switched from Console2 to ConEmu. ConEmu is far more advanced.

Console2 is great little front-end for Windows. It makes PowerShell even more usable. It’s very flexible and you can configure console window to behave like terminal window on MacOS or Linux. It has also support for transparency. It’s simply great. No need to add any more words. Just try it.

I’d like to add few more hints.

Enable transparancy

  • Go to Settings – Appearance – More…
  • Select Window transparency – Alpha
  • Change alpha level of Active and Inacative window.

Result:

Copy on left mouse button click, paste on middle button click

Default configuration of mouse is not very useful. You have to press Shift and Left Mouse to select and copy text. Make small adjustment:

  • Settings – Hotkeys – Mouse
  • Change: Copy/clear selection to Left + Shift
  • Change: Select text to Left

Use Console2 as front-end for NodeJS

You can use Console2 to invoke also NodeJS shell. Just create Tab definition for NodeJS.

  • Go to Settings – Tabs
  • Add NodeJS and set Shell to: “C:\Program Files (x86)\nodejs\node.exe”

Create new Tab with NodeJS profile:

Awesome 🙂

  • Where’s the fish?

  • Translations

  • Further info

  • Twitter

    Follow @jurajmichalek on twitter.

  • Comments

  • Tags

  • Topics