Admun's Tech Journey

thoughts, ideas, projects, and discoveries on technologies

  • Main
  • Tag Cloud
  • Archives

30

Apr

A Simple PHP Optimization in for loop

Posted by Admun  Tags: php, tips, optimization
I was reading a blog post the other day (sorry, lost the URL...), it gives a pretty cool optimization in for loop;

In stead of:

for ($i < 0; $i < count($array_X); $i++) {
// do something....
}

One can do this and only one count() is executed:

for ($i < 0, $cnt = count($array_X); $i < $cnt; $i++) {
// do something....
}

I alright has a little concern when I put in that count(), or whatever expensive operation in the evaluation. But never think of this trick, even I know about I can initialize more than one value in a loop.
Leave a comment

29

Apr

DNS Caching and Local DNS Domain with dnsmasq

Posted by Admun  Tags: dns, linux, sysadmin
My home network always has local domain setup so I can ssh to admun2 instead of 192.168.0.x.

This is achieved by running a bind server w/ DNS forwarding, and a local domain served by bind. This works and provide a mean for me to learn about setting DNS domain in a small network.

But this time around when I move my server setup to CentOS 5, I read about dnsmasq. After some research, it seems this provides the function I setup w/ bind, but much easier to configure!

1) install (or ensure) dnsmasq: yum install dnsmasq
2) start the server: /etc/init.d/dnsmasq start
3) setup server to start on boot-up: chkconfig --level 345 dnsmasq on
4) ensure DNS port (TCP port 53) is unblocked in the firewall
5) setup /etc/hosts with local domain IP/hostname i.e. 192.168.0.99 admun2
6) set dnsmasq server IP as primary DNS in DSL router's DHCP setting
Leave a comment

15

Apr

bash arithmetic

Posted by Admun  Tags: tips, unix, shell
I never really done much of math in shell script in the past, but a script that collect logs recently require some simple add up.

#!/bin/sh
x=1;
y=2;
echo $((x+y));
Leave a comment

About Me

admun My passion has always been on software development, and I know it since I wrote my first program on an Apple II. I worked on cellular wireless system in the past (C/C++) and now focus on web application (LAMP, PHP, MySQL, CakePHP, Symfony, jQuery, Google AppEngine/python).

Tags

abit android apache app engine audio bandwidth benchmark bing blogroll bluetooth boinc bookmark botnet bt cakephp cdma cellphone chinese chrome clouds coding crash crawler date dns drm dsl fedora friendster g1 gaim gdesklets gmail google grid h323 hardware html ie6 instant messaging internet javascript jquery language lifestreaming linux liunx meetup ming motorola msi mysql nas nat networking nokia ntp nucleus opinion optimization os p2p palm parrot php power reblog redhat regex rss sdk se search security shell skype social network spam stats string svn syntax sysadmin t-mobile teksavvy telecom thinkpad time tips tuning tv twitter unix voip web web app web2.0 webos wordpress

Archives

  • Full archive
  • May, 2013
  • Feb, 2013
  • May, 2012
  • Aug, 2011

Search

Powered by LMNucleus CMS v3.66 | Copyright Edmond Hui
This page takes 0.052 sec/29 queries to process | NP_BadBehavior blocked 334 spams for the past 7 days
Theme Design by short funny jokes | Ported to Nucleus CMS by BABOCHTA
[Valid XHTML 1.0 Strict]