Shantanu Oak
Nov. 22nd, 2009
01:56 pm - Gearmand magic
Download the gearmand C library from...
http://launchpad.net/gearmand/trunk/0.1
To build, you can follow the normal:
./configure
make
make install
You can also run 'make test' before installing to make sure everything checks out ok. Once you have it installed, you can start the Gearman job server with:
gearmand -v
This will start it while printing some verbose messages. To try running a job through it, look in the examples/ directory of this source and run:
./reverse_worker
Once that is running, you can run your first job with:
./reverse_client "Hello, Gearman!"
If all goes well, the reverse_worker application should have output:
Job=H:lap:1 Workload=Hello, Gearman! Result=!namraeG ,olleH
While the reverse_client returned:
Result=!namraeG ,olleH
_____
MySQL user Defined functions that uses the gearmand C library as discussed above...
http://launchpad.net/gearman-mysql-u
To build:
./configure --with-mysql=
For example:
./configure --with-mysql=/usr/local/mysql/bin/mysql_
make
make install
Please keep in mind that for your UDF to be loaded, it must be in the library path for your server. On most UNIX-like systems you can set this by exporting the correct path in LD_LIBRARY_PATH for your mysql server.
Once the UDFs have been compiled and installed, you load them into MySQL using the following queries:
CREATE FUNCTION gman_do RETURNS STRING
SONAME "libgearman_mysql_udf.so";
CREATE FUNCTION gman_do_high RETURNS STRING
SONAME "libgearman_mysql_udf.so";
CREATE FUNCTION gman_do_low RETURNS STRING
SONAME "libgearman_mysql_udf.so";
CREATE FUNCTION gman_do_background RETURNS STRING
SONAME "libgearman_mysql_udf.so";
CREATE FUNCTION gman_do_high_background RETURNS STRING
SONAME "libgearman_mysql_udf.so";
CREATE FUNCTION gman_do_low_background RETURNS STRING
SONAME "libgearman_mysql_udf.so";
CREATE AGGREGATE FUNCTION gman_sum RETURNS INTEGER
SONAME "libgearman_mysql_udf.so";
CREATE FUNCTION gman_servers_set RETURNS STRING
SONAME "libgearman_mysql_udf.so";
Once loaded, you'll need to add servers for the clients to query first. This can be done with:
SELECT gman_servers_set("127.0.0.1");
_____
select gman_do('reverse','abcd') as test;
+------+
| test |
+------+
| dcba |
+------+
SELECT gman_do('shell',
concat(' ls -lh ',
(select variable_value from information_schema.global_variables
where variable_name = "datadir" )))\G
total 40976
-rw-rw---- 1 gmax staff 5.0M Nov 11 13:34 ib_logfile0
-rw-rw---- 1 gmax staff 5.0M Nov 11 13:34 ib_logfile1
-rw-rw---- 1 gmax staff 10M Nov 11 13:34 ibdata1
-rw-rw---- 1 gmax staff 1.2K Nov 11 13:34 msandbox.err
drwx------ 2 gmax staff 2.4K Nov 11 13:34 mysql
-rw-rw---- 1 gmax staff 6B Nov 11 13:34 mysql_sandbox5140.pid
drwx------ 2 gmax staff 68B Nov 11 13:34 test
select gman_do('eval','2 * 3') ;
+-------------------------+
| gman_do('eval','2 * 3') |
+-------------------------+
| 6 |
+-------------------------+
select gman_do('eval',
concat('$_="',host,'";tr/a-z/b-za/; $_'))
as test from mysql.user;
+-------------+
| test |
+-------------+
| % |
| myserver |
+-------------+
Oct. 18th, 2009
06:16 am - Customizing gedit as a Web Developer’s IDE
There are very simple changes those you can make to your favorite text editor "gedit" to make it a ppwerful developer tool.
Personally, I like to have the following preferences set from Edit menu:
* View >
Uncheck "Enable text wrapping"
Check "Display line numbers"
Check "Highlight current line"
Check "Display right margin" and set to 80. (I manually wrap my code at 80 characters)
Highlight matching bracket (when cursor is at a bracket, it's pair is highlighted as shown in the image above).
* Editor >
Check "Use spaces instead of tabs" and set "Tab width" to 4. (We can use modelines to change this from file to file)
Check "Enable auto indentation"
Uncheck "Create a backup copy of file before saving". (I manually backup everything before I start work)
* Font and Colors > Uncheck "Use default theme font" and set "Editor Font" to "Monospace 10".
* Plugins tab > check the box next to 'File Browser Pane' and tag list.
http://www.micahcarrick.com/09-29-2
Aug. 21st, 2009
05:09 pm - rewriting a sub query to use joins
SELECT u.uid,
u.username,
u.nid,
wd.pay
FROM (users_data AS u
LEFT JOIN winners_data wd
ON u.nid = wd.nid
AND u.uid = wd.uid)
LEFT JOIN dp_node dn
ON u.nid = dn.nid
WHERE u.uid = ".$val."
AND ((dn.TYPE = 'event'
AND (SELECT Count(nid)
FROM tournament_event
WHERE nid = u.nid
AND type_value IN ('A','B','C')) > 0)
OR (dn.TYPE = 'new_event'
AND (SELECT Count(nid)
FROM user_tournament_event
WHERE nid = u.nid
AND type_0_value IN ('Y','X')) > 0))
ORDER BY nid ASC
Aug. 2nd, 2009
04:20 pm - Victims of Internet virus
The hidden IFRAME from the ‘good’ site causes the user’s browser to silently pull content from the ‘bad’ site. As it does so, the ‘bad’ site is able to determine what operating system, Web browser and vulnerable plug-ins are running on the user’s computer.
It then sends specially crafted multimedia data that contains an attack to the victim's computer. Once this content has been played by the multimedia player, the attacker has gained control of the computer. Leveraging the vulnerability present in the user’s multimedia player, one or more malware files are installed on the user’s computer.
The malicious code now steals personal information (e.g., online banking information, email, gaming passwords) and sends it back to the attacker. The entire attack is usually invisible to the victim and leaves no apparent clues to indicate that the computer has been compromised.
http://economictimes.indiatimes.com/qui
Jul. 24th, 2009
02:30 pm - Open Office Template
Honestly OpenOffice.org doesn’t come with any templates or clip art worth mentioning, but the community provides free templates that are easy to install. My favorite presentation templates are those designed by Chih-Hao Tsai:
http://technology.chtsai.org/impres
The OpenOffice.org Repositories for Extensions and for Templates are new services organizing many useful templates.
http://templates.services.openoffice.or
It may not be intuitive to look for templates under the Extensions Repository, but many templates packs are distributed as extensions. In particular, try the Professional Template Pack I and II.
http://extensions.services.openoffice.o
http://extensions.services.openoffice.o
Once you install the template packs, start OpenOffice.org and click File – New – Templates to browse the templates. If you are printing address, mailing, shipping, CD and other types of labels, browse WorldLabel.com Label Templates.
http://www.worldlabel.com/Pages/autofil
02:24 pm - User Friendly Ms-Office
One of the most important change took place in the latest M$ office is that it has dumped the drop down menu system. The "ribbon" as they call it, is not bad. But see what I got when I hit Alt + H
If this is called "User Friendly" then what should be called "ugly"? This is not the right way to maintain backward compatibility!
Jul. 7th, 2009
08:26 pm - Google's Context-Sensitive Spell Checker
Wikipedia includes as an example: "Their coming too sea if its reel", a phrase that has 5 spelling mistakes, even though all the words can be found in the dictionary. If you enter this text in Gmail's editor and click on "Check spelling", Gmail won't find any error. Type the same text in Google's search box, and you'll get a "did you mean" message that suggests to search for "Their coming to see if its real". As you can see, Google's search box has a better spell checker than Gmail since it doesn't rely on a dictionary, it uses a huge amount of searches to determine what are the most probable sequences of words that follow a certain pattern. Unfortunately, the spell checker available at Google.com is optimized for searches, which are usually short, so you can't use it to spell check an email message or a blog post.
http://googlesystem.blogspot.com/2009/0
Jun. 13th, 2009
05:07 pm - SQLite Triggers
Assuming that customer records are stored in the "customers" table, and that order records are stored in the "orders" table, the following trigger ensures that all associated orders are redirected when a customer changes his or her address:
CREATE TRIGGER update_customer_address UPDATE OF address ON customers
BEGIN
UPDATE orders SET address = new.address WHERE customer_name = old.name;
END;
With this trigger installed, executing the statement:
UPDATE customers SET address = '1 Main St.' WHERE name = 'Jack Jones';
causes the following to be automatically executed:
UPDATE orders SET address = '1 Main St.' WHERE customer_name = 'Jack Jones';
04:54 pm - SQLite Example file
Here is an example how does SQLite handle datetime function:
create table events (id INTEGER PRIMARY KEY AUTOINCREMENT, name, kind, start, end);
insert into events values (null, 'tom', 'hour', datetime('now', '+1 day','start of day', '+11 hours'), datetime('now', '+1 day','start of day', '+12 hours'));
insert into events values (null, 'tom', 'hour', datetime('now', '+1 day','start of day', '+9 hours'), datetime('now', '+1 day','start of day', '+10 hours'));
insert into events values (null, 'joe', 'hour', datetime('now', '+1 day','start of day', '+9 hours'), datetime('now', '+1 day','start of day', '+10 hours'));
insert into events values (null, 'tom', 'day', datetime('now', '+1 day','start of day'), datetime('now', '+1 day','start of day', '+1 day'));
select *, (strftime('%s', end) - strftime('%s', start)) as length from events;
select *, min((strftime('%s', end) - strftime('%s', start))) as length from events where datetime('now', '+1 day','start of day', '+9 hours','+30 minutes') and end > datetime('now', '+1 day','start of day', '+9 hours','+30 minutes') group by name;
Jun. 4th, 2009
11:14 am - Some Important Bookmarks:
Need to check the following links before investing :)
Alerts:
https://secure.icicidirect.com/cust
Demat Balance:
https://secure.icicidirect.com/trad
SectorWise:
https://secure.icicidirect.com/Trad
NetWorth:
https://secure.icicidirect.com/Trad
Research:
http://content.icicidirect.com/rese
Margin Positions:
https://secure.icicidirect.com/trad
May. 6th, 2009
07:19 pm - Star trains Between Mumbai and Pune
Mumbai to Pune
Hyderabad Express 7031 12:45PM 4:30PM (Dadar, Kalyan, Karjat, Lonavala, Pune Junction) Rs. 415, 300, 121
Chennai Special 0163 12:45PM 3:25PM NON STOP Rs. 415, 300, 121 Only on Tuesday
Konark Express 1019 3:10PM 7:00PM (Dadar, Kalyan, Karjat, Lonavala, Pune Junction) Rs. 415, 300, 121
Kanyakumari Express 6381 3:45PM 7:15PM (Dadar, Kalyan, Karjat, Lonavala, Pune Junction) Rs. 415, 300, 121
Pragati Express 2125 4:25PM 7:53PM (Dadar, Karjat, Lonavala, ShivajiNagar) Rs. 250, 71
Deccan Queen Express 2123 5:10 PM 8:25PM (Karjat, Lonavala, ShivajiNagar) Rs. 250, 71
Pune to Mumbai
* Deccan Queen Express 2124 7:15AM 10:30AM (Lonavala, Dadar) Rs. 250, 71
* Pragati Express 2126 7:50AM 11:10AM (Lonavala, Dadar) Rs. 250, 71
Chennai Dadar Superfast Express 0164 8:10PM 10:55PM NON STOP Rs. 415, 300, 121 Only Thursday
Mumbai express 7032 9:10AM 1:05PM (Lonavala, Karjat, Kalyan, Dadar) Rs. 250, 71
Mumbai Express 1042 9:35AM 1:45PM (Khadi, Lonavala, Kalyan, Thane, Dadar) Rs. 415, 300, 121
Hyderabad Dadar Special 0732 11:35AM 3:30PM (Lonavala, Kalyan) Rs. 415, 300, 121 Only Sunday and Monday
Udyan Express 6530 3:50PM 7:50PM (Lonvala, Kalyan, Dadar) Rs. 415, 300, 121
Nagarcoil Mumbai Express 6352 4:40PM 8:50PM (Lonavala, Kalyan, Thane, Dadar) Rs. 415, 300, 121 Monday and Friday
Mumbai Express 6340 4:40PM 8:50PM (Lonavala, Kalyan, Thane, Dadar) Rs. 415, 300, 121 Tuesday, Web, Thu, Sat
Mumbai Express 6332 4:40PM 8:50PM (Lonavala, Kalyan, Thane, Dadar) Rs. 415, 300, 121 sunday
* Intercity Express 2128 5:55PM 9:00PM (Lonavala, Thane, Dadar) Rs. 250, 71
* Indrayani Express 1022 6:35PM 9:55PM (Lonavala, Karjat, Kalyan, Thane, Dadar) Rs. 250, 71
Apr. 22nd, 2009
02:48 pm - decrease the shutdown time
One way to decrease the shutdown time is to pre-flush the dirty pages, like this:
mysql> set global innodb_max_dirty_pages_pct = 0;
Now run the following command:
$ mysqladmin ext -i10 | grep dirty
| Innodb_buffer_pool_pages_dirty | 1823484 |
| Innodb_buffer_pool_pages_dirty | 1821293 |
| Innodb_buffer_pool_pages_dirty | 1818938 |
And wait until it approaches zero. (If the server is being actively used, it won't get to zero.)
Once it's pretty low, you can perform the shutdown and there'll be a lot less unfinished work to do, so the server should shut down more quickly.
Apr. 13th, 2009
12:54 pm - PEAR Power
Basic commands:
pear search services
(search for packages those have services keyword in it)
pear list
(installed packages)
pear upgrade-all
(upgrade installed packages)
pear install --alldeps Service_Weather
_____
Useful Packages
Mail
(send mail with attachments)
upload/ download file after tar or zip
(file management made easy)
pager
(Paging result rows)
DB
(Database connection)
HTML_safe
(Find unclosed tags)
HTML_QuickForm
(Build forms dynamically)
HTML_Menu
(Build menus dynamically)
Numbers_words
(numbers to word like One hundred fifty)
Date
(all about comparing dates, finding diff)
PhpDocumentor
(code documentation on the fly)
Log
(Logging messages from code)
Config
(have a single file for all configurations)
Auth
(Login / password management)
Apr. 8th, 2009
09:52 am - Tips time
Here are the things I have recently learned...
_____
Success code start with 2xx
OK 200
Accepted 202
No Response 204
Created 201
partial 203
Error code start with 4xx and 5xx
Bad Request 400
Unauthorized 401
Payment Requested 402
Forbidden 403
Not Found 404
Internal Error 500
Not Implemented 501
Service temporarily overloaded 502
Gateway Timeout 503
Moved 301
Found 302
Modified 303
Not Modified 304
_____
When you are using Ext3 filesystem you are limiting yourself to 16GB single file size. And you can have 32000 directories/ files. The number is double in case of Ext4 filesystem.
_____
The fullform of ISCSI is Internet Small Computer Storage Interface
_____
There is a live cd called Damn Vulnerable Linux that is very unstable and open for intrusions.
There is also xp.iso that acts like Windows live cd.
_____
nikto, ettercap, nessus, wireshark and nmap are the two utilities for network security.
Some useful commands:
nmap -sS -o 10.10.10.0/24
/etc/init.d/nessusd start
equery files nessus
_____
In order to transfer a file to windows start listening on windows box
nc -lvp 4444 -e cmd.exe
and connect from Linux box
nc -v 192.168.240.128 4444
Mar. 5th, 2009
11:05 am - extracting rar files in linux
# wget http://www.rarlab.com/rar/rarlinux-3.6.0.t
--12:01:13-- http://www.rarlab.com/rar/rarlinux-3.6.0.t
Resolving www.rarlab.com... 217.70.129.242
Connecting to www.rarlab.com|217.70.129.242|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 752997 (735K) [application/x-gzip]
Saving to: `rarlinux-3.6.0.tar.gz'
100%[=======>] 752,997 27.3K/s in 29s
12:01:45 (25.6 KB/s) - `rarlinux-3.6.0.tar.gz' saved [752997/752997]
# tar -zxvf rarlinux-3.6.0.tar.gz
rar/
rar/file_id.diz
rar/license.txt
rar/Makefile
rar/order.htm
rar/rarfiles.lst
rar/rar.txt
rar/readme.txt
rar/technote.txt
rar/whatsnew.txt
rar/rar
rar/rar_static
rar/unrar
rar/default.sfx
# cd rar
# cp rar unrar /bin
Nov. 20th, 2008
02:38 pm - Remove junk in Linux
Sometimes you'll end up with carriage returns on each line in a file originally created on a DOS/Windows system, or filenames with spaces, tab, or other control characters in them, but you can't see them typically.
The cat command provides three useful options -v, -e, and -t that will let you understand these invisible characters
-v (displays non-printing characters)
-e (prints a "$" at the end of each line to indicate a NL character)
-t (prints "^I" for each Tab in the file)
cat -vet filename |more
Oct. 12th, 2008
06:01 pm - Analyse mysql config using MySQLTuner
[root@localhost Desktop]# cd /root/
[root@localhost ~]# wget mysqltuner.pl/mysqltuner.pl
--17:58:59-- http://mysqltuner.pl/mysqltuner.pl
Resolving mysqltuner.pl... 209.20.89.226
Connecting to mysqltuner.pl|209.20.89.226|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 38063 (37K) [text/plain]
Saving to: `mysqltuner.pl'
100%[===================================
17:59:01 (36.2 KB/s) - `mysqltuner.pl' saved [38063/38063]
[root@localhost ~]# ./mysqltuner.pl
bash: ./mysqltuner.pl: Permission denied
[root@localhost ~]# chmod +x mysqltuner.pl
[root@localhost ~]# ./mysqltuner.pl
>> MySQLTuner 0.9.9 - Major Hayden <major@mhtx.net>
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
[!!] Successfully authenticated with no password - SECURITY RISK!
-------- General Statistics ----------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.0.44sp1-enterprise-gpl-log
[OK] Operating on 32-bit architecture with less than 2GB RAM
-------- Storage Engine Statistics ----------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 250M (Tables: 35)
[--] Data in InnoDB tables: 145M (Tables: 29)
[--] Data in ARCHIVE tables: 95M (Tables: 3)
[!!] Total fragmented tables: 2
-------- Performance Metrics ----------------------------------------
[--] Up for: 14h 27m 20s (569 q [0.011 qps], 18 conn, TX: 63K, RX: 9K)
[--] Reads / Writes: 100% / 0%
[--] Total buffers: 1.0G global + 23.1M per thread (400 max threads)
[!!] Allocating > 2GB RAM on 32-bit systems can cause system instability
[!!] Maximum possible memory usage: 10.1G (1179% of installed RAM)
[OK] Slow queries: 0% (0/569)
[OK] Highest usage of available connections: 0% (1/400)
[OK] Key buffer size / total MyISAM indexes: 1.0G/130.9M
[!!] Key buffer hit rate: 66.7% (6 cached / 2 reads)
[!!] Query cache is disabled
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 1 sorts)
[OK] Temporary tables created on disk: 17% (15 on disk / 88 total)
[OK] Thread cache hit rate: 94% (1 created / 18 connections)
[OK] Table cache hit rate: 92% (86 open / 93 opened)
[OK] Open file limit used: 5% (112/2K)
[OK] Table locks acquired immediately: 100% (25 immediate / 25 locks)
[!!] Connections aborted: 16%
[!!] InnoDB data size / buffer pool: 145.4M/8.0M
-------- Recommendations ----------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours - recommendations may be inaccurate
Your applications are not closing MySQL connections properly
Variables to adjust:
*** MySQL's maximum memory usage exceeds your installed memory ***
*** Add more RAM before increasing any MySQL buffer variables ***
query_cache_size (>= 8M)
innodb_buffer_pool_size (>= 145M)
Oct. 2nd, 2008
05:57 pm - Sorting in Linux
[root@localhost ~]# cat testme.txt
this is a test
food that are killing you
wings of fire
we hope that the labor spent in creating this software
this is a test
unix ips as well as enjoy our blog
[root@localhost ~]# awk '!x[$0]++' testme.txt
this is a test
food that are killing you
wings of fire
we hope that the labor spent in creating this software
unix ips as well as enjoy our blog
[root@localhost ~]# sort -u testme.txt
food that are killing you
this is a test
unix ips as well as enjoy our blog
we hope that the labor spent in creating this software
wings of fire
[root@localhost ~]# sort testme.txt | uniq -u
food that are killing you
unix ips as well as enjoy our blog
we hope that the labor spent in creating this software
wings of fire
Aug. 26th, 2008
09:48 am - Digital Content and ICT
Someone asked me this question:
What is your Vision of Digital content for Development and how do you think ICT (Information Communication Technology) tools can be used towards this end at large?
Ans:
Digital content is very crucial for any development, let it be economic, social, educational or personal. There are 2 points to note though, a) The digitization method should not be proprietary, it should be free, open source. b) It should be available to the public at an affordable rates. Let's see an example of this. If I want to know more about a medicine or a disease like malaria, what were my options in the good old days?
a) Go to Public / private library and become a member by paying fees and filling lengthy forms.
b) Take help of the Librarian to find the section/ book on the subject.
c) If the book is available (and not already taken by some other knowledge seeker), stand in a queue to register it in my name so that I can take it home.
d) Remember to return the book in 7 days, or else be prepared to pay hefty fine.
Fast Forward: today, I can read wikipedia entry on malaria on my mobile!
In the very old days, the only way to seek the knowledge was through human interaction. The one who "have" knowledge was called "Guru". Most of the gurus took utmost care not to digitize the knowledge in any form so that they can keep their supremacy and bad guys won't get hold of it.
As the technology is progressing, it can play an important role of eliminating the supremacy of "Gurus" and "Paper". In a truly ICT driven digitalized world one can live happily with minimum interaction with these two supreme powers. Paper / books will still be important for the people who are not part of digital revolution due to ignorance, poverty or stigma.
May. 14th, 2008
11:20 am - Usability 3.0
This is about Nirav Mehta's post on usability found here...
http://www.mehtanirav.com/2008/04/17/im
and the comment by Naveen, found here...
http://www.creanology.org/2008/04/usabi
I do not agree with either of these great men, Nirav and Naveen.
1) I will like to remove the "No, I'm a new user" link. When I want to login, I simply want to type in my username and password and hit enter! When I want to register, I look for big "Register" or "Sign Up" button with mouseover effect. As you can see, 'Sign Up' and 'Sign In' links are there at the top! Therefore it would be best to remove the 'sign up' option from 'Sign in' page.
2) I do not like the idea of using E-mail address as login. I want to use 'username' as login credential and NOT an e-mail that may change.
3) I will like the username, password input boxes integrated somewhere on the home page, instead of having a separate page for it. If space is an issue, create a mouseover/ onclick drop down box for 'Sign In' link at the top right.
You have to understand how the new users come to site, interact and judge/trust site. The users like me register with several sites before settling down with one or two really useful sites those I will like to use often. So all I look for is a quick way to login or register. The best would have been integrating with facebook or drupal or open ID so that there is no need to login at all or atleast I can use the same username and password evreywhere!
Navigate: (Previous 20 Entries)
