Debug Command for unix n windows of networking, ip, firewall, port forwarding

Re: SSH to Debian Guest from Windows host via Putty Postby noteirak » 19. May 2013, 11:24

Run the following on the host : CODE: SELECT ALL EXPAND VIEW ipconfig /all route print arp -a netstat -an | find “LISTENING” netsh advfirewall show allprofiles

Run the following in the guest : CODE: SELECT ALL EXPAND VIEW sudo ifconfig -a sudo route sudo arp sudo netstat -lnp sudo iptables -L -n -v

and in virtualbox, if u opening port for flask, pls use
or ensure the port forwarding is go to in your VM

my python flask deploy flow

How to update python api sudo su deploy

cd /home/deploy/your-python-project
git pull
source ../py3.4/bin/activate
python bdist_egg
easy_install dist/<python_proj.egg>
alembic upgrade head
uwsgi –reload ~/

git download the src code -> (env) -> pack it into egg -> using easy_install to install the python egg -> update db migration -> restart server

my 幻想 docker flow

  • just write your code first, without docker
  • git push your application when you can first deploy
  • create a docker image, in dockerFile or init of your image, git clone the lastest code
  • pack it into image
  • for old machine, update the container with new image

  • one application one docker
  • mysql no need include in docker, and it should not go into a separate docker. just find a machine or one of a machine to run it.

Server Deployment Common Practice


  • You has a admin user call your name. Say roychung for me. And other admin has own account too.
  • A user call deploy or your service name for the main service of your written code. It should not be a sudoer. And suppose you cannot login via ssh.
  • For different service, may be redis. You may consider to open an account for it too.
  • So how to deploy to the deploy user? You may consider using sudo su deploy
  • Using Fabric for deployment, login with your own admin account and sudo su make your life easier when there are several server
  • Using redis as example, you may use sudo to install redis (or using redis user install on it home folder), but running redis command will be using that redis user. So other user can modify it without knowing your account

decorator in python

class entryExit(object):
def __init__(self, f): 
    print 'entry init enter' 
    self.f = f 
    print 'entry init exit'
def __call__(self, *args): 
    print "Entering", self.f.__name__ 
    r = self.f(*args) 
    print "Exited", self.f.__name__ 
    return r
print 'decorator using'
def hello(a): 
print 'inside hello' 
return "hello world " + a
print 'test start' 
print hello('friends')
>>> ================================ RESTART ================================ 
decorator using 
entry init enter 
entry init exit 
test start 
Entering hello 
inside hello 
Exited hello 
hello world friends

vagrant simple example

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don’t touch unless you know what you’re doing!

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provider “virtualbox” do |v|
v.memory = 1024
v.cpus = 1
config.vm.define “prod” do |prod_config| = “jamnplayer” “forwarded_port”, guest: 8080, host: 8081 “forwarded_port”, guest: 5000, host: 5001 “forwarded_port”, guest: 22, host: 2200, auto_correct: false, id: “ssh”
prod_config.vm.host_name = “prod”


# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don’t touch unless you know what you’re doing!

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provider “virtualbox” do |v|
v.memory = 2048
v.cpus = 1
config.vm.define “default” do |default_config| = “ubuntu-14.04” “forwarded_port”, guest: 6543, host: 6543 “forwarded_port”, guest: 8080, host: 8080 “forwarded_port”, guest: 5000, host: 5000 “forwarded_port”, guest: 22, host: 2222, auto_correct: false, id: “ssh”
default_config.vm.host_name = “default”

python property, getter, setter

Try this: Python Property

The sample code is:

class C(object):
def __init__(self):
self._x = None

def x(self):
“””I’m the ‘x’ property.”””
print “getter of x called”
return self._x

def x(self, value):
print “setter of x called”
self._x = value

def x(self):
print “deleter of x called”
del self._x

install harmtrace in linux

install haskell-platform
update cabal
cabal install HarmTrace

it will warn u no gsl
install gsl then

sudo apt-get install libgsl0-dev liblapack-dev

cabal install HarmTrace



harmtrace recognise –file=/Users/roychung/project/harmtrace/let_it_be.mp3 –mode=group –grammar=pop -o=/Users/roychung/project/harmtrace/output –log-dir=/Users/roychung/project/harmtrace/log –csv-dir=/Users/roychung/project/harmtrace/csv –sa-path=/Users/roychung/project/harmtrace/sonic-annotator –vamp-dir=/Users/roychung/project/harmtrace/vamp

in /Users/roychung/project/harmtrace/vamp need transform file
which is generate by sonic annotator

then it will say no sox

then sox want lame and mad (from readme)
install them

transform file is sth like :
$ sonic-annotator -s vamp:vamp-example-plugins:fixedtempo:tempo
@prefix xsd: <> .
@prefix vamp: <> .
@prefix : <#> .

:transform a vamp:Transform ;
vamp:plugin <> ;
vamp:step_size “64”^^xsd:int ;

vamp:block_size “256”^^xsd:int ;
vamp:parameter_binding [
vamp:parameter [ vamp:identifier “maxbpm” ] ;
vamp:value “190”^^xsd:float ;
] ;
vamp:parameter_binding [
vamp:parameter [ vamp:identifier “maxdflen” ] ;
vamp:value “10”^^xsd:float ;
] ;
vamp:parameter_binding [
vamp:parameter [ vamp:identifier “minbpm” ] ;
vamp:value “50”^^xsd:float ;
] ;
vamp:output <> .

beat-tracker transform need change to 256 …
it has error about it, or u cannot generate the beat-tracker.txt

[magento] some important file

read the following file can know more about the route and flow

store/app/code/core/Mage/Core/Controller/Varien/Front.php <== front controller store/app/code/core/Mage/Core/Model/App.php <== (Main) App Model (Object) about REFERENCE : 即係跳 block 專用技
Diagram 3

is used to make reference to another block. By making a reference to another block, the updates inside will apply to the it correlates to (see diagram 3).

In order to make the reference, you must target the reference to a block by using the ‘name’ attribute. This attribute targets the tag’s ‘name’ attribute. So if you were to make a reference by , you’re targeting the block called .

[magento] debugging ? open css hint

need some tricks:

Categories: Blog, Magento
Developing in Magento without these debugging tips can be challenging! Here is how you can debug magento:

Turn on Template Path Hints
Turn on error/system logging
Turn on SQL logging
Display PHP errors

Turn on Template Path Hints

Would you like to see the path of the file that is producing the HTML for each block on the page?

1. Log into the admin

2. Goto -> System ->Configuration, and on the bottom of the list select “Developer”

3. click on Debug – you will only see “Profiler”. Here is the trick – you have to switch the “Current Configuration Scope:” [in the upper left] to a website instead of default. Select “Main Website”.

4. Now you will see the selection for Template Path Hints – check yes. This will display the path of the template for each block of the page so you can find stuff! You can also choose to “Add Block Names to Hints” to see the corresponding model class for the block.

Turn on error/system logging

1. In the admin Goto -> System ->Configuration, and on the bottom of the list select “Developer”

2. Select the Log Settings tab and put Enabled = Yes

3. *to avoid any permissions issues, create folder/file


Turn on SQL logging

To enable SQL Debugging find the file


change line 45
protected $_debug = false;

protected $_debug = true;

It will then generate the file var/debug/sql.txt.

*If you have any issues create this file manually first…

Display PHP errors

Frustrated you can’t see your PHP errors? This is how you turn them on – for development use only, don’t do this on a production site!

In Index.php change


ini_set(‘display_errors’, 1);

multiple domain to subfolder htaccess rewrite

RewriteEngine On
RewriteBase /

# —————————————
# BEGIN Domain to folder mapping

# pointing to folder_1
ReWriteCond %{HTTP_HOST}
ReWriteCond %{REQUEST_URI} !so9sad/
ReWriteRule ^(.*)$ so9sad/$1 [L]

# pointing to folder_2
ReWriteCond %{HTTP_HOST}
ReWriteCond %{REQUEST_URI} !youtube9loop/
ReWriteRule ^(.*)$ youtube9loop/$1 [L]

# END Domain to folder mapping
# —————————————

# —————————————
# BEGIN htaccess pretection

order allow,deny
deny from all

# END htaccess pretection
# —————————————

With wordpress:

RewriteEngine On
RewriteBase /

# —————————————
# BEGIN Domain to folder mapping

# pointing to folder_1
ReWriteCond %{HTTP_HOST}
ReWriteCond %{REQUEST_URI} !folder_1/
ReWriteRule ^(.*)$ folder_1/$1 [L]

# pointing to folder_2
ReWriteCond %{HTTP_HOST}
ReWriteCond %{REQUEST_URI} !folder_2/
ReWriteRule ^(.*)$ folder_2/$1 [L]

# END Domain to folder mapping
# —————————————

# —————————————
# BEGIN WordPress

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress
# —————————————

# —————————————
# BEGIN htaccess pretection

order allow,deny
deny from all

# END htaccess pretection
# —————————————


活用 CI log to know a model is loaded

You can use the log_message() function and put it in the constructor, so it will be executed when it initiated

Put this in your model’s constructor (parent::Model())

log_message (“debug”, “Yourmodel is loaded”);
don’t forget to set the log config to debug mode, see the config.php file

$config[‘log_threshold’] = 2;
And set the system/logs directory permission to writable (by default CI will create the log files here)

or set the logs directory in another dir

$config[‘log_path’] = ‘another/directory/logs/’;
CI will then create the log file in the directory. monitor the log files as you like. You can get the debug message to see if your model is already loaded or not in the log files.

src :

save me time ! solve BeanCreationException for TilesConfigurer

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ’tilesConfigurer’ defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.servlet.view.tiles2.TilesConfigurer]: Constructor threw exception;


add this dependencies to solve :

js object and js function class

var yung = { variable : xxx, add: function () { } }

they are all accessible by other

yung.Class = function(someSetting) {

var privateVar
function privateFunction
function publicFunction

//public function
$.extend(this, {
publicFunction: publicFunction

yung.obj = new yung.Class(someSettings);



(function(object1, jquery, window, settings) {


})(object1, jquery, window, settings);

flash is suck in urlStream or fileRef.upload

urlStream is always good, it trigger the browser request to server, but very raw and cannot detect the upload progress (no progress event fire during upload) ( cal the speed and use Timer to pretend the progress bar )

but fileRef.upload is really poor, it use its user agent, so it is independent to browser, so no session can be save, it make a new session i think

judge yourself use which class then 🙂

skype development ref

@ww_boy6 roy:
this can help ?
actually they think so 麻煩 becoz they want to do VOIP
but we only need msg
u see this web app can do skype
for ww

[jquery] xxx.fn.funtionName() {} is prototype


All objects have a prototype property. Whenever the interpreter looks for a property, it also checks the prototype. jQuery uses that extensively to add methods to jQuery instances.

var form = $(“#myform”);
form.clearForm; // undefined
form.fn.clearForm = function() {
return this.find(“:input”).each(function() {
this.value = “”;
form.clearForm() // works for all instances of jQuery objects, because the new method was added to the prototype

(This example needs clarification: how does it modify the prototype when the word “prototype” doesn’t appear anywhere? The implication is that form.fn is simply an alias for form.prototype, but if that’s the case then it should be explained. :-?)

In javascript:the definitive guide 5 edition,dont add attibute to Object.prototype

[apache][phpmyadmin] change phpmyadmin to 443 using default phpmyadmin package

idea: rewrite engine to make http => https

1. go to .htaccess in /usr/share/phpmyadmin

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

2. activate the rewrite engine by a2enmod rewrite , then restart apache2

3. make SSL cert, some command like the following
#openssl req $@ -new -x509 -days 365 -nodes -out /etc/apache2/apache.pem -keyout /etc/apache2/apache.pem


4. permission for the cerf : #chmod 600 /etc/apache2/apache.pem

5. Listen 443 in ports.conf

6. Set the phpmyadmin conf in sites-available:

# phpMyAdmin default Apache configuration
Alias /phpmyadmin /usr/share/phpmyadmin

DocumentRoot /usr/share/phpmyadmin
SSLEngine on
SSLCertificateFile “/etc/apache2/apache.pem”

Options Indexes FollowSymLinks
AllowOverride All
DirectoryIndex index.php

AddType application/x-httpd-php .php

php_flag magic_quotes_gpc Off
php_flag track_vars On
php_flag register_globals Off
php_value include_path .

# Authorize for setup

AuthType Basic
AuthName “phpMyAdmin Setup”
AuthUserFile /etc/phpmyadmin/htpasswd.setup

Require valid-user

# Disallow web access to directories that don’t need it

Order Deny,Allow
Deny from All

Order Deny,Allow
Deny from All

7. Finish.