Modern Perl Best Practices by Damian Conway

bkt_perl_modern_practices

Summary: Highly recommended

Whether you want to watch this video heavily depends on how much Perl do you use, and how much do you appreciate good advices.

If you work with Perl on day to day basis, and you want to improve by applying some of the good practices, really consider this one. Damian Conway goes over variety of topics here and presents best practices. Of course the term best is heavily biassed here, as author shows what is the best in his opinion. It not always must be the case, but still, huge part of the video shows you really good practices, while remaining one presents almost best practices.

What is really worth to watch is the approach to certain topics and, to my surprise, some of the ideas can be easily adapted to Python as well. Of course you can’t get them directly, but concepts and ideas are really worth taking them into Python instead of Perl. This, for example refers to hash map manipulations, passing arbitrary number of arguments via dictionary, naming conventions, data layout in the code, code formatting and documentation, etc. Even though you won’t be able to apply these rules directly, you will be still able to follow them.

As for perl itself, there were few surprises in the video that caught my attention (I am just a casual perl developer). I was caught by some builtins (e.g. enumeration), I was surprised by some conventions that can do you lots of harm when incorrectly used (e.g. scalar vs. list context), and in general it was real eye-opener in many cases (but that might be the result of my rather reduced activity when it comes to day to day usage of language).

If you ask about lecture delivery, video quality, and material preparation – they are simply top-notch.

As for the best practices themselves, these are not defined by simple set of rules, but your attitude towards excellence in what you do – as Damian points out at the end.

Highly recommended.

How to import Safari bookmarks into Opera 25

It is not an easy task. Unfortunately, it doesn’t work out of the box, but you can cheat Opera a little bit.

So, to get all bookmarks from Safari inside Opera 25 you have to use Chrome :) Install Opera, install Chrome.

After starting Chrome, it will ask you to import bookmarks from Safari – agree to do this.

Then, open Terminal window and execute following command

cd ~/Library/Application\ Support/com.operasoftware.Opera
cp ./Bookmarks ./Bookmarks~
cp ../Google/Chrome/Default/Bookmarks .

And, that’s it :)

You have all your Safari bookmarks inside Opera.

NOTE! Opera 26 – 26.0.1656.24 gives you the option to import bookmarks directly from Opera -> Import Bookmarks and Settings … !!

Keynote – disable snap to objects

Sometimes, it’s quite frustrating when you can’t place object exactly where you want it. And that’s the result of “snap” feature in Keynote. You can easily overcome that by clicking Command button. Take a look below.



Diablo 3 – crashes at OS X and freezes my Mac

If you have experienced the issue with Diablo 3 completely freezing your Mac, take a look at file inside /Application/D3Debug.txt.

In my case, there was this issue that files were corrupted. You can tell that by examining the D3Debug.txt

2014.11.12 00:38:24.407071158	ERROR: Failed to validate 
file (Appearance\a3dun_Keep_Cart_A_Breakable.app). Details:
F9E0777B147CBC680FB8E6358613B470 778840 1

Data_D3\PC\MPQs\Cache\base\patch-base-26451.mpq

2014.11.12 00:38:24.407202563	ERROR: [Data Validation Failure] 
Diablo III was unable to validate core data files.

What you can see here is that one of the patches is corrupted. In order to fix that, you have to go inside

/Applications/Diablo III/Data_D3/PC/MPQs/Cache/base

And remove mentioned patched file + anything that is newer than that. In my case, it was: patch-base-26451.mpq file.

After removing broken patches, application downloaded all the data once again and this time it was just fine.

Building Chromium on OS X

That’s my minimal scenario:

cd ~/bin
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=`pwd`/depot_tools:"$PATH"
cd ~/opt
mkdir chromium
cd chromium/
~/bin/depot_tools/fetch --nohooks --no-history chromium
cd src
git checkout master
echo "{ 'GYP_DEFINES': 'OS=ios', 'GYP_GENERATOR_FLAGS': \
 'xcode_project_version=3.2', }" > chromium.gyp_env
~/bin/depot_tools/gclient sync
tools/clang/scripts/update.sh
GYP_DEFINES=clang=1 build/gyp_chromium
~/bin/depot_tools/ninja -C out/Debug chrome

Of course, you can find details here: http://dev.chromium.org/Home

As for the build process, it’s quite consuming:

┌─[michalo@pi]───────[16:38:40]
└─[~/opt/chromium/src] ~/bin/depot_tools/ninja -C out/Debug chrome
ninja: Entering directory `out/Debug'
[17146/17146] STAMP Chromium.app
┌─[michalo@pi]───────[19:42:04]
└─[~/opt/chromium/src]

After it is finished, you should be able to open Chromium

open ./out/Debug/Chromium.app/

Screen Shot 2014-11-01 at 7.52.19 PM

I hate Python! – importing modules from subdirectories (PYTHONPATH)

So, you have your python application, and you want to make it tidy. You want to keep all you modules in proper subdirectories (e.g. database manipulation, views, etc.). So, here you are with your subdirectories and the code.

Step one – everything at the same level

pythonapp/
├── module_root.py
└── simple.py

The code is really simple and looks like this:

''' simple.py '''
from module_root import *

print "Hello, I will call module_root"
fun_root()

and for the module_root it is equally simple:

''' module_root.py '''
def fun_root():
  print "Hello from module_root"

Step two – make it runnable from any location (using PATH, chmod +x and python location)

Now, everything is just fine when we call the application from the same directory where the file is. But what will happen if we change directory to some other location?

> cd ~
> python simple.py
python: can't open file 'simple.py': [Errno 2] No such file or directory

What we can do is to specify the file location explicitly

> python pythonapp/simple.py
Hello, I will call module_root
Hello from module_root

Now, it works fine, but we don’t want to specify the full path all the time.

First, let’s modify code a little bit

#!/usr/bin/python
''' simple.py '''
from module_root import *

print "Hello, I will call module_root"
fun_root()
> chmod +x ~/pythonapp/simple.py
> export PATH=~/pythonapp:$PATH
> simple.py
Hello, I will call module_root
Hello from module_root

Step three – We want to split codes across different sub-directories

That’s cool. So far, so good. However, there is one more issue. We don’t want to keep all the sources at the same level. We want to put them inside subdirectories. Like this:

pythonapp/
├── module
│   └── module_sub.py
├── module_root.py
└── simple.py

And, of course, we want to use module_sub as well. That’s simple! Let’s modify the code a little bit

#!/usr/bin/python
''' simple.py '''
from module_root import *
from module.module_sub import *

print "Hello, I will call module_root"
fun_root()

print "I will call module_sub"
fun_sub()

and, the code for the module_sub.py looks like this

''' module_sub.py '''
def fun_sub():
  print "Hello from submodule"

Let’s roll

> simple.py
Traceback (most recent call last):
  File ".../pythonapp/simple.py", line 3, in <module>
    from module.module_sub import *
ImportError: No module named module.module_sub

Surprise, surprise. It doesn’t work. Well, it should. At least that’s what you expect when you are coming from Java world where everything below CLASSPATH dir is treated as packages.

Step four – We want to mark directory as module

Not in here. In python, you have to mark directory as “module” by doing it explicitly. You have to create __init__.py file insde directory. Like this:

cd pythonapp/module
touch __init__.py

And your structure should resemble something like this:

pythonapp/
├── module
│   ├── __init__.py
│   ├── module_sub.py
├── module_root.py
└── simple.py

And now …

> simple.py
Hello, I will call module_root
Hello from module_root
I will call module_sub
Hello from submodule

You are happy to GO!

View Updating by C.J. Date

bkt_view_updating

Summary: Can be really tough on you

This one is the weakest in the whole series. I had really hard time while going through. I can understand the point of having views that behave as relations but I think I was not convinced that it can be easily done. Instead of listening what should be doable, I’d like to see it really working. Just as a side note. I think that this one should be watched at the very end as it requires information from previous videos.

Product page:

O’Reilly (video): View Updating

nulls and three value logic by C.J. Date

bkt_nulls_three_valued_logic

Summary: beware of nulls, they can surprise you

So far, this one is the best out of the five in the series.

nulls are painfull in db world. No matter how you define them (null, unknown, nothing at all). You can always use something that means – “missing value” – let it be: “sysmiss”, 999, “NULL”, 0. But there is still a problem. And that’s the purpose of this video, to show you how nulls can mess around with your data. You will learn how to become more suspicious in terms of results that you get from sql queries involving nulls.

Pay attention that this video will not provide you with definite answer on how to solve the problem of nulls. It is nither the sql tutorial. It’s rather a smoke sign indicating the problem.

There is, however one remark that make me think “come on, that’s not the proper way of giving the argument”. When C.J. Date discusses arguments against null defenders he jumps into “maybe” logic which stands in quite contradiction to what he defends over the whole course of the lecture.

Anyway, definitely worth watching.

Product page:

O’Reilly (video): Nulls, Three-Valued Logic, and Missing Information

tcsh – keeping your prompt always up to date

In case you want to put some variable’s value inside tcsh prompt you should consider using precmd in order to keep it updated. Inside your ~/.login put following code

alias precmd 'source ~/bin/prompt.sh'

Inside ~/bin/prompt.sh you can put any definition of prompt

set prompt="┌[%n@%m variable=${ENV_VAR}]\n└[%~] "

If you use precmd you will keep the value of ENV_VAR always updated in the prompt.

You may also want to change default “cd” behavior: tcsh + pushd + cd – very convenient settings

Nullology – Empty Sets in Database Theory and Practice by C.J. Date

Nullology – Empty Sets in Database Theory and Practice by C.J. Date

bkt_nullology

Summary: that’s one of these love-hate relationsips :)

Whether you love it or hate it depends heavily on:

– whether you are concious enough to follow the material (don’t watch it at night while preparing for sleep – definitelly not a good idea)
– whether you are able to admit that SQL queries won’t give a definite answer for all the questions
– whether you are interested in the theory behind the SQL
– whether you like to force your brain to do some real work

For me, there were few surprises in the video. Especially when topics related to empty set were discussed. I mean, it’s coverage in SQL, or better said – the lack of it.

In case you are autodidact in the field of SQL, this video will for sure open your eyes. But it will not teach you the SQL, it will show you what SQL is, comparing to relational theory.

And now, for something completelly different, my perfect quotes from the video are:

“And I can think about practical examples where that could be usefull too. They’re little bit complicated so I won’t try to talk through them now and I leave it as an excersice to you.”

and second one

“Please, remember TABLE_DEE and TABLE_DUM!”

Just get it, if you want to know the limits of SQL, simply get it.

Product page:

O’Reilly (video): Nullology – Empty Sets in Database Theory and Practice

←Older