nraj
nraj
TechBites
82 posts
Don't wanna be here? Send us removal request.
nraj · 11 years ago
Text
Node installation on a screwed up OSX env.
Cleaning up development env. on Mac
1. Remove any traces of node and family
Excellent set of instructions given here:
http://stackoverflow.com/questions/11177954/how-do-i-completely-uninstall-node-js-and-reinstall-from-beginning-mac-os-x
2. Use homebrew and nothing else to start fresh.
See instructions at -
http://thechangelog.com/install-node-js-with-homebrew-on-os-x/
3. brew update
If that fails, then
cd $(brew --repository) git reset --hard FETCH_HEAD
4. brew doctor
Per the recommendations of doc, I ended up -
   - upgrading  xCode
   - brew prune to mend broken symlinks
   - brew installing missing - brew missing
   - brew install openssl. 
5. fix the path by setting at higher priority local installations instead of system's 
echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile
6. Finally, the nirvana -
brew install node
0 notes
nraj · 11 years ago
Text
Mount | Sharing bet Windows & Linux server
Libraries to be installed are samba-client, samba-common, cifs-utils
yum install samba-client samba-common cifs-utils
Create directory for shared drive 
sudo mkdir -p /mnt/sharedDrive
Mount the Windows drive on CentOS server
sudo mount -t cifs //machinename/shareName -o username=<username>,password=<password> /mnt/sharedDrive
View a list of mounted drives
cat /proc/mounts
Un-mount an existing mounted drive
umount /mnt/sharedDrive
To permanently remove the share
rm -rf /mnt/sharedDrive
To mount a DFS share, add following in /etc/request-key.conf file
create cifs.spnego * * /usr/sbin/cifs.upcall -c %k create dns_resolver * * /usr/sbin/cifs.upcall %k
DFS share mount may not work using cifs-utils since its valid for CentOS-6 (or later) only
View the available shares on a non-DFS machine like so-
smbclient -L '//machinename' -U ieams/nraj
Incase of non-DFS share mounting, one can use IP if machine name mounting doesnt work.
Reference: http://www.cyberciti.biz/faq/mounting-windows-partition-onto-ubuntu-linux/ http://mikemstech.blogspot.in/2012/10/how-to-mount-dfs-share-in-linux.html
http://wiki.centos.org/TipsAndTricks/WindowsShares
http://www.thatsquality.com/articles/mounting-windows-smb-file-shares-using-cifs
0 notes
nraj · 11 years ago
Text
Custom format for excel dates
select cell
right click and select format
choose Cutsom
In the type textbox, give the custom format that you want from the abbreviations found in the reference site.
Ref: http://office.microsoft.com/en-in/excel-help/format-a-date-the-way-you-want-HA102809474.aspx
0 notes
nraj · 11 years ago
Text
Common *nix commands
Archive
To view contents of a zip file without unzipping -
unzip -l status-api.zip | less
Such and other Utility commands with gz files -
http://www.cyberciti.biz/tips/decompress-and-expand-text-files.html
0 notes
nraj · 12 years ago
Text
- tmux
- Rename window
ctrl a + ,
- Check out all bindings
ctrl a + ?
- Split current window into vertical panes
ctrl a + %
- Split current window into horizontal panes
ctrl a + "
- Switch to next pane
ctrl a + o
- toggle between horizontal and vertical layouts
ctrl a + <spacebar>
- Maximize the current pane
ctrl a + z
- restore the current pane to its original size
ctrl a + z
Ref: https://gist.github.com/MohamedAlaa/2961058
http://blog.hawkhost.com/2010/06/28/tmux-the-terminal-multiplexer/
0 notes
nraj · 12 years ago
Text
/home/localadmin/.forever/*.log {
  monthly       # how often to rotate
  rotate 12     # max num of log files to keep
  missingok     # don't panic if the log file doesn't exist
  notifempty    # ignore empty files
  compress      # compress rotated log file with gzip
  sharedscripts # no idea what it does, but it's in all examples
  copytruncate  # needed for forever to work properly
  dateext       # adds date to filename
  create 775 apache apache
  dateformat %Y-%m-%d.
}
0 notes
nraj · 12 years ago
Text
Mysql server fails to start [error : 28]
 sudo service mysqld start
Timeout error occurred trying to start MySQL Daemon.
Starting MySQL:                                            [FAILED]
Logs /var/log/mysqld :
mysqld  Error: unable to create temporary file; errno: 28
Can't start server : Bind on unix socket: No space left on device
1. Check /tmp for permissions and space availability
2. df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvd               37G   35G  0M    100% /
...
tmpfs                 2.0G     0  2.0G   0% /dev/shm
Now, /tmp is under / which has 0 M available and is 100% used.
3. ls -lrt /tmp . Its lined up with loads of RackMultipart files
Reason: Paperclip Issue 
Check the no. of such files 
> ls -lrt /tmp/RackMultipart* | wc -l
> 297
4. Remove these files 
rm -f /tmp/RackMultipart*
5. Try again
sudo service mysqld start
Starting MySQL:                                            [  OK  ]
sudo service mysqld status
mysqld (pid 17048) is running...
Ref: http://man.chinaunix.net/database/manual_MySQL/manual_Problems.html
0 notes
nraj · 12 years ago
Text
Linux Drives / Partitions /Volumes
Straight from this SO Issue
A drive is a physical block disk. For example: /dev/sda.
A partition A drive can be divided into some logic block disk. These logic block disk are named partition. For example: /dev/sda1, /dev/sda2.
A volume is also a logic block disk. Volume is a concept involved with partition. A volume can contain many partition. You can take a look at LVM project to understand the concept of a volume.http://sourceware.org/lvm2/.
For example: vg0/lvol0
0 notes
nraj · 12 years ago
Text
Tmux installation on CentOS
Install libevent which is a pre-req for tmux installation
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
sudo tar xzvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
sudo ./configure && make
 sudo make install
    2. Now install tmux by downloading from http://tmux.sourceforge.net/
sudo tar xzvf tmux-1.8.tar.gz
cd tmux-1.8
sudo ./configure && make
sudo make install
     3. Confirm tmux installation like so -
whereis tmux
      4. If you get the following error after installation -
tmux: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
       Solution:
sudo vi ~/.bashrc
       Append 
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"/usr/local/lib"
source ~/.bashrc
Ref: http://superuser.com/questions/324613/installing-a-library-locally-in-home-directory-but-program-doesnt-recognize-it
0 notes
nraj · 12 years ago
Text
NODE JS package manager- npm install <options>
npm install <tarball file> npm install <tarball url> npm install <folder> npm install <pkg> npm install <pkg>@<tag> npm install <pkg>@<version> npm install <pkg>@<version range> Ref: http://npmjs.org/doc/install.html
0 notes
nraj · 12 years ago
Text
How to check if a CentOS port is open
nmap -sT -O localhost
 cat /etc/services | grep smtp
netstat -anp | grep 25
lsof -i | grep 25
telnet myserver.com 25
netstat -tuplen
  Ref: http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s1-server-ports.html
0 notes
nraj · 12 years ago
Text
Unicode UTF-8 Issue with YII and MSSQL framework
Error : QLSTATE[HY000]: General error: 20018 Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier.
Diagnosis:
The requisite encoding UTF-8 is not getting set.
Application Stack:
MS SQL
YII framework
PHP
Red Hat
Fixes at all levels of application stack:
1. MSSQL - Checked at the database level, SQL data is getting stored and retrieved without any issues.
2. YII - ini_set('mssql.charset', 'UTF-8'); in index.php
3. PHP - in /etc/php.ini,
   default_charset = "UTF-8"    mssql.charset = "UTF-8"
4. Red Hat Server
In /etc/freetds.conf -
ensure in teh global settings if dedicated server else have a separate section with these setting for your application instance
[global]      host = servername      client charset = UTF-8      tds version = 8.0      text size = 20971520
References:
- http://www.yiiframework.com/wiki/16/how-to-set-up-unicode/
- Basics: http://blog.goosoftware.co.uk/2012/12/05/how-ascii-lost-and-unicode-won/
-  http://stackoverflow.com/questions/1322421/php-sql-server-how-to-set-charset-for-connection
- http://www.craig-edmonds.com/solved-php-mssql-unicode-encoding-issues/
0 notes
nraj · 12 years ago
Text
JavaScript - Numeric to String()
On Javascript console, try this -
12.toString();
SyntaxError: Unexpected token ILLEGAL
So to get string counterpart of a JavaScript number, use any of the the following options-
Number.prototype.toString.call(12); "12" OR 12..toString();
  OR
  (12).toString();
  Reference:
http://stackoverflow.com/questions/4046342/why-dont-number-literals-have-access-to-number-methods
http://stackoverflow.com/questions/6853865/usage-of-tostring-in-javascript
0 notes
nraj · 12 years ago
Text
SVN Branch merge
Create a branch
svn copy http://proj_base_svn_url/trunk http://proj_base_svn_url/branches/rel-1.3.3/
Checkout branch as a new instance to work upon -
svn checkout http://proj_base_svn_url/branches/rel-1.3.3/  proj_rel133
Work on the newly created branch and keep checking the changes back to the parent SVN branch
Keep merging the branch code with trunk regularly to avoid numerous conflicts at the last moment.
svn merge ^/trunk
build and test
Once satisfied with the merge, commit the branch code back to SVN
svn commit -m "Comiting changes pertaining to branch merge with trunk"
Branch -Trunk merge
When the branch is ready to be merged back into trunk
cd proj_trunk
Get the trunk to latest state
svn update
Merge branch code into trunk
svn merge --reintegrate ^/branches/rel-1.3.3
In case there are conflicts, revert the merge like so -
svn revert -R .
If merge goes well, commit back the merge code into SVN
svn commit -m "branch 1.3.3. merged with trunk"
0 notes
nraj · 12 years ago
Text
Regex escape of special characters in JavaScript/NodeJs
Escape your regex containing \ ^ $ * + ? . ( ) | { } [ ] like so:
function escapeRegExp(str) {
  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")
}
OR
RegExp.escape = function(text) {
  return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
};
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")ex documentation on Mozillaerflow solution 1
Stackoverflow solution 2
0 notes
nraj · 12 years ago
Text
Rails - JSON encoding performance analysis
Scrutinize problem piece of code - 
Rather than using Ruby array manipulation functions on activerecord objects fetched, try to use the sql filter, order, group etc. via AREL
at = User.arel_table   
at1 = Object2.includes(:class3).where(at[:attribute1].lower.matches("%#{search_text.downcase}%"))
     2. While querying, include all the nested objects for eager loading.       Dramatic difference it makes - 
users = User.includes(:addresses => [{:countries => :city}, :designations]).where('id in (?) AND active = 1', user_ids)
    3. Now optimize the json encoding process - 
 Use Yajl library. Install like so
# Gemfile
gem 'yajl-ruby', :require => "yajl"
Use Yajl library
Ensure the engine used :
> MultiJson.engine
  Installation might give an error about Notifier, update your ruby gems - 
gem update --system
  4. Other JSON builders could also be chosen -
Representative
Tokamak
Builder
JSONify
Argonaut
JSON Builder
RABL
References:
https://groups.google.com/forum/?fromgroups=#!topic/rails-oceania/kGHfiHU3GG4
http://stackoverflow.com/questions/10451722/what-is-the-fastest-way-to-render-json-in-rails
Use Yajl library for JSON processing -
# Gemfile gem 'yajl-ruby', :require => "yajl"
Options
https://github.com/mdub/representative
https://github.com/inem/tequila https://github.com/abril/tokamak https://github.com/jbr/argonaut
http://engineering.gomiso.com/2011/05/16/if-youre-using-to_json-youre-doing-it-wrong/
0 notes
nraj · 12 years ago
Text
Escape Mysql keywords in mysqli
How to escape and use historical tables/columns with reserved names in mysql command line -
mysql> select count(*) from keys;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'keys' at line 1
Use Backticks like so:
mysql> select count(*) from `keys`;
Ref: http://stackoverflow.com/questions/7380156/is-key-a-reserved-word-in-mysqli-im-getting-an-error
0 notes