Wednesday, January 30, 2013

modx page error

this caused me an hour to finally realize,
never ever use reserved querystring Q and A in modx

Tuesday, January 29, 2013

rails engine initializer to add upload path


sample: lib/mymodule/lib/mymodule/engine.rb

module MyModule
  class Engine < ::Rails::Engine
    isolate_namespace MyModule
    #dependency setting is important here
    initializer 'Entcommerce.initialize_upload', :after=> :disable_dependency_loading do |app|
      #Rails.logger.debug "Root: " + Rails.root.to_s
      config.upload_path = Rails.root.join("assets").join("images").join("product")
      #Rails.logger.debug "upload_path: " + config.upload_path.to_s
    end
  end
end



#To get this setting from controller
Rails.application.config.upload_path

reference:

Monday, January 28, 2013

rails generator templates


Scaffold View templates:
https://github.com/rails/rails/tree/master/railties/lib/rails/generators/erb/scaffold/templates
#replace able through
lib/templates/erb/scaffold/ (rails 3.2)

Scaffold Controller template:
https://github.com/rails/rails/tree/master/railties/lib/rails/generators/rails/scaffold_controller/templates
lib/templates/rails/scaffold_controller/controller.rb

git submodules

When you need sub projects to be attached to other git,
its possible to do this with git submodule.

first, if you have already added this sub module as part of the root git, remove this with:
(remember to do a backup first):
git -rm -r --cached lib/mymodule

#next,
cd lib/mymodule
git init
#add .gitignore if required
git add *
git commit -a

#now back to root project and add this sub directory as sub git
cd ../../
git submodule add ssh://remote-path-to-git/ lib/mymodule
git commit -a
#notice .gitmodules and file: /lib/mymodule will be added to git





Sunday, January 27, 2013

Mongodb SyntaxError: invalid property id on $or

the problem example:
db.tablename.find(
{"_id.period":{"$gte": ISODate("2011-01-01T00:00:00"), "$lte": ISODate("2011-12-31T23:59:59")}, 
{"$or": [{"value.field1": "COMMUNICATION", "value.field2": "GOVERNMENT INSTITUTIONS - LOCAL"}, {"value.field1": "COMMUNICATION", "value.field2": "INTERNET SERVICE PROVIDER"}]}
})

the solution:
#remove { } wrapper from $or

{"_id.period":{"$gte": ISODate("2011-01-01T00:00:00"), "$lte": ISODate("2011-12-31T23:59:59")}, 
"$or": [{"value.field1": "COMMUNICATION", "value.field2": "GOVERNMENT INSTITUTIONS - LOCAL"}, {"value.field1": "COMMUNICATION", "value.field2": "INTERNET SERVICE PROVIDER"}]
})


Tuesday, January 22, 2013

modx windows 2008 manager unable to load

found that the minified have issues on windows 2008.
workaround is edit
manager/min/index.php
change:
$hasVirtualAssetsURL = empty($min_documentRoot) || strpos(MODX_ASSETS_PATH, $min_documentRoot) !== 0 || strpos(MODX_ASSETS_PATH, MODX_ASSETS_URL) === false || substr(MODX_ASSETS_PATH, 0, strpos(MODX_ASSETS_PATH, MODX_ASSETS_URL)) !== $min_documentRoot;

if ($hasVirtualAssetsURL) {
    $min_serveOptions['minApp']['allowDirs'][] = MODX_ASSETS_PATH;
    $min_serveOptions['minApp']['virtualDirs'][MODX_ASSETS_URL] = MODX_ASSETS_PATH;
}
to:

$hasVirtualAssetsURL = false;
$min_serveOptions['minApp']['allowDirs'][] = MODX_ASSETS_PATH;
if ($hasVirtualAssetsURL) {
    $min_serveOptions['minApp']['allowDirs'][] = MODX_ASSETS_PATH;
    $min_serveOptions['minApp']['virtualDirs'][MODX_ASSETS_URL] = MODX_ASSETS_PATH;
}

Sunday, January 20, 2013

Cordova create An unexpected error occurred: "$ANDROID_BIN" create project --target $TARGET

It turns out that ive mis named my package name
package name should be prefixed accordingly with 3 namespace
example
com.compname.projectname

try this:
./create ~/mobiles com.company.projectname projectname

Refinery CMS Dragonfly Shell Command Failed

this cms requires bundler and imagemagick

to install using mac port
sudo port install imagemagick


sudo ln -s /opt/local/bin/convert /usr/local/bin/convert
sudo ln -s /opt/local/bin/identify /usr/local/bin/identify


Wednesday, January 16, 2013

Ruby MySQL ActiveRecord::ConnectionNotEstablished

Trying my first ruby on rails, got me into this problem.
Modify gemfile, and add this be:

#below gem 'sqlite3'
gem 'mysql2'


Example database.yaml

development:
  adapter: mysql2
  encoding: utf8
  database: yourdbname
  username: yourusername
  password: "your password"
  host: localhost
  port: 3306

Tuesday, January 15, 2013

Mod security sample configuration

on CentOS
sudo yum install mod_security


follow instruction here:
https://github.com/SpiderLabs/owasp-modsecurity-crs

copy modsecurity_crs_10_setup.conf.example and name as modsecurity_crs_10_setup.conf

add this to modsecurity_crs_10_setup.conf on top:
SecRuleEngine On


after install, edit
/etc/httpd/conf/conf.d/00.modsecurity.conf
add :
Include 
[path-to-crs]/modsecurity_crs_10_setup.conf
[path-to-crs]/base_rules/*.conf


Monday, January 14, 2013

CSF for ZPanel

After installation, add these to /etc/csf/csf.pignore


exe:/usr/lib/courier-imap/bin/pop3d
exe:/usr/lib/courier-imap/bin/imapd
exe:/usr/sbin/pure-ftpd
exe:/usr/local/apache/bin/httpd
exe:/usr/sbin/sshd
exe:/usr/sbin/proftpd
exe:/usr/libexec/dovecot/imap
exe:/usr/libexec/dovecot/pop3
exe:/usr/sbin/named
exe:/usr/sbin/ntpd
exe:/bin/dbus-daemon
exe:/usr/sbin/ntpd
exe:/usr/sbin/exim4
exe:/sbin/ntpd

exe:/usr/libexec/postfix/pickup
exe:/usr/libexec/postfix/smtpd
exe:/usr/libexec/postfix/qmgr
exe:/usr/libexec/mysqld
exe:/usr/sbin/httpd
exe:/usr/libexec/dovecot/anvil
exe:/usr/libexec/dovecot/auth
exe:/usr/libexec/dovecot/pop3-login
exe:/usr/libexec/dovecot/imap-login


Friday, January 11, 2013

mac port installing ruby 1.9


sudo port uninstall ruby
sudo port uninstall rb-*
sudo port clean ruby
sudo port clean rb-*

sudo rm -rf /usr/bin/rake

#For Mac Port
curl -L https://get.rvm.io | bash -s stable --ruby
Reopen console / terminal
rvm install 1.9.3 --with-openssl-dir=/usr
rvm alias create default 1.9.3
rvm use 1.9.3 --default

#For CentOS (linux)
sudo su #or login as root
curl -L https://get.rvm.io | bash -s stable --ruby
#exit and relogin as root
sudo rvm install 1.9.3 --with-openssl-dir=/usr
rvm alias create default 1.9.3
rvm use 1.9.3 --default

sudo gem install rack 
sudo gem install rake 
sudo gem install rails
sudo gem install passenger
sudo gem install mysql2

rvmsudo passenger-install-apache2-module


#To undo set default ruby,
rvm reset

Sunday, January 6, 2013

Installing mod passenger with Mac Port

First, makesure you have apache installed,
default path on
/opt/local/apache2

then
sudo gem install passenger

next
sudo passenger-install-apache2-module


To get ruby 1.9 version on macport, follow here:

Saturday, January 5, 2013

jQuery Ajax not calling in IE8!

WTH!
Its due to few issue:
one: dataType: json
Never use it, instead, call:
success: function(data) {
var result = eval("(" + data + ")");

}

2nd, when passing data parameter, makesure no tailing ,
example:

data: {x:1, y:2, },
success: function(data) {

},

notice the highlighted commas above,
if the array ended with no further variables, do not add comma.


Friday, January 4, 2013

ModX Manager error 500

Upon completed the setup process,
i stumble upon modx error 500.

after adding into manager/index.php
error_reporting(E_ALL);

ini_set('display_errors','On');


i found unable to render header.tpl

the problem is path issue.
open core/config/core.config.php

and makesure you have set the full path to the server for:
$modx_core_path
$modx_processors_path
$modx_connectors_path
$modx_manager_path
$modx_base_path

example:

if (!defined('MODX_CORE_PATH')) {
    $modx_core_path= 'C:/Domains/your_domain_here/wwwroot/core/';
    define('MODX_CORE_PATH', $modx_core_path);
}
if (!defined('MODX_PROCESSORS_PATH')) {
    $modx_processors_path= 'C:/Domains/your_domain_here/wwwroot/core/model/modx/processors/';
    define('MODX_PROCESSORS_PATH', $modx_processors_path);
}
if (!defined('MODX_CONNECTORS_PATH')) {
    $modx_connectors_path= 'C:/Domains/your_domain_here/wwwroot/connectors/';
    $modx_connectors_url= '/connectors/';
    define('MODX_CONNECTORS_PATH', $modx_connectors_path);
    define('MODX_CONNECTORS_URL', $modx_connectors_url);
}
if (!defined('MODX_MANAGER_PATH')) {
    $modx_manager_path= 'C:/Domains/your_domain_here/wwwroot/manager/';
    $modx_manager_url= '/manager/';
    define('MODX_MANAGER_PATH', $modx_manager_path);
    define('MODX_MANAGER_URL', $modx_manager_url);
}
if (!defined('MODX_BASE_PATH')) {
    $modx_base_path= 'C:/Domains/your_domain_here/wwwroot/';
    $modx_base_url= '/';
    define('MODX_BASE_PATH', $modx_base_path);
    define('MODX_BASE_URL', $modx_base_url);
}


Next:
delete all contents in
core/cache/*

Finally, you will realize the js files in manager isnt working, due to a bug in modx which have been fixed in nightly build:
http://tracker.modx.com/issues/7418

It wasnt fixed, comment off these line in manager/min/index.php works!
//if ($hasVirtualAssetsURL) {
// $min_serveOptions['minApp']['allowDirs'][] = MODX_ASSETS_PATH;
// $min_serveOptions['minApp']['virtualDirs'][MODX_ASSETS_URL] = MODX_ASSETS_PATH;
//}



Tuesday, January 1, 2013

Cpanel and PHP error 500

Sometimes its not possible to see what are the error that return error 500 in php, especially with wordpress.

One way to check all php error are here:
/usr/local/apache/logs/error_log

Found one common problem lately was that the /home/username/ directory became writable by group which return the error 500.
changing the permission solve the issue
sudo chmod og-w /home/username/