Posts

Showing posts from 2015

PLSQL Procedure in Erlang

Image
Functions/Procedures from Erlang: Prepare your DB: drop table employee; CREATE TABLE EMPLOYEE ( "NR" NUMBER, "FIRSTNAME" VARCHAR2(20), "LASTNAME" VARCHAR2(20), "GENDER" CHAR(1), "EXPERIENCE" NUMBER ) ; ALTER TABLE EMPLOYEE ADD PRIMARY KEY ("NR"); DROP SEQUENCE EMPLOYEE_SEQ; CREATE SEQUENCE EMPLOYEE_SEQ INCREMENT BY 1 START WITH 1 MAXVALUE 9999999999999999999999999999 MINVALUE 1 CACHE 20; create or replace TRIGGER EMPLOYEE_SEQ_TRG BEFORE INSERT ON EMPLOYEE FOR EACH ROW BEGIN <<COLUMN_SEQUENCES>> BEGIN IF INSERTING AND :NEW.NR IS NULL THEN SELECT EMPLOYEE_SEQ.NEXTVAL INTO :NEW.NR FROM SYS.DUAL; END IF; END COLUMN_SEQUENCES; END; insert into EMPLOYEE(FIRSTNAME, LASTNAME, GENDER, EXPERIENCE) values ('Richa','Vaidya','F',4); select * from EMPLOYEE; and check the output. Lets create a procedure for inserting:

Learning PHP Now ;)

Image
I am learning PHP now. Here is a basic tutorial on PHP. What all do you need to learn PHP? 1.        I am using XAMPP server : https://www.apachefriends.org/index.html Check the video on how to install XAMPP from the site. 2.        That’s it! Yes. If you install XAMPP Server for development, that’s all you need. It allows you to select all that you want to install : PHP, Perl, MySql etc. Easy to install and use. Assumptions for the tutorial: 1.        The installation directory for XAMPP is C:\xampp 2.        You have basic HTML Knowledge 3.        Other assumptions will be added as I come across them :D Starting you XAMPP: If you have checked the video on XAMPP Site, you probably have already started XAMPP and MySql Server. If you get error like: www.example.com:443:0 server certificate does NOT include an ID which matches the server name Restart xampp-control using admin user.  Your first php application can be a really simple one. I always

PL/SQL Procedure

Image
Creating a procedure in PL-SQL: Firstly, we create a table, a sequence for the primary keys and a trigger to handle the value of primary key. =========================== DROP TABLE DUMMY_TABLE; CREATE TABLE DUMMY_TABLE( DUMMY_ID INTEGER, TIME_DELAY INTEGER ); ALTER TABLE DUMMY_TABLE ADD( CONSTRAINT DUMMY_PK PRIMARY KEY(DUMMY_ID) ); DROP SEQUENCE DUMMY_SEQUENCE ; CREATE SEQUENCE DUMMY_SEQUENCE INCREMENT BY 1 START WITH 1 MAXVALUE 9999999999999999999999999999 MINVALUE 1 CACHE 20; CREATE OR REPLACE TRIGGER DUMMY_SEQUENCE_TRIGGER BEFORE INSERT ON DUMMY_TABLE FOR EACH ROW BEGIN < > BEGIN IF INSERTING AND :NEW.DUMMY_ID IS NULL THEN SELECT DUMMY_SEQUENCE.NEXTVAL INTO :NEW.DUMMY_ID FROM SYS.DUAL; END IF; END COLUMN_SEQUENCES; END; Here we have created a dummy table, a sequence and a trigger. On every insert on the table, the trigger will be called and next value of oour sequence will be the ID/Primary key of our table. Let us now se

Java - Equals and Hashcode

Image
Every object has the following two properties: 1. An ability to compare itself with any other object 2. A int value associated with it, which can have a business logic There are a few basic rules to be applied for two objects to be equal: Consistency : If two objects are equal they should always be equal provided none of their values(which determine their equality) change Symmetry : If object1 equals object2, then object2 should equal object1, Same rule for non-equality Reflexive : If you compare an object with itself, it should always return true, under all circumstances Transitivity : If object1 equals object2, and object2 equals object3, then object1 should equal object3. Why do we need equals method when we have ==? == checks for reference equality (if two reference are same) equals method checks if two objects are equal or not Just be sure of overriding equals method before using it. Else be ready for false, except when comparing same references :D It is a

Erlang OTP

Joe Erlang had fault tolerance in his mind when he designed and implemented Erlang. He was the chief architect of the project which built Erlang/OTP. Features of Erlang: Concurrent Scalable Soft-Real Time Distributed Fault Tolerant Where all is Erlang used? Telecom Banking E-Commerce Instant Messaging Computer Telephony What is OTP? OTP is set of Erlang libraries and design principles providing middle-ware to develop these systems. It includes its own distributed database applications to interface towards other languages debugging release handling tools Ericsson managed to get the nine 9's reliability in one of its product (99.9999999% reliability). Erlang is based on the following ideas: Share Nothing Pure message passing Crash detection. Let it crash and recover principle Erlang processes are very lightweight. Erlang can have hundreds of thousands of processes. Garbage collection is also good. It can have thousands of independent heaps and all are

Writing your own ejabberd Module

Coming soon: What is ejabberd? What is erlang? Installation details. I will start with writing the ejabberd module first. Once you have done all the installations: sudo make sudo make install sudo ejabberdctl start sudo ejabberdctl stop You can check the status using: sudo ejabberdctl status You can locate logs at: (With default installation) /var/log/ejabberd All config related changes will be mainly done at: /etc/ejabberd/ejabberd.yml You will need a basic understanding of erlang. You can take a short crash course at: http://www.erlang.org/course/course.html This is a good reference. Go to your ejabberd-15.07/src directory. This is where you will write the hook for your ejabberd server. Create a file, say mod_changeBody.erl. Your module name and file name should be same. Add the following basic contents into your erl file: -module(mod_changeBody). -behavior(gen_mod). -include("ejabberd.hrl"). -include("logger.hrl"). -expo