Jan 30, 2015

Open big files in Komodo

Although Komodo is great, it will be broken on big files. The reason is costly syntax highlight.

Big files can be: too many lines; or big filesize.

To overcome this, create and run this macro "once".
After running, it will be persisted as a preference.
My setting is 200Kb and 5000 lines limit : )

// Let Komodo able to open big files by disable Syntax Highlight
var gprefs = Components.classes["@activestate.com/koPrefService;1"].
  getService(Components.interfaces.koIPrefService).prefs;
gprefs.setLongPref("documentByteCountThreshold", 200000);
gprefs.setLongPref("documentLineCountThreshold", 5000);
alert('All was set. Openning big files is OK right now');

Jan 29, 2015

Ruby notes



My discoveries:

print : echo bare text
p: print object as it as, with new line
puts: echo text with new line

alias create alias for existing method, var

ensure always executed at block termination

block comment
=begin 
=end

undef remove function definition


convention:
Eg: eql?
method with a question mark return a bool value

Eg: delete! (bang symbol)
method with exclamation ! indicates that it's destructive: change object than a copy

Eg: name=
method ends with = is a setter


block can be wrapped by "do .. end" or { }
run by "yield"
Check for existence via if block_given?

:symbol 
storage optimized string

Global names is from Kernel module


replace string once:
string['search']= 'replace'

replace all
string.gsub 'search', 'replace'

regex
string[/regex/]
regex replace uses the same syntax

string.split(/, /) you might guess

Object methods:
obj.to_s
obj.class

string.to_sym -> :symbol
num_string.to_i -> integer
range.to_a -> array

%w[ string1, ... ]
%i [ symbol1, ...]
[num1, ... ]

array << x # Add x to array (immuttable)

set operator: intersect &, diffeence -, union | 
array.join sep
array.shift

Hash.new(default_value)
hash.key?
hash.value?
hash.keys
hash.values

Gem gotcha

If your local machine's hostname is set to your name, you will likely hit a trouble while installing gem:

"your-dns-needs-immediate-attention"

That's all I know. That message is oversay!

What to do is: set your hostname to a real top-level domain.
If it's a local machine, set it to "your-name.local"
Bold characters must be exactly typed!

# Linux
hostname -s your-name.local 

# Mac OSX
scutil --set HostName your-name.local


Dreamy app stack

If choosing my own stack, I will choose:

- Python: Beauty, simple, powerful. It's slow but productive. Anything has tradeoff ; )
Framework: Tornado

- Cassandra: Autoscale, SQL-like query, Fast write, able to tune consistency: What can I ask more for a database!

- WeedFS: Distribute storage.

Jan 26, 2015

Find PHP bottleneck!

There are many ways, such as Xhprof. However, because I already had Xdebug I will use Xdebug to profile the app; and setup Xdebug seems easier than Xhprof.

1. First set these in .htaccess (or php.ini)

php_value xdebug.profiler_enable 1
php_value xdebug.profiler_output_dir "/var/xdebug/"

2. Make sure that /var/xdebug/ is writable by web app, or change it to your folder.

3. Run the request to benchmark.

4. Each request will result in a new file /var/xdebug/cachegrind.out.NNNN

5. To read these stats needs brew install qcachegrind on Mac OSX, or kcachegrind on Linux.
After installing them, run, eg: qcachegrind /var/xdebug/cachegrind.out.NNNN

6. Examine by clicking on "self" column; consider function that take longest time. Well from here we need to think about what caused these bottlenecks.


Jan 23, 2015

Custom Komodo look and feel

Komodo's user interface can be "styled" using CSS!
Komodo is written using Mozilla framework. Internally it's HTML/CSS with Javascript/Python API.

Howto:

  • Install "DOM Inspector" add-on. Use this to find out element ID, class you want to style, similar as you inspect a website using development tool
  • Create  ~/Library/Application Support/KomodoEdit/8.5/XRE/chrome/userChrome.css
  • Write your styles ; )


Jan 21, 2015

About Cassandra

https://ria101.wordpress.com/2010/02/24/hbase-vs-cassandra-why-we-moved/

- About CAP theorem, Cassandra offers consistent level on reading/writing (selectable CAP tradeoffs)
- Level ALL
- Level QUORUM
- Level ONE
- Symmetric system: no single point of failures. Equal role for all nodes using P2P Gossip
- Simple admin and scale

Jan 18, 2015

Auto reload while development

While developing web application using Python (or Ruby), I often run web server by ourself. If a bug was introduced, web server would die. After debugged it,  I have to re-run it manually! Well, today I figure out a way to restart it automatically ^^. Basically a Bash script will loop and restart on your behalf.

To having this work for you, replace PYTHON_APP (or entire script function) to your specific needs.
Have fun!

#!/bin/bash
SLEEP_INTERVAL=2 # second
PYTHON_APP="python3 -m tasty serve:web --port=9100"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
script () {
  cd $DIR
  PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 PYTHONDONTWRITEBYTECODE=1 PYTHONDEBUG=1 PYTHONIOENCODING=utf8 $PYTHON_APP
}
echo "Development mode."
until script; do
    echo "Crashed with exit code $?.  Respawning.." >&2
    sleep $SLEEP_INTERVAL
done