Monday, October 12, 2020

Run php script as daemon process with Systemd (AWS EC2)

To run PHP script as a  daemon service under Linux using Systemd do as below. Best way to make a shell script daemon? With new systemd you can create a service. You must create a file or a symlink in /etc/systemd/system/, eg. myservice.service and place content like this one, myservice will be the name of the service:



Create a service unit file:

Let’s create a file called /etc/systemd/system/myservice.service

[Unit]
Description=My PHP service

[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/php -f /path/to/myservice.php

[Install]
WantedBy=multi-user.target

Now, you will be able to start, get status, restart and stop the services using the command

systemctl <start|status|restart|stop|enable> myservice

sudo systemctl enable myservice  
- enable for restart after boot

sudo systemctl is-enabled myservice  
- check if myservice is enabled for startup

sudo systemctl start myservice  
- start the service

sudo systemctl restart myservice  
- restart the service

sudo systemctl status myservice  
- check the status of the service.


What is systemd PID file?

Can I use this script without creating a PID file? Why do we need a PID file at all? In which case we should use PID file? 

PIDFile=: If the service type is marked as "forking", this directive is used to set the path of the file that should contain the process ID number of the main child that should be monitored. when Type=forking is in use, then the pid file must be created (with the correct pid) before the parent process exits.

Actually, the whole point of systemd is to daemonize processes and run them in background for you... By trying to do that yourself, you're just preventing systemd from doing it for you. Which is making your life much harder at the same time... Instead of using Type=forking, simply write your shell script to run in foreground and set up the service to use Type=simple. You don't need any pidfiles then.

systemd's Type=forking is really there only for legacy programs that only work that way and can't be easily fixed to work in foreground... It's hacky and inefficient. The whole point of systemd (and some of its alternatives, predecessors) is to do the forking and daemonizing itself and let services just worry about doing what they need to do! :-)


For Type, there are a few choices: forking, simple, etc.

When you start the service manually from the command line (without using the nohupprefix command or the & suffix to run it in the background, or in other words, just run the command you would put on the ExecStart= line of the .service file), what happens?

a) If the service starts and keeps running, and the prompt does not return until you press Control-C or stop the service in some other way: then Type = simple is the right choice.

b) If the prompt returns but the service keeps running in the background (i.e. the service daemonizes itself on its own), then Type = forking is the right choice.

Note: many service applications designed to be portable to many Unix-style systems may behave as b) by default, but can be made to work like a) by adding an option (usually described as "don't fork", "keep running in foreground", "don't daemonize" or similar). In that case, if the option has no other side effects, then adding the option and using the a)-type behavior would be preferable for systemd.

Forking systemd service example

[Unit]
Description=My PHP service

[Service]
Type=forking
Restart=always
RestartSec=1
User=root
PIDFile=/var/run/myservice.pid
ExecStart=/usr/bin/php -f /path/to/myservice.php

[Install]
WantedBy=multi-user.target



Thursday, August 24, 2017

OKTA API Call with PHP Curl

Friday, September 6, 2013

नेपाली नलेख्ने नेपालीहरु

संदेश दाजु काठमाडौंको पपुलर स्कूलमा नेपाली पढाउनु हुन्छ l एकपल्ट दाजुले फेसबुक स्टाटस लेखी पोस्ट बटन दाबेर आफ्नो पोस्ट देखिएला भन्दै न्युज फिड हेरिरा बेला माथीबाट लुत्रुक्क एन.एस.ए सर्भिलेन्स सम्बन्धि पोस्ट झरेछ l संदेश दाजुको कम्पारो तात्यो l आफ्ना साथीले हेरुन भनेर लेखेको पोस्ट फेसबूक मार्फत घुमी फिरी कहाँ कहाँ पुग्दो रहेछ अनी त्यसमा अनेक थरिका मेसिनरी प्रोसेसिंग भएर स्टाटस लेख्नेको बारेमा बकाइदा अमेरिकी सरकारी निकाएबाट जासूसी मोनिटरिङ भैरहेको हुदों रैछ l आफ्नो सूचना र गोपनियताको हक खै ? संदेश दाजुले मलाई कल गर्नुभो – "के हो  बाबु यस्तो ? "

संदेश दाजु पि.सी.एल. गरेका मान्छे l आफू अंग्रेजीमा अली कमजोर भएको स्विकार्ने मान्छे l अंग्रेजी फाट्ट फुट्ट लेख्ने अनी साधारण अंग्रेजी बुझ्नेका लागि भनेर लेखिएका समाचारहरु कनीकुथी अर्थ लाउन जान्ने l टुटे फुटेको अंग्रेजीमा पोस्ट लेख्दा अनी आफूले लेखेको अंग्रेजी मिठासको प्रसंसा गर्ने फेसबुकका लाइकेहरु देखेर दाजुलाई मजा लाग्दो हो l एक लाइकमा एक मजा हुन्छ अरे l

"अनलाईनमा लेख्ने सबै कुरा नेपालीमा लेख्नु संदेश दाजु - नेपाली भाषा बुझेर अर्थ लाउने जान्ने मेसिनहरु संसारमा अहिले सम्म बनेका छैनन्", मैले सारा नेपाली प्राबिधिक क्षेत्रको ज्ञाताले जसरि कन्फिडेन्स साथ भने l "ए हो त है !" संदेश दाजुले फोन राखे l उनि मेरा गफ चाडै बुज्छन्, खै कसरी हो ? कुनै बेला प्रविधि बिकाश नहुनुले थोरै भएनी डिजिटल सुचना सम्बन्धि आफ्नो गोपनीयताको हक संरक्षण गर्न सक्छ भन्ने अस्थाई निचोड थियो यो हाम्रो कफी गफको l

दाजुले त्यो दिन देखी आजसम्म आफ्नो फेसबुकमा अंग्रेजीमा पोस्ट लेखेको मैले देखेको छैन l संदेश दाजुलाई आफ्नो लेखाई माथिको सर्भिलेन्स मन नपर्नुको अनेक कारण होलान, तर म आफ्नो सुझाब त्यो हदसम्म लागू भएको देखेर दुई चार दिन निदाईन l छटपटी यो थिएन कि मैले गलत बोले - बरु यो थियोकी मैले आफूले अनलाईनमा त्यो रुपमा नेपाली भाषामा लेख्ने प्रतिबद्दता कहिलै गर्न सकेको थिएन l नेपाली नबुझ्ने साथीभाइसंग अंग्रेजीमा संचार्नु आफ्नो ठाउँमा छ तर जानी नजानी आफूले नेपाली भाषाको अपहेलना गरेको अनुभव भयो ! नेपाली अक्षरहरुमा लेख्नुलाई नेपाली लेख्नु मान्छु म, व्याकरणको सुद्द्ता हाम्रा मास्टरले राम्रो संग सिकाए जस्तो मान्दिन l

म नेपाली भाषा रुचाउने मान्छे l फाट्टफुट्ट आफ्नो भाषामा आफूले छानेका शब्दहरु कोरेर स्पस्ट संग आफ्नो मन मस्तिस्कमा लागेका कुरा बाढ्नुको मजा भोगेको मान्छे l पाँच छ बर्ष अघि नेपाली युनिकोड प्रचलनमा नहुदाँ इन्टरनेटमा बलियो नेपालीपन झल्काउनेगरी आफ्ना वेबसाइट तथा ब्लगको उपस्थिति दर्साउनु सम्भव थिएन l तर अहिले इन्टरनेटमा, कम्प्युटर सफ्टवेयरमा जता ततै नेपाली युनिकोडमा लेख्ने प्रविधिहरु बिकाश भएका छन् l नेपाली संस्था मदन पुरस्कार पुस्तकालय तथा गूगल, माइक्रोसफ्ट जस्ता कम्पनीले नेपाली भाषाको प्रबिधिकरणमा काम गरेका छन् l मदन पुरस्कार तथा गूगलले आ-आफ्नै नेपाली इनपुट मेथड निकालेको छ l माइक्रोसफ्टले बिंग नेपाली अनुबादक निकालेको छ, अनुबाद हास्यास्पद भएपनी प्रयास राम्रो मान्नु पर्छ l सबै आधुनिक इन्टरनेट ब्राउजर हरुले नेपाली भाषामा लेखेका कुरा बिना हिचकिच देखाउन सक्छन l यो बिकाश आफ्नै आँखा अघि हिजो, आज गर्दै हुँदा पनी मैले अनलाईनमा नेपालीमा लेख्ने स्पस्ट प्रेरणा भेटिन l तर आज दुई पल्ट यो बिसयमा सोचेर बस्ने हिम्मत जुटेको छ, प्रेरणा मिलेको छ l

हाम्रा बा-आमाले नेपाली भाषामा लेखेको स्पस्ट पढ्न, बुझ्न र बुझाउन सक्नु हुन्छ l तर म बारम्बार आफ्नो मोबाइल, ल्यापटप वा पि.सी. अघि बसेर फटर-फटर अंग्रेजी हेरेको र लेखेको वहाँहरुलाई जमेन l बुझ्न सिक्न चासो नदेखाउनु भएको हैन - बुबाले अंग्रेजी लेखेको लहै-लहै बुझ्नु हुन्छ तर हामीले चलाउने कुनै पनी इलेक्ट्रोनिक डिभाइस नेपालीले चलाउन भनेर बनाइएका छैनन् l नत हामीले चलाउने कुनै सफ्टवेयरको झलक नेपालीमा देखिन्छ l यो भाषाको कुरो हामी दुई चार जनालाई समस्या नहोला l कतिनै छौं र हामी जो इन्टरनेटमा अंग्रेजी बुज्छौ - नेपाली जनसंख्याको दश प्रतीशत ? पन्ध्र प्रतीशत ? आमा सिधा-सिधा भन्नु हुन्छ - यो गाई खाने भाषाले गर्नु गर्यो ! नौ-दश बर्ष अघि सम्म मैले बुझ्दिनथें त्यो के भनेको हो भनेर l आजकल स्पस्ट सुनिन्छ l

त्यसो हो भने हामीले गर्ने के त ? सबैलाई अंग्रेजी सिकाउने ? की सबै डिजिटल सुचना नेपालीकरण गर्ने ? ल जे गरम्ला तर त्यो कसले गर्दिने हो ?

समस्या हाम्रो हो l समाधानको जिम्मेबारी हामीले लिन सक्नुपर्छ l हामी सफ्टवेयर बनाउनेहरुलाई नेपालीको लागि सफ्टवेयर बनाउन आउदैन l हामी बिदेशीका निम्ति सफ्टवेयर बनाउदा र कोड लेख्दा यति पोख्त भईसकेउँ नेपालीको लागि सफ्टवेयर बनाउनु हाम्रो प्राथमिकतामा पर्दैन l हामी ग्लोबलाइजेसनका कुरा फ्याक्छौं कफी खाँदै, तर आफ्नो भाषा र संस्कार मेटिएको हामीलाई चासो लाग्दैन l हामी कस्ता भने - कुरो बिग्रेपछि ए हो त बिग्रेछ भन्न पोख्त l बेद पुराण लाई कक्षा एक देखी दश सम्मको पाठ्यक्रममा सम-सामयिक तरिकाले परिमार्जन गर्दै पढाएको भए पहिलो एरोप्लेन बनाउने नेपाली हुन्थ्यो होला l हामीले अहिले चचच गर्छौं, सबैले पुराण बिर्सेपछि, अनी पुजा पाठ गर्दा गुरु नभेटे पछी l ग्रन्थ हराउँदा मौलिकता यसरि हराउछ l भाषा बिर्सिदा संस्कार यसरीनै लोप हुनेछ l

करिब डेढ बर्ष अघि गूगलको आधिकारिक नेपाल भ्रमणमा गूगलले नेपाली भाषामा चासो राखेको र आन्तरिक रुपमा नेपाली भाषामा काम भईरहेको कुरा गूगलका कर्मचारीले नेपाली प्रविधि क्षत्रसंग बाँडेर गए l हाम्रो भाषामा मल्टीनेसनल कम्पनीले चासो राख्नु हाम्रो लागि गर्बको कुरो थियो l हामी आशे भएम - आश गरेर बसेम l

गूगलले नेपाली भाषालाई सजिलै अंग्रेजीमा र अंग्रेजी भाषालाई नेपालीमा अनुबाद गर्न सक्ने मेसिन ट्रान्सलेटर बनाउन खोजेको थियो l त्यो बन्यो भने नेपाली - अंग्रेजी भाषाको अनुबादलाई आधार बनाएर बिश्वका पैसट्ठी भाषामा लेखेका कुरालाई हामीले एक क्लिक को भरमा नेपालीमा पढ्न सक्छौ l नेपालीमा लेखेका लेखलाई हामीले ती बिश्वका भाषामा सहज रुपमा उल्था गर्न सक्छौ l गूगलले सकेन l कसरी सकोस जब नेपाली र अंग्रेजीमा एउटै अर्थ लाग्ने लेखहरु हामी संग छदै छैनन् l पल्पसा क्याफे जसरि सबै पुस्तक नेपाली र अंग्रेजीमा निस्कने भए ? भाषा अनुबाद गर्न सक्ने मेसिन बनेका छन्, बनेर के गर्नु ? चामल र भुस निकाल्न धान चाहियो नी ? हामी नेपाली प्रविधिमा लाग्नेले नत धान फलाएम न त प्रसस्त नेपाली शब्दहरु नै सिर्जना गर्न सकेम l जसले नेपालीमात्र बुज्छन् र लेख्न रुचाउँछन् उनीहरु प्रविधिको पहुँचमा पुग्दा धेरै ढिलो भइसक्नेछ l यो अवस्थामा गूगलले अनुबादक बनायो भने पनी माइक्रोसफ्ट बिंग को अनुबादक जस्तो जोकको बिषय बन्ने छ l गूगलमा काम गर्ने संसारका सर्वोत्कृष्ट इन्जिनियरहरुले  बनाएको नेपाली इनपुट मेथड प्रयोग गरेर लेखेको लेखहरुलाई उनीहरुलै बनाएको अर्को भाषा डिटेक्टर सफ्टवेयरले हिन्दी लेख भनेर ठोकुवा गर्छ त्यस्तै - अनुबाद पनी हिन्दी टोनमा निकाल्न के बेर ? हामीले हेलचेक्र्याइँ गरेकोले हाम्रो भाषा र हाम्रा कखराको आज मजाक बनेको छ l

हामी सफ्टवेयरको झलकलाई म्यानुअल तरिकाले नेपालीमा अनुबाद गर्न लागिपर्छौ l अनी यस्तो अनुबाद गर्छौं त्यो न त सिकारुले सिकेर प्रोफेसनल बन्न सक्ला न त हामी जो अली अली कम्प्युटर जानेका छौं हामीहरुले नै चलाउन सकौंला l भाषा प्रबिधिकरण गर्न हामीसँग शब्द अभाब छ l शब्द अभाब कसरी नहोस जब कम्प्युटरमा लेख्न जान्ने सबैले अंग्रेजीमा लेख्छन ?

माइक्रोसफ्टले आफ्नो पपुलर अपरेटिंग सिस्टम नेपाली भाषामा उल्था गर्ने प्रयत्न गर्यो l मेनु लाई पर्दा भनेर लेखेको सफ्टवेयर मैले चलाउन सकिन l इन्टर लाई घुसाउनुहोस् लेख्नेहरु एक पल्ट त पक्का हाँसे होलान l

नेपालमै लिनक्स ओपन सोर्स अपरेटिंग सिस्टमको नेपाली अनुबाद नेपालीनक्स बन्यो l त्यो किन बन्यो र अहिले कहाँ छ बनाउनेलाई चाहिँ थाहा होला l काठमाडौं बिश्वबिध्यालयमा दोभासे नाम गरेको नेपाली अंग्रेजी अनुबादक सफ्टवेयरमा गहन रिसर्च र अध्ययन भयो - त्यो पनी शब्द अभाबले अघि बढ्न सकिरहेको छैन l

नेपाली शब्द कहाँ छन् त ? यी यहिँ छन्, फेसबुक चलाउने बिसलाख नेपालीमाझ l तर ति नेपालीका सोचहरु अनी बिचारहरु नेपाली शब्दका रुपमा झरेनन l नेपालीको हातहरु कीबोर्डमा चल्दा अंग्रेजी अक्षर झर्छन् l अनी त्यहाँबाट सुरु हुन्छ सम्पूर्ण नेपाली भाषा सम्बन्धि प्राबिधिक कठिनाईहरु l

बिसलाख नेपालीले हरेक दिन बिसलाख ओटा वाक्य नेपाली भाषामा लेखे भने एक वर्षमा कति शब्द जम्मा होलान ? अनी कति नयाँ सजिला शब्द जन्मेलान l भाषा मेटिनु भन्दा आगन्तुक शब्दहरु थपिउन बरु l

जुकर्बरले नबुझ्ने भाषा उसको अफिसको फेसबुक वोर्ल्ड मनिटरिङ सफ्टवेयरमा बट्टा बट्टा त नदेखाउला नी? ल्यारी पेज ले विकासशील मुलुक हरुको त्रैमासिक प्रविधि ग्रोथको ट्रेन्ड हेर्दा हुन् l नेपाली अक्षरहरु उनको दृश्यमा पर्ने कहिले ? इभान विलियमले नेपाली बोल्ने मान्छे छन् र भन्दा हुन् l कसरी भनुन - हामी इन्टरनेट चलाउने नेपालीहरुले नेपाली भाषा बिर्सेपछी l

अनुवादको नाममा एउटा साधारण नेपालीले सपनामा नी नसोच्ने शब्द बनाएर भासिक रुपमा अप्ठ्यारा नेपाली अनुवादित सफ्टवेयर निकाल्नुको आफ्नै मत होला तर त्यो तरिकाले काम गरेन भन्ने कुरा हामीले भोगेको अवस्था हो l त्यो दोहोरिनु आफ्नै खुट्टामा बन्चरो हान्नु हो l समय पछिल्तिर चल्छ र ? नेपाल प्रविधिमा छिट्टै फड्को मार्दै छ - सुरुबाट सुरु गर्ने अवस्था अब रहेन l

नेपाली भाषाको प्राबिधिक बिकाशमा बिर्को लागेको छ l नेपाली इन्जिनियरिङ पढ्ने बिध्यार्थीले आफ्नो लागि प्रोजेक्ट भेट्दैनन, नेपालमा खोजे पो भेटिन्थ्यो, हेरे पो देखिन्थ्यो l नेपाली सफ्टवेयर कम्पनी र नेपाली सफ्टवेयर डेभलपर्सहरुले नेपाली भाषामा सफ्टवेयर बनाउने कहिले ? नेपाली भाषा सम्बन्धि प्रबिधिमा गर्न सक्ने काम धेर-थोर भइरहेको छ तर भएको देखिएन l

यो शब्द अभाब हामीले सिर्जना गरेको हो l यसको पूर्ति हामीले गर्नुपर्छ l भाषाको सम्बन्ध संस्कार र राष्ट्रिय एकता संग जोडिएको हुन्छ l बिगत पन्ध्र वर्ष कम्प्युटर साइन्स पढेर मैले नेपाली भाषामा लेख्न बिर्सें l म कुत्तुवा गरेर भन्न सक्छु म संगै पढाई सुरु गर्ने सत्तरी प्रतीशत नेपालीहरुले इन्टरनेटमा नेपाली भाषामा लेख्न रुचाउदैनन l जान्दैनन भन्न खोजेको हैन l

सुन्छु, बैज्ञानिक थेसिस अंग्रेजीमा लेख्नु पर्छ l कम्प्युटर चलाउन सिकाउने कुरा अंग्रेजीमा लेख्नु पर्छ l बिदेशीले लेखेको पढेर सिकेर त्यहि कुरो अंग्रेजीमै कपि पेस्ट गर्दा कहाँको मान्छेले गन्ला र ? कमसेकम आफूले पढेर बुझेको कुरो एक दुई हजार नेपाली शब्दमा लेख्दा - अंग्रेजी भाषा अप्ठेरो मान्ने नेपालीहरुलाई त काम लाग्ला !

फेसबूक को स्टाटस अंग्रेजीमा लेख्नु पर्छ अरे l ट्वीट अंग्रेजीमा नलेखे ट्वीटेको के मजा l यी ढोंग हुन् l आफ्नो भाषालाई जानी जानी रेट्ने यसरि हो l लेखाई भाषामा हुदैन l लेखमा हुन्छ l राम्रो लेख संसारमा हरेक भाषामा अनुवादित हुन्छ l म आफूलाई नेपाली भन्छु भने मैले आफूले कम्प्युटरको किबोर्ड थिचेर नेपाली युनिकोडमा अक्षर झर्दा गर्व गर्न सक्नु पर्छ l जसरि हामीलाई नेपाली भाषामा बोल्न हिचकिच छैन त्यसरी लेख्न पनी हिचकिच हुनु हुन्न l बोलेको कुरो हावामा उड्छ भन्छन - यसरि नेपाली भाषामा लेख्न छाड्ने हो भने - हाम्रो भाषिक अस्तित्व मेटिने छ l हामी नेपाली बोल्ने अंग्रेज हुनेछौं l

संदेश दाजुले जस्तो अटोठ गर्न नसके पनी मैले कोशिश गर्नेछु, अबका हरेक दिनहरु जब म लेख्न बस्छु कम्प्युटरमा मैले नेपाली अक्षरहरुमा लेख्ने छु l प्राबिधिक रुपमा र शत प्रतीशत भाषिक सुद्दतामा कन्ट्रीब्युसन गर्न नसके पनी - एउटा लेख्न रुचाउने नेपालीको हैसियतले मैले आफूले सके जति नेपाली शब्द इन्टरनेटमा छर्ने छु l एन. एस. ए. ले नेपाली नबुझुन्जेल - अर्को तिरको मन्द मन शान्ति छँदैछ l

माइसंसारमा मन परे हरियो मन नपरे रातो भनेको जस्तो यो लेख मन परे फेसबूक, ट्विटर, गूगल प्लस आदिमा सेयर गरिदिनु होला /
 
(यो पोस्टको ड्राफ्ट हेरिदिने साथी भुवन पोखरेलमा आभार)

Thursday, May 16, 2013

Met the social media personality #fotosoto

Starting this post i'm going to share some of the moments captured through my camera. Will be using the label #fotosoto so share similar posts. If you know the persons in picture, feel free to add an awesome comment which will delight both of us : )


The person in this photo is a internet spammer, yeah people use that term when there is no word coined to describe exceptional online social media presence and management skills, he is the man who ignited interest in me to learn about social media.  Glad to meet the one man virality machine who can drive your mid sized website down in a minute.

Tuesday, April 30, 2013

Social Network Status Updates – Database Schema

Here's a simple database schema which can be used in cases where you want to take user status input. The entities available are users, updates, comments & likes. Additional entities can be added as required. Also, for simple user registration and status updates it will be more than enough.  Schema derived by studying popular social networks like Facebook / Twitter / Google+ Status Updates mechanism. The schema uses MySql.

Schema Diagram:updatebox

MySQL Create Script:
-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 03, 2013 at 09:56 PM
-- Server version: 5.1.37
-- PHP Version: 5.3.0
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `updatebox`
--
-- --------------------------------------------------------
--
-- Table structure for table `comments`
--
CREATE TABLE IF NOT EXISTS `comments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `text` text CHARACTER SET utf8 NOT NULL,
  `created_at` int(11) NOT NULL,
  `update_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `comments`
--

-- --------------------------------------------------------
--
-- Table structure for table `likes`
--
CREATE TABLE IF NOT EXISTS `likes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `update_id` int(11) NOT NULL,
  `created_at` int(11) NOT NULL,
  `dislike_user_id` int(11) DEFAULT NULL,
  `like_user_id` int(11) DEFAULT NULL,
  `comment_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `likes`
--

-- --------------------------------------------------------
--
-- Table structure for table `updates`
--
CREATE TABLE IF NOT EXISTS `updates` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `text` text CHARACTER SET utf8 NOT NULL,
  `picture` varchar(255) DEFAULT NULL,
  `location` varchar(255) DEFAULT NULL,
  `created _at` int(11) NOT NULL,
  `video` varchar(255) DEFAULT NULL,
  `tags` varchar(255) DEFAULT NULL,
  `user_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `updates`
--

-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(255) NOT NULL,
  `mid_name` varchar(255) DEFAULT NULL,
  `last_name` varchar(255) NOT NULL,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `address` varchar(255) NOT NULL,
  `phone` varchar(255) NOT NULL,
  `dob` int(11) NOT NULL,
  `about` text NOT NULL,
  `user_type` int(11) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `users`
--

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Saturday, April 27, 2013

Online Shopping System–Database Design

Database design of Online Shopping System. Schema represents minimal information required to store information of a shop and products to sell. Cart information can be stored in session or if wishlist / watchlist is needed, the schema can be simply extended. Enjoy.

Entities:

users – shop admin, owner and customers
products – products to sell
categories - category of products. eg. laptops, phones etc
orders – customer placed a order
order_details – order always won't have a single item. store details here.
sales – order is sold.
contact – when customers / visitors contact shop owner
smartshop
MySQL Create Script / phpMyAdmin dump:
-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 03, 2013 at 07:51 AM
-- Server version: 5.1.37
-- PHP Version: 5.3.0
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `smartshop`
--
-- --------------------------------------------------------
--
-- Table structure for table `category`
--
CREATE TABLE IF NOT EXISTS `category` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `details` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
--
-- Dumping data for table `category`
--
INSERT INTO `category` (`id`, `name`, `details`) VALUES
(1, 'laptops', 'laptops lorem ipsum'),
(2, 'phones', 'phones details'),
(3, 'tablets', 'tablets details');
-- --------------------------------------------------------
--
-- Table structure for table `contact`
--
CREATE TABLE IF NOT EXISTS `contact` (
  `contact_id` int(11) NOT NULL AUTO_INCREMENT,
  `firstname` varchar(255) NOT NULL,
  `middlename` varchar(255) DEFAULT NULL,
  `lastname` varchar(255) NOT NULL,
  `emai` varchar(255) NOT NULL,
  `message` varchar(255) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`contact_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `contact`
--

-- --------------------------------------------------------
--
-- Table structure for table `orders`
--
CREATE TABLE IF NOT EXISTS `orders` (
  `order_id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `shiping_address` varchar(255) DEFAULT NULL,
  `shiping_date` int(11) DEFAULT NULL,
  `shipping_status` varchar(255) DEFAULT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`order_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `orders`
--

-- --------------------------------------------------------
--
-- Table structure for table `order_details`
--
CREATE TABLE IF NOT EXISTS `order_details` (
  `order_details_id` int(11) NOT NULL AUTO_INCREMENT,
  `order_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `quantity` int(11) NOT NULL,
  PRIMARY KEY (`order_details_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `order_details`
--

-- --------------------------------------------------------
--
-- Table structure for table `products`
--
CREATE TABLE IF NOT EXISTS `products` (
  `product_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `description` text NOT NULL,
  `image` varchar(255) NOT NULL,
  `category_id` int(11) NOT NULL,
  `quantity` varchar(255) NOT NULL,
  `brand` varchar(255) DEFAULT NULL,
  `model` varchar(255) DEFAULT NULL,
  `configuration` varchar(255) DEFAULT NULL,
  `price` varchar(255) NOT NULL,
  `featured` int(11) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`product_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `products`
--

-- --------------------------------------------------------
--
-- Table structure for table `sales`
--
CREATE TABLE IF NOT EXISTS `sales` (
  `sales_id` int(11) NOT NULL AUTO_INCREMENT,
  `order_id` int(11) NOT NULL,
  `sales_amount` int(11) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`sales_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `sales`
--

-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `firstname` varchar(255) NOT NULL,
  `middlename` varchar(255) DEFAULT NULL,
  `lastname` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `address` varchar(255) NOT NULL,
  `phone` varchar(255) NOT NULL,
  `type` varchar(255) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `users`
--

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Friday, April 26, 2013

Quiz System–Database Schema Design

MySQL Database Schema design for quiz system.

Schema Diagram:

quiz

MySQL Create Script:

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 01, 2013 at 08:27 PM
-- Server version: 5.1.37
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `quiz`
--

-- --------------------------------------------------------

--
-- Table structure for table `category`
--

CREATE TABLE IF NOT EXISTS `category` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8 NOT NULL,
  `slug` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `category`
--


-- --------------------------------------------------------

--
-- Table structure for table `level`
--

CREATE TABLE IF NOT EXISTS `level` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `slug` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `level`
--


-- --------------------------------------------------------

--
-- Table structure for table `questions`
--

CREATE TABLE IF NOT EXISTS `questions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `question` text CHARACTER SET utf8 NOT NULL,
  `option1` varchar(255) NOT NULL,
  `option2` varchar(255) NOT NULL,
  `option3` varchar(255) NOT NULL,
  `option4` varchar(255) NOT NULL,
  `answer` varchar(255) NOT NULL,
  `category_id` int(11) NOT NULL,
  `level_id` int(11) NOT NULL,
  `image` varchar(255) DEFAULT NULL,
  `status` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `questions`
--


-- --------------------------------------------------------

--
-- Table structure for table `score`
--

CREATE TABLE IF NOT EXISTS `score` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `question_id` int(11) NOT NULL,
  `category_id` int(11) NOT NULL,
  `level_id` int(11) NOT NULL,
  `user_answer` varchar(255) NOT NULL,
  `is_correct` int(11) NOT NULL,
  `points` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `score`
--


-- --------------------------------------------------------

--
-- Table structure for table `settings`
--

CREATE TABLE IF NOT EXISTS `settings` (
  `points_per_question` int(11) NOT NULL,
  `site_name` varchar(255) NOT NULL,
  `site_slogan` varchar(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `settings`
--


-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `created_at` int(11) NOT NULL,
  `image` varchar(255) DEFAULT NULL,
  `about` text CHARACTER SET utf8,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=73 ;

--
-- Dumping data for table `users`
--


/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Photo Video Gallery–Database Design

Database design for photo video gallery website / app. Enjoy.

Schema Diagram:

pvgallery
MySQL Create script:

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 03, 2013 at 10:25 PM
-- Server version: 5.1.37
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `pvgallery`
--

-- --------------------------------------------------------

--
-- Table structure for table `category`
--

CREATE TABLE IF NOT EXISTS `category` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `details` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `category`
--


-- --------------------------------------------------------

--
-- Table structure for table `comments`
--

CREATE TABLE IF NOT EXISTS `comments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `media_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `comment_text` text CHARACTER SET utf8 NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `comments`
--


-- --------------------------------------------------------

--
-- Table structure for table `media`
--

CREATE TABLE IF NOT EXISTS `media` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8 NOT NULL,
  `description` text CHARACTER SET utf8 NOT NULL,
  `file` varchar(255) NOT NULL,
  `size` int(11) NOT NULL,
  `likes` int(11) DEFAULT NULL,
  `views` int(11) DEFAULT NULL,
  `downloads` int(11) DEFAULT NULL,
  `category_id` int(11) DEFAULT NULL,
  `user_id` int(11) NOT NULL,
  `media_type_id` int(11) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `media`
--


-- --------------------------------------------------------

--
-- Table structure for table `media_type`
--

CREATE TABLE IF NOT EXISTS `media_type` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `slug` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `media_type`
--

INSERT INTO `media_type` (`id`, `name`, `slug`) VALUES
(1, 'Videos', 'videos'),
(2, 'Photos', 'photo'),
(3, 'Music', 'music');

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `type` int(11) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `users`
--


/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Wednesday, April 24, 2013

Marksheet Generation System–Database Design

Schema for Marksheet Generation System useful for school, colleges and institutes to store student's information, exam marks etc. Extend at your will.

Schema Diagram:

online_marksheet

MySQL Create Script phpMyAdminDump:

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 02, 2013 at 07:28 PM
-- Server version: 5.1.37
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `online_marksheet`
--

-- --------------------------------------------------------

--
-- Table structure for table `faculties`
--

CREATE TABLE IF NOT EXISTS `faculties` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `faculties`
--

INSERT INTO `faculties` (`id`, `name`) VALUES
(1, 'BSC-CSIT'),
(2, 'BBA'),
(3, 'BBS');

-- --------------------------------------------------------

--
-- Table structure for table `feedback`
--

CREATE TABLE IF NOT EXISTS `feedback` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `email` int(11) NOT NULL,
  `comment` text CHARACTER SET utf8 NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `feedback`
--


-- --------------------------------------------------------

--
-- Table structure for table `institutions`
--

CREATE TABLE IF NOT EXISTS `institutions` (
  `id` int(50) NOT NULL,
  `name` varchar(255) NOT NULL,
  `address` varchar(255) NOT NULL,
  `phone` varchar(255) NOT NULL,
  `fax` varchar(255) NOT NULL,
  `website` varchar(255) NOT NULL,
  `affiliated_to` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `institutions`
--


-- --------------------------------------------------------

--
-- Table structure for table `marks`
--

CREATE TABLE IF NOT EXISTS `marks` (
  `id` int(11) NOT NULL,
  `subject_id` int(11) NOT NULL,
  `student_id` int(11) NOT NULL,
  `mark_assessment` int(11) NOT NULL,
  `mark_semester` int(11) NOT NULL,
  `total_marks` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `marks`
--


-- --------------------------------------------------------

--
-- Table structure for table `results`
--

CREATE TABLE IF NOT EXISTS `results` (
  `id` int(11) NOT NULL,
  `student_id` int(11) NOT NULL,
  `total_marks` int(11) NOT NULL,
  `result` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `results`
--


-- --------------------------------------------------------

--
-- Table structure for table `students`
--

CREATE TABLE IF NOT EXISTS `students` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(255) NOT NULL,
  `mid_name` varchar(255) NOT NULL,
  `last_name` text NOT NULL,
  `symbol_no` varchar(255) NOT NULL,
  `date_of_birth` datetime NOT NULL,
  `regd_no` varchar(255) NOT NULL,
  `faculty_id` varchar(255) NOT NULL,
  `year` varchar(255) NOT NULL,
  `semester` varchar(255) DEFAULT NULL,
  `institutions_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `students`
--


-- --------------------------------------------------------

--
-- Table structure for table `subjects`
--

CREATE TABLE IF NOT EXISTS `subjects` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `course_no` varchar(255) NOT NULL,
  `course_hours` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL,
  `fm_assessment` int(11) NOT NULL,
  `fm_semester` int(11) NOT NULL,
  `fm_total` int(11) NOT NULL,
  `pm_assessment` int(11) NOT NULL,
  `pm_semester` int(11) NOT NULL,
  `pm_total` int(11) NOT NULL,
  `type` varchar(255) NOT NULL COMMENT 'theory or practical',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `subjects`
--


-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(222) NOT NULL,
  `email` varchar(222) NOT NULL,
  `password` varchar(222) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `users`
--


/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Friday, April 19, 2013

Simple CMS (Content Management System) – database design

Schema design of simple content management system. Schema and tables itself speak about the type of information indented to be stored by the system.

Schema Diagram:

cms-v1.0
MySQL Create Script phpMyAdmin dump:

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Mar 30, 2013 at 10:20 PM
-- Server version: 5.1.37
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `cms`
--

-- --------------------------------------------------------

--
-- Table structure for table `comments`
--

CREATE TABLE IF NOT EXISTS `comments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) DEFAULT NULL,
  `post_id` int(11) NOT NULL,
  `author` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `author_email` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `author_url` varchar(255) DEFAULT NULL,
  `content` text NOT NULL,
  `approved` int(11) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `comments`
--


-- --------------------------------------------------------

--
-- Table structure for table `gallery`
--

CREATE TABLE IF NOT EXISTS `gallery` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8 NOT NULL,
  `path` varchar(255) NOT NULL,
  `caption` varchar(255) CHARACTER SET utf8 NOT NULL,
  `status` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `gallery`
--


-- --------------------------------------------------------

--
-- Table structure for table `navigations`
--

CREATE TABLE IF NOT EXISTS `navigations` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `link_text` varchar(255) CHARACTER SET utf8 NOT NULL,
  `url` varchar(255) NOT NULL,
  `description` varchar(255) CHARACTER SET utf8 NOT NULL,
  `group_id` int(11) NOT NULL,
  `click_count` int(11) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `navigations`
--


-- --------------------------------------------------------

--
-- Table structure for table `navigation_groups`
--

CREATE TABLE IF NOT EXISTS `navigation_groups` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8 NOT NULL,
  `slug` varchar(255) CHARACTER SET utf8 NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `navigation_groups`
--


-- --------------------------------------------------------

--
-- Table structure for table `post`
--

CREATE TABLE IF NOT EXISTS `post` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `title` varchar(255) CHARACTER SET utf8 NOT NULL,
  `content` text CHARACTER SET utf8 NOT NULL,
  `category` int(11) DEFAULT NULL,
  `image` varchar(255) DEFAULT NULL,
  `created_at` int(11) NOT NULL,
  `status` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `post`
--


-- --------------------------------------------------------

--
-- Table structure for table `post_categories`
--

CREATE TABLE IF NOT EXISTS `post_categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8 NOT NULL,
  `slug` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `post_categories`
--


-- --------------------------------------------------------

--
-- Table structure for table `settings`
--

CREATE TABLE IF NOT EXISTS `settings` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `site_name` varchar(255) CHARACTER SET utf8 NOT NULL,
  `site_slogan` varchar(255) CHARACTER SET utf8 NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `settings`
--


-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `created_at` int(11) NOT NULL,
  `image` varchar(255) DEFAULT NULL,
  `about` text CHARACTER SET utf8,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=73 ;

--
-- Dumping data for table `users`
--


/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Friday, April 5, 2013

Online Vehicle Ticketing System Database Design Sample

Online Bus/Vehicle Ticketing System Database Design Sample – MySQL. With minor modifications or further generalization this database schema can be used to implement any kind of ticket booking system. eg. movie ticket booking system, events/show ticket booking etc. 

Entities:

users – user details
user_type – type of users in system
vendors – providers' information, in this case vehicle owner
vehicles – particular vehicle information
schedules – schedules of vehicles
routes – information of vehicle routes
vehicle_seats – vehicle seats information
tickets – actual ticket booking status etc stored here
media – images/videos etc related to particular vehicle stored here.
onlineticket

MySQL Create Script:

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 04, 2013 at 10:18 PM
-- Server version: 5.1.37
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `onlineticket`
--

-- --------------------------------------------------------

--
-- Table structure for table `media`
--

CREATE TABLE IF NOT EXISTS `media` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `vehicle_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `path` varchar(255) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='table for storing images, video etc about vehicles' AUTO_INCREMENT=1 ;

--
-- Dumping data for table `media`
--


-- --------------------------------------------------------

--
-- Table structure for table `routes`
--

CREATE TABLE IF NOT EXISTS `routes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `source` varchar(255) NOT NULL,
  `destination` varchar(255) NOT NULL,
  `distance` varchar(255) NOT NULL,
  `travel_time` varchar(255) NOT NULL,
  `stops` text NOT NULL,
  `fare` varchar(255) NOT NULL,
  `other_info` text,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `routes`
--


-- --------------------------------------------------------

--
-- Table structure for table `schedules`
--

CREATE TABLE IF NOT EXISTS `schedules` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `vehicle_id` int(11) NOT NULL,
  `departure_time` varchar(255) NOT NULL,
  `arrival_time` varchar(255) NOT NULL,
  `status` int(11) NOT NULL COMMENT 'schedule confirmed, delayed, cancelled',
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `schedules`
--


-- --------------------------------------------------------

--
-- Table structure for table `tickets`
--

CREATE TABLE IF NOT EXISTS `tickets` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ticket_no` varchar(255) NOT NULL,
  `schedule_id` int(11) NOT NULL,
  `seat_id` int(11) NOT NULL,
  `vehicle_id` int(11) NOT NULL,
  `route_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `status` int(11) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `tickets`
--


-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `phone` varchar(255) NOT NULL,
  `type_id` int(11) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `users`
--


-- --------------------------------------------------------

--
-- Table structure for table `user_type`
--

CREATE TABLE IF NOT EXISTS `user_type` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `slug` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `user_type`
--


-- --------------------------------------------------------

--
-- Table structure for table `vehicles`
--

CREATE TABLE IF NOT EXISTS `vehicles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `vendor_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `vehicle_info` text NOT NULL,
  `number` varchar(255) NOT NULL,
  `seats` int(11) NOT NULL,
  `driver` varchar(255) NOT NULL,
  `driver_phone` varchar(255) NOT NULL,
  `route_id` int(11) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `vehicles`
--


-- --------------------------------------------------------

--
-- Table structure for table `vehicle_seats`
--

CREATE TABLE IF NOT EXISTS `vehicle_seats` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `description` varchar(255) NOT NULL,
  `remark` varchar(255) NOT NULL,
  `vehicle_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `vehicle_seats`
--


-- --------------------------------------------------------

--
-- Table structure for table `vendors`
--

CREATE TABLE IF NOT EXISTS `vendors` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `description` text NOT NULL,
  `logo` varchar(255) DEFAULT NULL,
  `address` varchar(255) NOT NULL,
  `phone` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `website` varchar(255) NOT NULL,
  `user_id` int(11) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `vendors`
--


/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Tuesday, November 8, 2011

PyroCMS Themes, Widgets and Modules - for reference.

Themes :

https://github.com/semicolondevelopers/pyro_theme_artificial_casting
https://github.com/semicolondevelopers/pyro_theme_blue_spades
https://github.com/semicolondevelopers/pyro_theme_business_time
https://github.com/semicolondevelopers/pyro_theme_coffee
https://github.com/semicolondevelopers/pyro_theme_eco_design
https://github.com/semicolondevelopers/pyro_theme_night_club

PyroCMS v1.3.2 Theming Guide for beginners:
http://echo.semicolondev.com/2011/11/hot-to-create-pyrocms-v132-theme-step.html

PyroCMS Tag Cheat Sheet


Widgets

https://github.com/semicolondevelopers/pyro_widget_category
https://github.com/semicolondevelopers/pyro_widget_login_box
https://github.com/semicolondevelopers/pyro_widget_selected_category_posts

PyroCMS v1.3.2 Widget creation guide for beginners
http://echo.semicolondev.com/2011/11/how-to-create-pyrocms-v132-widgets.html

Modules:

Hello World Module
https://github.com/semicolondevelopers/pyro_module_hello

Old 0.9.9.x Forum module upgraded to v1.3.2
https://github.com/semicolondevelopers/pyro_module_forums

PyroCMS v1.3.2 & v0.9.9.7 Module Creation guide for beginners:
http://bhu1st.blogspot.com/2010/09/hello-world-pyrocms-module.html

Monday, November 7, 2011

नेपाली ब्लगरहरुलाई छोटो मीठो सल्लाह

Quick SEO tip for Nepali (Unicode) Bloggers

Here goes, one quick SEO (Search Engine Optimization) tip for Nepali Bloggers who use Blogger.com to publish their content written in Nepali Unicode.

What I’m talking about ?

Say: your blog post title is “मेरो नेपाल”
You publish it. Now blogger gives you one random “url/permalink” to your post which looks something like – http://yourblog.com/2011/11/blog-post.html. Why that happens is because blogger.com service is not made in Nepal. Now forget that reasoning since that does makes no sense.

Such permalinks suck from SEO perspective, ain’t it ? Blogger left no option to provide an equivalent English permalink/url for our Nepali Unicode blog article.

If the post had English/roman title like : Mero Nepal
Permalink would have been: http://yourblog.com//2011/11/mero-nepal.html

Do you see problem here ? Yes that’s what I am talking about. Now question is, what if we could provide a meaningful url to our Nepali Unicode post keeping the Unicode title as is ? Obviously, our content would be more search engines friendly.

Solution ?

Solution is so simple that even our grandmother would follow it. Let me describe that in steps.

Step 1:

Write your article in Nepali Unicode.

Step 2:

Give your post a equivalent roman or english title.
eg. instead of using “मेरो नेपाल” in blog title use “Mero Nepal” or “My Nepal”

Step 3:

Publish your blog post.
that gives us a readable URL in English or roman.

Step 4:

Now edit your blog post’s title – change it back to Nepali Unicode version.
use “मेरो नेपाल”  in title of the article now.

Step 5:

Re-publish the edited post.

Step 6:

Enjoy ! Let Google take care of the rest.

Conclusion

Search engines give more priority to the permalink/URL of the post. It makes sense to have a more meaningful, human readable URL to our blog post. It helps our reader to find our content via search engines.

If you find this tip useful, please leave a comment to this post or subscribe to my blog.

Tuesday, March 29, 2011

Android SDK and AVD Manager slow download problem

I was Installing the Android SDK (http://developer.android.com/sdk/installing.html) on my Windows XP box.

Problem : Slow download of android SDK platforms ~5kb/s


android sdk download ~5kb per second
Android SDK and AVD Manager Stalling During Download : Google Groups
Android sdk download/update failing : Stack Overflow

How to speed up Android SDK platform download ?

1. Allow download over http : check the option in Settings section of Android SDK and AVD manager.
https
2. Disable/Deactivate your antivirus application.
Recommended at : Adding SDK Components page

Caution: Before you install SDK components, we recommend that you disable any antivirus software that may be running on your computer. There are cases in which antivirus software on Windows is known to interfere with the installation process, so we suggest you disable your antivirus until installation is complete.

After allowing download over http and deactivating antivirus, my download speed increased to around 20kb/s. Still not good but better than ~5kb/s

android sdk download 20kb per second
3. Or you can prefer offline Android SDK component download option :
Stackoverflow: Download the Android SDK components for offline install 
(direct link to post describing offline download procedure)
Hope this helps save some of your android sdk platforms download time.


After download you can start with following Hello World android tutorials.

Android Hello world tutorials:

Hello, World – Android developers
http://developer.android.com/resources/tutorials/hello-world.html
Android Development Tutorial - Gingerbread
http://www.vogella.de/articles/Android/article.html


Or grab this book:




Cheers!

Monday, March 7, 2011

PHP Short Tag : Avoid Them

PHP Short Tag: 

it  look like this:

<?   ?>

<?= $var ?>

obvious ones:

<?php  ?>

<?php echo $var ?>.

I downloaded an open source php script, thinking to work it out for my own purpose – but what sucks is - the project uses short tag that my host doesn’t *seems* to provide support for. For the testing purpose i needed to TOGGLE the short tag on/off switch in php.ini

How to enable PHP Short Tag ?

Open your php.ini file in your favorite editor.

Here’s what it says in line number 214 through 226

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It's been
; recommended for several years that you not use the short tag "short cut" and
; instead to use the full <?php and ?> tag combination. With the wide spread use
; of XML and use of these tags by other languages, the server can become easily
; confused and end up parsing the wrong code in the wrong context. But because
; this short cut has been a feature for such a long time, it's currently still
; supported for backwards compatibility, but we recommend you don't use them.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
; short_open_tag = Off

Now change the short_open_tag = Off  to (remove semicolon)

short_open_tag = On

Restart Apache or XAMPP or your WAMPP installation

but here’s a big BUT below

 

Why you should avoid using PHP Short Tag ?

Stackoverflow : Answer

Normally you write PHP like so: <?php PHP CODE HERE ?>. However if *allow_short_tags* directive is enabled you're able to use: <? PHP CODE HERE ?>. Also sort tags provides extra syntax: <?= $var ?> which is equal to <?php echo $var ?>.

Short tags might seem cool but they're not. They causes only more problems. Oh... and IIRC they'll be removed from PHP6.

Stackoverflow: Answer

They're not recommended because it's a PITA if you ever have to move your code to a server where it's not supported (and you can't enable it). As you say, lots of shared hosts do support shorttags but "lots" isn't all of them. If you want to share your scripts, it's best to use the full syntax.

I agree that <? and <?= are easier on programmers than <?php and <?php echo but it is possible to do a bulk find-and-replace as long as you use the same form each time (and don't chuck in spaces (eg: <? php or <? =)

I don't buy readability as a reason at all. Most serious developers have the option of syntax highlighting available to them

 

Use it if :

  • you own a server and don’t care whether shared server support short tag or not
  • you don’t care what community says
  • you don’t want to Open Source your code later

<?php

/*

Oh please, don’t ask another question on stackoverflow about how to disable PHP Short Tag.

Rather you may want to write a parser that will loop through your 500+ php source code files and replace this Pain In The Ass PHP Short Tag to Normal PHP tag and share us the link. Here’s hint.

*/

?>

Sunday, March 6, 2011

Wordpress Themes / Templates - Useful Codes

Here are few fairly basic but handy wordpress codes that a wordpress theme or template developer/designers could use as reference. i personally use these a lot while working with wordpress.

 

Wordpress Site Name:

<?php bloginfo('name'); ?>

 

Wordpress Site Description:

<?php bloginfo('description'); ?>

 

Wordopress: Home Page Link:


<a href="<?php get_option('home'); ?>">Home</a></p>
or
<a href="<?php bloginfo('url'); ?>">Home</a>

 

Wordpress : Navigation – Display List of Pages in <li>

<?php wp_list_pages('title_li=&depth=1&exclude=2,7'); ?>

 

Wordpress Theme/Template Path:

<link rel="stylesheet" type="text/css" media="screen" href="<?php bloginfo('template_url');?>/css/screen.css" />

 

Wordpress : Inside The Loop

<?php the_permalink() ?>
<?php the_title_attribute(); ?>
Post time: <?php the_time('F jS, Y') ?>
Post Author: <?php the_author() ?>
Post Content: <?php the_content('Read the rest of this entry &raquo;'); ?>
Post Tags: <?php the_tags('Tags: ', ', ', '<br />'); ?>
Post Category: <?php the_category(', ') ?>
Post Edit Link: <?php edit_post_link('Edit', '', ' | '); ?>

 

Wordpress: Display Specific Page/Post Content

display specific  page content with page name

<?php query_posts('pagename=pname'); //pname = your page name?>
<?php while (have_posts()) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<p>
<?php the_content() ?>
</p>    
<?php endwhile; ?>

 display specific  page content with using page_id

<?php query_posts('page_id=1'); //put page id of Home or Stations  in your case?>
<?php while (have_posts()) : the_post(); ?>
<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<p>
<?php
the_content('Read the rest of this entry &raquo;')
?>
</p>
<?php endwhile; ?>

display specific  post content using post id

<?php
// retrieve one post with an ID of 5
query_posts( 'p=5' );
// set $more to 0 in order to only get the first part of the post
global $more;
$more = 0;
// the Loop
while (have_posts()) : the_post();
the_content( 'Read the full post »' );
endwhile;
?>

 

Wordpress : Get Custom Value

<?php
$cvalArr = get_post_custom_values("custom-val");   
$cval = $cvalArr[0];     
echo $cval
?>

 

Wordpress : Display X Latest Post from Category Y

<?php query_posts('posts_per_page=5&cat=2');
//post_per_page = number of post to grab
//cat = 2 –> from category 2, find your category id from admin
?>
<?php while ( have_posts() ) : the_post(); ?>
<?php //the_title(); ?>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>" title="Read full view of
<?php the_title_attribute(); ?>">Read more</a>
<?php endwhile; wp_reset_query(); ?>

i am thinking to put series of posts live describing wordpress development, let’s see.

Refs: Codex, Wordpress

http://codex.wordpress.org/Function_Reference/query_posts
http://codex.wordpress.org/Function_Reference/WP_Query

Friday, February 4, 2011

Hello World – Ruby on Rails

None of tutorials i found around web helped me get straight to the Ruby on Rails development environment in Windows. that’s why i thought would sum up how i setup rails in my Windows XP Professional box.

Yet, this was amusing (from Ruby on Rails Getting Started Guide)

If you’re working on Windows, you should be aware that the vast majority of Rails development is done in Unix environments. While Ruby and Rails themselves install easily using for example Ruby Installer, the supporting ecosystem often assumes you are able to build C-based rubygems and work in a command window. If at all possible, we suggest that you install a Linux virtual machine and use that for Rails development, instead of using Windows.

Let’s start.

1. Rails Development Environment Prerequisites/Setup

you should have following things installed before you can ride on Rails

- Install Ruby Language
- RubyGems Packaging System
- A working installation of the SQLite3 Database. you can setup other databases later.

Ruby Installer bundles all ruby development environment within one click setup file. Download the latest version of Ruby Installer from this page: http://rubyinstaller.org/downloads/

i downloaded : Ruby 1.9.2-p136

it installs Ruby, Ruby Gems etc.. in your selected drive. don’t forget to check the “Environment path tick mark” during installation, that helps later.

Check installed components going to the program listing in Start Menu-> All Programs

add the Ruby Installation path to the SYSTEM or USER PATH eg path.  C:\Ruby192>

 

2. Verify the Ruby and RubyGems Installation

Go to Command Prompt  (Run->CMD)

Verify your environment variables i.e PATH is setup correctly otherwise we may run into problems.

Type following commands:

ruby –v 

should give you ruby version

and

gem –v

should give you gem version

in my case:
ruby version : 1.9.2
gem version: 1.5.0

if you didn't get these numbers, update gem, execute following command

gem update --system



takes few minutes to update your gem package.



3. Now Setup Rails



execute the following command in command line




gem install rails




it will install rails, takes few minutes. you can take a cup of coffee while rails gets completely installed.



check rails version after installation:




rails –v




gives you rails installation version. a long number looks scary.



4. Setup Sqlite3 database



execute following command:




gem install sqlite3-ruby




the installed sqlite3 gem requires sqlite3.dll file. you need to download, copy/cut/whatever –then- paste the sqlite3.dll file to your Ruby or system path.



Go to Sqlite download page http://www.sqlite.org/download.html 
Scroll down to “Precompiled Binaries For Windows”


Download the “This ZIP archive that contains a DLL for the SQLite library version 3.x.y



Extract the zip, copy the sqlite3.dll  to system PATH




That’s it.



5. Create your first Rails application : The New Hello World “Ruby on Rails”



create a special folder somewhere in you hard disk dedicated to rails project.

eg. D:\web\rails





Change working directory to that path. execute following command:




rails new the_new_hello_world




the_new_hello_world <—this is the name of the web app we are going to create. name it whatever you like.



if everything went fine, rails will create a “web app template” folder in your current directory i.e the_new_hello_world directory with bunch of files/folders, yes they suck.



6. Run the development web server



execute following command:




rails server




hurray! your development web server will be now running : http://localhost:3000/





Go to that page at http://localhost:3000/ . It is there to welcome you to Rails, follow the instruction under Getting Started Section.



1. Use “rails generate” to create your models and controllers


2. Set up default route and remove or raname the config/routes.rb file


3. Create your database





Continue reading the Getting Started Guide after successfully  setting up the rails environment.  http://guides.rubyonrails.org/getting_started.html





Congratulations!!!



you are now riding on rails. where are you going?





Mention me if it didn’t work for you. i might help.


Cheers.

Friday, January 14, 2011

7th National ICT Student & Youth Conference – My Paper Abstract

Event

7th National ICT Student & Youth Conference
Date: 15th January 2011, (Saturday)
Venue: Local Development training Center, Jawlakhel, Lalitpur
Time: 9:00 A.M – 4:00 pm

banner

Organized By:

Information technology Society, Nepal (ITSN)

Conference Theme:

Youths on collaborative development

Conference Tracks:

Recent Trends in IT for Rural Developments
Smart Data Policy
IT Security
Electronic Document Management
Future Information Technology
Information & Multimedia Technology
Cyber-cultures
Knowledge Discovery
E-Democracy, E-Participation and E-voting
Security & Cryptography
Digital Enterprise
E-Tourism for 2011
Impact of social network over Youth

tracks

 

I’ve always been a community and collaboration admirer. at present i work as software developer and there are few tools and concepts that we use daily to facilitate collaborative development. To share this idea, and expecting participation of college students in group software development in future i am going to present a paper titled “Collaborative Software Development – how Nepali youths could do it?”.

i will be talking about using Open Source and free collaboration tools available online and how we can use them to make our day to day software development tasks easier

My Paper Abstract:

Title:

        Collaborative Software Development,
        how Nepali youths could do it ?

Estimated Time:  20 Minutes for presentation

Update: This paper was created collaborating with @bibekraj . we used Google Docs Presentation as collaboration tool.

Abstract:

Collaboration is working together on site or off site,  in which two or more people work together convinced around a common goal.

In collaborative software development, a small sized team of developers or larger community of developers work together using specific source code control methods to facilitate the code sharing and combine working environment.

In foreign countries (US/UK) software development has flourished so much that they are leading the software development industry as a whole. The clue for this success is nothing more that community effort or to say collaborative contribution by a lot of developers who live in those countries. Whereas in Nepal, a youth gets introduced to collaborative development only after attempting few job interviews or looking through job vacancies. Knowledge of collaborative working is so essential that, the chances are odd you would be hired without its practical working knowledge. Further, knowledge of basic collaborative development tools will give each individual the opportunity to explore the whole Open Source World of software development.

The popular Open Source Software hosting platforms like, Google Code hosting, Github, SourceForge.Net are so rich in their user base (users who are developers or coders) and project base that any guy with few knowledge of writing "Hello World" codes in languages like C, C++, PHP, C#, Python, Ruby can get to see the actual code behind stable releases of larger Open Source projects. This gives a developer an opportunity to see how "the code" works in real world. How can she write better codes. What are best practices in software development. Obviously, if she can, she would contribute back to the project itself.

This paper, exploring the "7th National ICT Student & Youth Conference"  - Youths on collaborative development theme will try to introduce basic collaboration concepts, tools and how can we use them to get into Collaborative Software Development on personal team or community based teams to the college students of Nepal.

About Me:

at present i work as software developer at Semicolon Developers,
and working on ITS – Nepal as Second Vice President.

(I will attach the presentation here after conference, most probably tomorrow eve, stay tuned)

The Conference is Open to all Nepali professionals, youths and college students. Be in conference hall on time (around 9am) and we would go through all the registration process.

Location (ref: Ghanshyam):

location

Hope to meet you there.

Update:

Here’s the slide i presented today.

Download as PPT
Download as PDF

 

happy to know after presentation that participants liked it :)

Saturday, September 25, 2010

Hello World - PyroCMS Module

/*---------------------------------------------------------------------------------------------
Update 10/16/2011:

This tutorial has been here for older version (< 1.0.x) of PyroCMS. Latest Stable PyroCMS release is v1.3.2
Please download and use following tutorial files which are for PyroCMS 1.3.2:

PyroCMS Hello World Module tutorial pdf for v1.3.2
Download Sample Hello World Module PyroCMS 1.3.2

Pyro docs have been significantly improved over the year. You can refer it too. If you need developers to work on your PyroCMS project you can contact us here - Semicolon Developers.

(Many thanks to Alan Martin from South Africa who forwarded me these updates.)

---------------------------------------------------------------------------------------------*/
PyroCMS Version: 0.0.9.9.x
What’s here:
------------------------------------------------------------
PyroCMS Module – Folder Location?
PyroCMS Module – Files Required & Folder Structure?
PyroCMS Module – Frontend/Backend Snapshot (of what we are going to build)
PyroCMS Module – Coding the Hello World module with full MVC implementation 
Why "<![CDATA  MySql stuffs     ]]>" required to be in correct format in details.xml ?
Hello world module Code
Summary
----------------------------------------------------------
With this text, I assume your familiarity with PyroCMS folder structure and theming, and you are testing on xampp.  I would explain how to make PyroCMS Module with very basic concepts from Codeigniter and PyroCMS.  Do double check what i have highlight here,  you may get errors installing/running the module we create, otherwise.
PyroCMS is good, but its documentation is not enough/not clear. I mean, once you know stuffs, its very easy to understand things at one shot, but it is rarely the case with beginners, that’s why i thought i would put the example on it.
Don’t copy-paste the code from the example below rather download source code from github, in copy pasting you might face quotes errors. mysql query might not work.

PyroCMS Module – Folder Location?

PyroCMS Core Modules
…..xampp\htdocs\pyrocms\application\modules\pages
”pages” is pyrocms core module that handles the pyroCMS page element

Custom Modules / Third Party Module / we are creating one now

Custom Modules are placed under projectname\third_party\modules  folder
xampp\htdocs\pyrocms\third_party\modules\helloworld
pyrocms – our project name
helloworld – the module we are going to create.
Remember Core and Third Party modules and their directories.

PyroCMS Module – Files Required?

PyroCMS requires at least a details.xml and one controller inside the module-name folder to be a module. I will explain file requirements for different types of module creation. Filenames and folders, are understood easily if you know Codeigniter MVC conventions. If you are not familiar with CI and trying to build PyroCMS module, still its easy to grasp the folder structure with one easy attempt like this. You can have following folders inside a custom module folder - config, controllers, helpers, libraries, models, views, js, css, img.
1. helloworld\details.xml
-> its basic structure is explained in detail below
-> this file contains module name, description, version etc.. and some useful configuration options that help PyroCMS understand our new module. Say Hello! Introduce your module here.
2. helloworld\controllers\helloworld.php
-> the name of the controller (file name & class name) keep them same as module name
-> If you need module just for front end and nothing required in backend, you’d need at least one controller, and extend the controller class from Public_Controller.
-> if you need to access these module from backend (like CRUD interface in backend), you’ll need  a controller class helloworld\controllers\admin.php which would extent Admin_Controller
When i write a file name like helloworld\controllers\helloworld.php i expect, you have created a helloworl.php controller inside controllers folder inside our helloworld module.
3. helloworld\views\helloworld.php
-> view file which would be used for displaying data from module controller
->If you don’t need to access database for your module these 3 files will suffice your need for creating module, otherwise you need model class too. Take your time to understand the folder structure.
-> if you thought to put backend admin controllers in setp 2 above, then think about placing its views too.

let’s place some view files as for admin side in a views\admin folder for easy structure: 

helloworld\views\admin\index.php
-> pass data to this view from admin controller
helloworld\views\admin\sidebar.php
-> sidebar partial that’s shown in left sidebar of the default backend theme.
-> partial is just few tags and php codes together. think of it as general “view file” . For eg. the box in the sidebar of other modules you see while browsing in admin.
4. helloworld\models\helloworld_m.php

So when we require database access or to implement business logic, we create models :
helloworld_m.php  <— this is a convention of underscore m, model class name would be Helloworld_m . You can create more model files as per your need.
Don’t forget to place these file on respective Models/Views/Controllers folder according the folder structure in the figure (at end of this section below)
1. helloworld\details.xml
2. helloworld\controllers\helloworld.php
      ----> helloworld\controllers\admin.php  [controller for admin interface]
3. helloworld\views\view_file.php
    -------> helloworld\views\admin\index.php –> admin main view
    ------> helloworld\views\admin\sidebar.php –> admin sidebar partial
4. helloworld\models\helloworld_m.php
If your module is complex, you end with more files, that’s okay.
PyroCMS module file/folder structure is MVC, just bundled within a module folder. That’s what makes PyroCMS HMVC ( Hierarchical Model View Controller). PyroCMS is codeigniter based, if you know codeigniter you have an option to understand HMVC and build your own CMS ;) Good Luck.

Here’s the PyroCMS helloworld module folder structure:
module_structure

PyroCMS Module – Frontend/Backend Snapshot

Let’s have a look at what our module will look in front-end and backend

Frontend: <h1><?php echo $msg; ?></h1> that’s it
front
(to see a module in action, we’d after installing helloworld module link one header navigation to our module)

Section of what you see when you add new navigation link:
link_module
Backend:

Module installed and listed in the Admin –> Modules-> Third party Section (we don’t create view for this listing, PyroCMS automatically lists our new module there if successfully installed, information is taken from details.xml)
modulelist
We have – index.php and  sidebar.php  for admin side view,
when we build template from these two view that will look as below on the admin side.
Hello World Module Page on admin side: 
 admin
noticed the – left sidebar? main content? helloworld link on the admin navigation, link to hello world module in the dropdown modules list ?

PyroCMS Module – Coding the module

The code is just for illustration purpose. My idea is to help you create and install your own custom module.

1. helloworld\details.xml
2. helloworld\controllers\helloworld.php
      a. ----> helloworld\controllers\admin.php  [controller for admin interface]
3. helloworld\views\view_file.php
      a. -------> helloworld\views\admin\index.php –> admin main view 
      b. ------> helloworld\views\admin\sidebar.php –> admin sidebar partial
4. helloworld\models\helloworld_m.php
we’ll create 1 (details.xml) + 2 (controllers) + 3 (views) + 1 (model file) = 7 files in total and respective folders Models\Views\Controllers and place them inside MVC folder structure.

1. helloworld\details.xml

A. basic file / when no backend and MySQL required:

-> When we don’t need custom table for our module in database or when we are just working on PyroCMS tables to access data, we can have a minimal details.xml as follows.
<?xml version="1.0" encoding="UTF-8"?>
<module version="0.1">
  <name>   
    <en>Helloworld</en>   
  </name>
  <description> 
    <en>Displays Hello World! Message to user</en>   
  </description>  
  <skip_xss>1</skip_xss>
  <is_frontend>1</is_frontend> 
  <is_backend>0</is_backend>
  <is_backend_menu>0</is_backend_menu>   
</module>

where:
<name> &  <description>  will help list the module in admin->modules->third party modules list.
<skip_xss>1</skip_xss> – skip_xss true
<is_frontend>1</is_frontend>  - front end of the module exists <is_backend>0</is_backend>  - module has no backend support
<is_backend_menu>0</is_backend_menu>   - module will not be listed in backend admin navigation
B. Advanced file / when backend of module exists and our module will have its own database table to operate:
<?xml version="1.0" encoding="UTF-8"?>
<module version="0.1">
  <name>   
    <en>Helloworld</en>   
  </name>
  <description> 
    <en>Displays Hello World! Message to user</en>   
  </description>  
  <skip_xss>1</skip_xss>
  <is_frontend>1</is_frontend> 
  <is_backend>1</is_backend>
  <is_backend_menu>1</is_backend_menu>   
    <controllers>
        <controller name="admin">
            <method>index</method>           
        </controller>
    </controllers> 
    <install>
<![CDATA[  
DROP TABLE IF EXISTS hello_world;
-- command split --
CREATE TABLE hello_world (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`msg` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL
) ENGINE = MYISAM ; 
-- command split --
INSERT INTO `hello_world` (`id`,`msg`)
VALUES (NULL , 'hello world from PyroCMS module, from db'),
(NULL , 'Greetings from @bhu1st');
]]>
  </install>
<uninstall>
<![CDATA[
  DROP TABLE IF EXISTS hello_world;
]]>
</uninstall>
</module>
Did you see the changes??
is_backend set to one. i.e module accessible in backend. If database table are used just for storing information and no backend access required this can be set to zero.
<is_backend>1</is_backend>   - we are going to build module backend accessible
<is_backend_menu>1</is_backend_menu>  - module will be listed in admin side navigation menu  

Name of the admin controller and its methods

We add code  below when we create module that have backend interface.
<controller name=”admin”> tells we are going to create a
helloworld\controllers\admin.php  - controller
The controller that will extend Admin_Controller and we would have one method named index in it.
<controllers>
       <controller name="admin">
           <method>index</method>            
       </controller>
</controllers> 

MySQL Queries required at module install time
Before explaining this i want you to remember that details.xml file is a XML document.
Let me explain, What is this "<![CDATA  MySql stuffs     ]]>" doing here?

Everything inside a CDATA section is ignored by the XML parser, but will be used by PyroCMS module install routine.
XML Document Parser will parse all <element></element> but, characters inside the "<![CDATA  -----------    ]]>"  are not parsed by XML parsers and they are taken as raw string of characters.  So the advantage is we keep our required MySQL queries inside it, as normal storage. At XML document parse time (module installation),  the content between <install></install> is taken, split by the separator -- command split --  and executed over the PyroCMS database that we setup in PyroCMS installation process.
Remember:
a. Include your MySQL queries inside "<![CDATA” &    “ ]]>"
b. Separate each MySQL query by the separator
          -- command split --
c. the CDATA end marker ]]>" cannot contain spaces or line breaks before it. Just place it before </install> as

]]>
</install>

d. last query doesn’t need the -- command split --  separator
e. CDATA can not be nested 

So the code below contains two queries,  clear to see:

<install>
<![CDATA[  
DROP TABLE IF EXISTS hello_world;
-- command split --
CREATE TABLE hello_world (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`msg` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL
) ENGINE = MYISAM ; 
-- command split --
INSERT INTO `hello_world` (`id`,`msg`)
VALUES (NULL , 'hello world from PyroCMS module, from db'),
(NULL , 'Greetings from @bhu1st');
]]>
</install>
In this CDATA section, we first drop the table “hello_world” if exists in database, then we create and insert some data in the hello_world table. That’s it. Our table is created and populated with the supplied data, if module installation went fine, you should be able to see the hello_world table in PyroCMS database you setup before.
MySQL Queries required at module uninstall time
  <uninstall>
<![CDATA[
  DROP TABLE IF EXISTS hello_world;
]]>
</uninstall>
If you grasped the CDATA concept, only thing that concerns us in <uninstall></uninstall> code is the MySQL query “DROP TABLE IF EXISTS hello_world;”, yup, this will be triggered when you uninstall the module.  That’s fine. Tables created during install time will be deleted.

C. When your module is just accessed in backend, like Newsletter module etc..

 
<is_frontend>0</is_frontend>
<is_backend>1</is_backend>
<is_backend_menu>0</is_backend_menu>
refer code above with these settings for full details.xml code..

2. helloworld\controllers\helloworld.php

Code/comment explains itself, you may refer above sections too.
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
|-------------------------------------
| Publich Controller of our module
|-------------------------------------
| accessed from front end
|
| extends Public_Controller
*/
class Helloworld extends Public_Controller
{
    function __construct()
    {
        parent::Public_Controller();
    }
    function index()
    {
        //load model
        $this->load->model('helloworld_m');
        //get message from model
        $message = $this->helloworld_m->getHelloMsg();
        //pass message and build template
        $this->data->msg = $message;       
        $this->template->build('helloworld', $this->data);
    }
}

2. a. helloworld\controllers\admin.php  [controller for admin interface]

The controller file name “admin.php” since we specified so in our details.xml

<controllers>
       <controller name="admin">
           <method>index</method>            
       </controller>
</controllers> 

The Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
|-------------------------------------
| Admin Controller of our module
|-------------------------------------
| accessed from back end
| extends Admin_Controller
|
*/
class Admin extends Admin_Controller
{
    public function __construct()
    {
        parent::Admin_Controller();       
        //load model
        $this->load->model('helloworld_m');   
        //set views/admin/sidebar as 'sidebar' partial,
        //that is to be shown on Sidebar section of backend
        $this->template->set_partial('sidebar', 'admin/sidebar');
    }
    //Show Helloworld message to admin
    function index()
    {           
        //function triggred when we click on the module name in backend in the menu
        //get message from model
        $message = $this->helloworld_m->getHelloMsg();
        //pass message and build template
        $this->data->msg = $message;           
        $this->template->build('admin/index', $this->data);
    }
}
?>

3. helloworld\views\view_file.php

<h1><?php echo $msg; ?></h1>

3.a. helloworld\views\admin\index.php - admin main view 

Hi,
<br/> <br/>
<h2><?php echo $msg; ?></h2>

3.b, helloworld\views\admin\sidebar.php –> admin sidebar partial

see how it is set as sidebar partial in constructor of our Admin controller 2. a. helloworld\controllers\admin.php

  $this->template->set_partial('sidebar', 'admin/sidebar');

this view file would contain following html:
<div class="box">
    <h3>About Me</h3>   
    <div class="box-container">
        Bhupal Sapkota<br/>
        Kathmandu, Nepal<br/>
    </div>
</div>
i’ve put a little bit info about me, never mind. Put any <html> or Pyro stuff you like there.

4. helloworld\models\helloworld_m.php – our model class

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
|-------------------------------------
| Model Class of our module
|-------------------------------------
| for database access
|
*/
class Helloworld_m extends Model
{
    function __construct()
    {
        parent::Model();
    }
    function getHelloMsg()
    {   
        //get hello_world table
        $query = $this->db->get('hello_world');
        //if module successfully installed and data exists in table, grab it, return it
        if($query->num_rows() > 0){
            $result = $query->row_array();
            return $result['msg'];   
        }else { //otherwise return simple hello message       
            return "Hello world from PyroCMS Module!";
        }
    }
}
?>


Install Helloworld Module

->Download code from Helloworld PyroCMS Module in Github

zip your module, and upload it from the Modules –> Third party section, Upload link
If your MySQL queries had no problems, you’d see hello_world table added in PyroCMS database. Helloworld module will be listed in admin navigation, modules list, in third party section.

When you uninstall

module gets deleted from third_party\modules\ folder. think of having a backup before uninstall.

Module In Action

Access module from Admin Navigation menu or type this in browser:

Backend:
http://localhost/projectname/admin/modulename

 http://localhost/pyrocms/admin/helloworld
Frontend:
Assign one frontend navigation link to point our helloworld module
http://localhost/projectname/modulename
 http://localhost/pyrocms//helloworld

Output Check

I have added validation in our model Helloworld_m,
function getHelloMsg()
    {   
        //get hello_world table
        $query = $this->db->get('hello_world');
        //if module successfully installed and data exists in table, grab it, return it
        if($query->num_rows() > 0){
            $result = $query->row_array();
            return $result['msg'];   
        }else { //otherwise return simple hello message       
            return "Hello world from PyroCMS Module!";
        }
    }
If SQL executed successfully during module install, the $msg in view renders “hello world from PyroCMS module, from db” otherwise  "Hello world from PyroCMS Module!";

Conclusion

1. follow the file/folder structures and naming conventions.
2. Understand the module creation requirement and accordingly settings in details.xml
3. CDATA section of the details.xml needs to carefully saved. Check your queries in database before saving them in CDATA section.
4. Upload your module to install it.  [ remember to upload zip file, zip file name same as module name ]
[helloworld.zip] or [yourmodule.zip]
5. If upload failed, delete raw upload from third_party modules folder, database column if any, check your settings, check queries again, zip it, and re-upload.
5. If still couldn’t install it:
--> i think you now understand the module creation flow
--> insert few queries in database  [details.xml]
-> add your module settings in modules table in database [details.xml]
-> don’t wait for any other documentation ;) the kickass CMS, created over the kickass framework is really easy to grasp in one shot back tracing, 2-3 hours max  
-> hack it use it. contribute back if any.
-> if you are familiar with Codeigniter and not with HMVC  <------ read