Expressions.jsp Page that demonstrates JSP expressions. Uses the JSP-Styles style sheet.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
Example of JSP Expressions.
Taken from Core Web Programming Java 2 Edition
from Prentice Hall and Sun Microsystems Press,
.
May be freely used or adapted.
-->
<HTML>
<HEAD>
<TITLE>JSP Expressions</TITLE>
<META NAME="keywords"
CONTENT="JSP,expressions,JavaServer,Pages,servlets">
<META NAME="description"
CONTENT="A quick example of JSP expressions.">
<LINK REL=STYLESHEET
HREF="JSP-Styles.css"
TYPE="text/css">
</HEAD>
<BODY>
<H2>JSP Expressions</H2>
<UL>
<LI>Current time: <%= new java.util.Date() %>
<LI>Your hostname: <%= request.getRemoteHost() %>
<LI>Your session ID: <%= session.getId() %>
<LI>The <CODE>testParam</CODE> form parameter:
<%= request.getParameter("testParam") %>
</UL>
</BODY>
</HTML>
Jul 29
Expressions.jsp Page that demonstrates JSP expressions. Uses the JSP-Styles style sheet.
Jul 29
A simple C++ Program code
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream in("test", ios::in | ios::binary);
if(!in) {
cout << "Cannot open input file.\n";
return 1;
}
double num;
char str[80];
in.read((char *) &num, sizeof(double));
in.read(str, 14);
str[14] = '\0'; // null terminate str
cout << num << ' ' << str;
in.close();
return 0;
}
Jul 29
valarray with double value inside
/* The following code example is taken from the book
* "The C++ Standard Library - A Tutorial and Reference"
* by Nicolai M. Josuttis, Addison-Wesley, 1999
*
* (C) Copyright Nicolai M. Josuttis 1999.
* Permission to copy, use, modify, sell and distribute this software
* is granted provided this copyright notice appears in all copies.
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*/
#include <iostream>
#include <valarray>
using namespace std;
// print valarray line-by-line
template<class T>
void printValarray (const valarray<T>& va, int num)
{
for (int i=0; i<va.size()/num; ++i) {
for (int j=0; j<num; ++j) {
cout << va[i*num+j] << ' ';
}
cout << endl;
}
cout << endl;
}
int main()
{
/* valarray with 12 elements
* - four rows
* - three columns
*/
valarray<double> va(12);
// fill valarray with values
for (int i=0; i<12; i++) {
va[i] = i;
}
printValarray (va, 3);
// assign 77 to all values that are less than 5
va[va<5.0] = 77.0;
// add 100 to all values that are greater than 5 and less than 9
va[va>5.0 && va<9.0] = valarray<double>(va[va>5.0 && va<9.0]) + 100.0;
printValarray (va, 3);
}
/*
0 1 2
3 4 5
6 7 8
9 10 11
77 77 77
77 77 5
106 107 108
9 10 11
*/
Jul 28
নোড . জে এস । Node.js – ইউটিলিটি মডিউল (Utility Modules)
নোড . জে এস । Node.js – ইউটিলিটি মডিউল
রিদওয়ান বিন শামীম
নড জেএস মডিউল লাইব্রেরিতে বেশ কিছু সংখ্যক ইউটিলিটি মডিউল আছে। এই মডিউলগুলো খুব কমন আর নড ভিত্তিক এপ্লিকেশনে প্রচুর ব্যবহৃত হয়ে থাকে।
S.N. মডিউলের নাম ও বিবরণ
1 ওএস মডিউল
অপারেটিং সিস্টেম সংক্রান্ত ইউটিলিটি ফাংশনের ব্যবস্থা করে।
2 পাথ মডিউল
ফাইল পাথ নিয়ন্ত্রণ ও ব্যবস্থাপনার সুযোগ দেয়।
3 নেট মডিউল
সার্ভার ও ক্লায়েন্টকে স্ট্রিম রূপে প্রকাশ করে। নেটওয়ার্ক রাপার হিসেবে কাজ করে।
4 ডিএনএস মডিউল
প্রকৃত ডিএনএস লুকআপের জন্য ফাংশনের ব্যবস্থা করে, অন্তর্নিহিত অপারেটিং সিস্টেমের নাম রেজুলেসনের ফাংশনালিটি ব্যবহারের জন্য
5 ডোমেইন মডিউল
মাল্টিপল আই/ও অপারেশনকে সিঙ্গেল গ্রুপ হিসেবে নিয়ন্ত্রণের সুযোগ সৃষ্টি করে।
তথ্যসূত্রঃ http://www.tutorialspoint.com/nodejs/nodejs_utitlity_module.htm
Jul 27
নোড.জেএস : Node.js – বাফার
রিদওয়ান বিন শামীম
পিউর জাভাস্ক্রিপ্ট ইউনিকোড বান্ধব কিন্তু বাইনারি ডাটায় তেমন নিখুঁত নয়। টিসিপি সিস্টেম বা ফাইল স্ট্রিম নিয়ে কাজ করার সময় অক্টেট স্ট্রিম নিয়ন্ত্রণের প্রয়োজন হয়। নড বাফার ক্লাস প্রভাইড করে যা কিনা পূর্ণসংখ্যার অ্যারির সদৃশ ‘র’ ডাটা সংরক্ষণের সুযোগ দেয় কিন্তু ভি৮ হিপের(V8 heap)বাইরে ‘র’ মেমোরি এলোকেশনের সাথে সুসংহত থাকে।
বাফার ক্লাস গ্লোবাল ক্লাস, এটি বাফার মডিউল ইমপোর্ট করা ছাড়াই এপ্লিকেশনে ব্যবহার করা সম্ভব।
বাফার তৈরি করা
কয়েকটি উপায়ে বাফার তৈরি করা যেতে পারে,
প্রথম পদ্ধতিঃ ১০ অক্টেটের আনইনিসিয়েটেড বাফার তৈরির সিনট্যাক্স,
var buf = new Buffer(10);
দ্বিতীয় পদ্ধতিঃ প্রদত্ত অ্যারি থেকে বাফার তৈরির সিনট্যাক্স,
var buf = new Buffer([10, 20, 30, 40, 50]);
তৃতীয় পদ্ধতিঃ প্রদত্ত স্ট্রিং থেকে বাফার তৈরির সিনট্যাক্স ও অপশনাল এনকোডিং টাইপ,
var buf = new Buffer(“Simply Easy Learning”, “utf-8”);
যদিও ডিফল্ট এনকোডিং হল “utf8” , আমরা “ascii”, “utf8”, “utf16le”, “ucs2”, “base64” বা “hex” ইত্যাদিও ব্যবহার করতে পারি।
বাফারে লেখা
নড বাফারে লেখার জন্য সিনট্যাক্স,
buf.write(string[, offset][, length][, encoding])
প্যারামিটারঃ সংশ্লিষ্ট প্যারামিটারগুলো হল,
- স্ট্রিং
- অফসেট
- লেন্থ
- এনকোডিং
রিটার্ন ভ্যালু
এই প্রক্রিয়া লিখিত অক্টেটের নাম্বার রিটার্ন করায়। বাফারে পুরো স্ট্রিংএর জায়গা না থাকলে আংশিক লেখা হয়। যেমন,
buf = new Buffer(256);
len = buf.write(“Simply Easy Learning”);
console.log(“Octets written : “+ len);
এটি সঠিকভাবে সম্পাদিত হলে তা যে ফলাফল দেখাবে তা হল,
Octets written : 20
বাফার থেকে পড়াঃ এজন্য প্রয়োজনীয় সিনট্যাক্স হল,
buf.toString([encoding][, start][, end])
এর প্যারামিটারগুলো হল,
- এনকোডিং
- স্টার্ট
- এন্ড
উদাহরণ,
buf = new Buffer(26);
for (var i = 0 ; i < 26 ; i++) {
buf[i] = i + 97;
}
console.log( buf.toString('ascii')); // outputs: abcdefghijklmnopqrstuvwxyz
console.log( buf.toString('ascii',0,5)); // outputs: abcde
console.log( buf.toString('utf8',0,5)); // outputs: abcde
console.log( buf.toString(undefined,0,5)); // encoding defaults to 'utf8', outputs abcde
এটি সঠিকভাবে সম্পাদিত হলে তা যে ফলাফল দেখাবে তা হল,
abcdefghijklmnopqrstuvwxyz
abcde
abcde
abcde
বাফার থেকে জেএসওএনে রূপান্তরের সিনট্যাক্স,
buf.toJSON()
এটির উদাহরণ,
var buf = new Buffer('Simply Easy Learning');
var json = buf.toJSON(buf);
console.log(json);
এটি সঠিকভাবে সম্পাদিত হলে তা যে ফলাফল দেখাবে তা হল,
[ 83, 105, 109, 112, 108, 121, 32, 69, 97, 115, 121, 32, 76, 101, 97, 114, 110, 105, 110, 103 ]
কনকাটেনাট বাফারঃ কনকাটেনাট নড বাফার থেকে সিঙ্গেল নড বাফারে রূপান্তর করার সিনট্যাক্স,
Buffer.concat(list[, totalLength])
এর প্যারামিটারগুলো হল,
- লিস্ট
- টোটাললেন্থ
রিটার্ন ভ্যালুঃ বাফার ইন্সটেন্স রিটার্ন করায়।
উদাহরণ,
var buffer1 = new Buffer('TutorialsPoint ');
var buffer2 = new Buffer('Simply Easy Learning');
var buffer3 = Buffer.concat([buffer1,buffer2]);
console.log("buffer3 content: " + buffer3.toString());
এটি সঠিকভাবে সম্পাদিত হলে তা যে ফলাফল দেখাবে তা হল,
buffer3 content: TutorialsPoint Simply Easy Learning
বাফার তুলনাঃ এর জন্য ব্যবহৃত সিনট্যাক্স,
buf.compare(otherBuffer);
উদাহরণ,
var buffer1 = new Buffer('ABC');
var buffer2 = new Buffer('ABCD');
var result = buffer1.compare(buffer2);
if(result < 0) {
console.log(buffer1 +" comes before " + buffer2);
}else if(result == 0){
console.log(buffer1 +" is same as " + buffer2);
}else {
console.log(buffer1 +" comes after " + buffer2);
}
এটি সঠিকভাবে সম্পাদিত হলে তা যে ফলাফল দেখাবে তা হল,
ABC comes before ABCD
বাফার কপি করাঃ এর সিনট্যাক্স হল,
buf.copy(targetBuffer[, targetStart][, sourceStart][, sourceEnd])
এর প্যারামিটারগুলো হল,
- টার্গেট বাফার
- টার্গেট স্টার্ট
- সোর্স স্টার্ট
- সোর্স এন্ড
উদাহরণ,
var buffer1 = new Buffer('ABC');
//copy a buffer
var buffer2 = new Buffer(3);
buffer1.copy(buffer2);
console.log("buffer2 content: " + buffer2.toString());
সঠিকভাবে সম্পাদিত হলে এটি ফলাফল দেখাবে,
buffer2 content: ABC
স্লাইস বাফারঃ এর সিনট্যাক্স হল,
buf.slice([start][, end])
প্যারামিটারঃ এর প্যারামিটার কোল,
- স্টার্ট
- এন্ড
উদাহরণ,
var buffer1 = new Buffer('TutorialsPoint');
//slicing a buffer
var buffer2 = buffer1.slice(0,9);
console.log("buffer2 content: " + buffer2.toString());
সঠিকভাবে সম্পাদিত হলে এটি ফলাফল দেখাবে,
buffer2 content: Tutorials
বাফার লেন্থঃ এর জন্য আমাদের যে সিনট্যাক্স ব্যবহার করতে হবে তা হল,
buf.length;
উদাহরণ,
var buffer = new Buffer(‘TutorialsPoint’);
//length of the buffer
console.log(“buffer length: ” + buffer.length);
সঠিকভাবে সম্পাদিত হলে এটি ফলাফল দেখাবে,
buffer length: 14
রেফারেন্স
নড জেএসে প্রাপ্ত বাফার মডিউলের রেফারেন্স নিচে দেয়া হল,
SN মেথড
- new Buffer(size)
- new Buffer(buffer)
- new Buffer(str[, encoding])
- buf.length
- buf.write(string[, offset][, length][, encoding])
- buf.writeUIntLE(value, offset, byteLength[, noAssert])
- buf.writeUIntBE(value, offset, byteLength[, noAssert])
- buf.writeIntLE(value, offset, byteLength[, noAssert])
- buf.writeIntBE(value, offset, byteLength[, noAssert])
- buf.readUIntLE(offset, byteLength[, noAssert])
- buf.readUIntBE(offset, byteLength[, noAssert])
- buf.readIntLE(offset, byteLength[, noAssert])
- buf.readIntBE(offset, byteLength[, noAssert])
- buf.toString([encoding][, start][, end])
- buf.toJSON()
- buf[index]
- buf.equals(otherBuffer)
- buf.compare(otherBuffer)
- buf.copy(targetBuffer[, targetStart][, sourceStart][, sourceEnd])
- buf.slice([start][, end])
- buf.readUInt8(offset[, noAssert])
- buf.readUInt16LE(offset[, noAssert])
- buf.readUInt16BE(offset[, noAssert])
- buf.readUInt32LE(offset[, noAssert])
- buf.readUInt32BE(offset[, noAssert])
- buf.readInt8(offset[, noAssert])
- buf.readInt16LE(offset[, noAssert])
- buf.readInt16BE(offset[, noAssert])
- buf.readInt32LE(offset[, noAssert])
- buf.readInt32BE(offset[, noAssert])
- buf.readFloatLE(offset[, noAssert])
- buf.readFloatBE(offset[, noAssert])
- buf.readDoubleLE(offset[, noAssert])
- buf.readDoubleBE(offset[, noAssert])
- buf.writeUInt8(value, offset[, noAssert])
- buf.writeUInt16LE(value, offset[, noAssert])
- buf.writeUInt16BE(value, offset[, noAssert])
- buf.writeUInt32LE(value, offset[, noAssert])
- buf.writeUInt32BE(value, offset[, noAssert])
- buf.writeInt8(value, offset[, noAssert])
- buf.writeInt16LE(value, offset[, noAssert])
- buf.writeInt16BE(value, offset[, noAssert])
- buf.writeInt32LE(value, offset[, noAssert])
- buf.writeInt32BE(value, offset[, noAssert])
- buf.writeFloatLE(value, offset[, noAssert])
- buf.writeFloatBE(value, offset[, noAssert])
- buf.writeDoubleLE(value, offset[, noAssert])
- buf.writeDoubleBE(value, offset[, noAssert])
- buf.fill(value[, offset][, end])
ক্লাস মেথড
SN মেথড
- Buffer.isEncoding(encoding)
- Buffer.isBuffer(obj)
- Buffer.byteLength(string[, encoding])
- Buffer.concat(list[, totalLength])
- Buffer.compare(buf1, buf2)
Jul 27
Print minimum, maximum, and sum of the valarray
/* The following code example is taken from the book
* "The C++ Standard Library - A Tutorial and Reference"
* by Nicolai M. Josuttis, Addison-Wesley, 1999
*
* (C) Copyright Nicolai M. Josuttis 1999.
* Permission to copy, use, modify, sell and distribute this software
* is granted provided this copyright notice appears in all copies.
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*/
#include <iostream>
#include <valarray>
using namespace std;
// print valarray
template <class T>
void printValarray (const valarray<T>& va)
{
for (int i=0; i<va.size(); i++) {
cout << va[i] << ' ';
}
cout << endl;
}
int main()
{
// define two valarrays with ten elements
valarray<double> va1(10), va2(10);
// assign values 0.0, 1.1, up to 9.9 to the first valarray
for (int i=0; i<10; i++) {
va1[i] = i * 1.1;
}
// assign -1 to all elements of the second valarray
va2 = -1;
// print both valarrays
printValarray(va1);
printValarray(va2);
// print minimum, maximum, and sum of the first valarray
cout << "min(): " << va1.min() << endl;
cout << "max(): " << va1.max() << endl;
cout << "sum(): " << va1.sum() << endl;
// assign values of the first to the second valarray
va2 = va1;
// remove all elements of the first valarray
va1.resize(0);
// print both valarrays again
printValarray(va1);
printValarray(va2);
}
/*
0 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
min(): 0
max(): 9.9
sum(): 49.5
0 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9
*/
Jul 27
valarray slice
/* The following code example is taken from the book * “The C++ Standard Library – A Tutorial and Reference” * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in all copies. * This software is provided “as is” without express or implied * warranty, and with no claim as to its suitability for any purpose. */
#include <iostream>
#include <valarray>
using namespace std;
// print valarray line-by-line
template<class T>
void printValarray (const valarray<T>& va, int num)
{
for (int i=0; i<va.size()/num; ++i) {
for (int j=0; j<num; ++j) {
cout << va[i*num+j] << ' ';
}
cout << endl;
}
cout << endl;
}
int main()
{
/* valarray with 12 elements
* - four rows
* - three columns
*/
valarray<double> va(12);
// fill valarray with values
for (int i=0; i<12; i++) {
va[i] = i;
}
printValarray (va, 3);
// first column = second column raised to the third column va[slice(0,4,3)] = pow (valarray<double>(va[slice(1,4,3)]), valarray<double>(va[slice(2,4,3)])); printValarray (va, 3); // create valarray with three times the third element of va valarray<double> vb(va[slice(2,4,0)]);
// multiply the third column by the elements of vb va[slice(2,4,3)] *= vb; printValarray (va, 3); // print the square root of the elements in the second row //printValarray (sqrt(valarray<double>(va[slice(3,3,1)])));
// double the elements in the third row va[slice(2,4,3)] = valarray<double>(va[slice(2,4,3)]) * 2.0;
printValarray (va, 3); }
/*
0 1 2 3 4 5 6 7 8 9 10 11
1 1 2 1024 4 5 5.7648e+006 7 8 1e+011 10 11
1 1 4 1024 4 10 5.7648e+006 7 16 1e+011 10 22
1 1 8 1024 4 20 5.7648e+006 7 32 1e+011 10 44
*/
Jul 27
Call member function for each element in vector
/* The following code example is taken from the book * "The C++ Standard Library - A Tutorial and Reference" * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in all copies. * This software is provided "as is" without express or implied * warranty, and with no claim as to its suitability for any purpose. */ //#define mem_fun1 mem_fun #include <iostream> #include <vector> #include <string> #include <algorithm> #include <functional>
class Person {
private:
std::string name;
public:
//...
void print () const {
std::cout << name << std::endl;
}
void printWithPrefix (std::string prefix) const {
std::cout << prefix << name << std::endl;
}
};
void foo (const std::vector<Person>& coll)
{
using std::for_each;
using std::bind2nd;
using std::mem_fun_ref;
// call member function print() for each element for_each (coll.begin(), coll.end(), mem_fun_ref(&Person::print));
// call member function printWithPrefix() for each element // - "person: " is passed as an argument to the member function
for_each (coll.begin(), coll.end(),bind2nd(mem_fun_ref(&Person::printWithPrefix),"person: ")); }
void ptrfoo (const std::vector<Person*>& coll) // ^^^ pointer !
{
using std::for_each;
using std::bind2nd;
using std::mem_fun;
// call member function print() for each referred object for_each (coll.begin(), coll.end(),
mem_fun(&Person::print));
// call member function printWithPrefix() for each referred object // - "person: " is passed as an argument to the member function
for_each (coll.begin(), coll.end(),bind2nd(mem_fun(&Person::printWithPrefix),"person: "));
}
int main()
{
std::vector<Person> coll(5); foo(coll); std::vector<Person*> coll2; coll2.push_back(new Person); ptrfoo(coll2); } /*
person: person: person: person: person: person: */
Jul 27
Use bitset with enum together
/* The following code example is taken from the book
* "The C++ Standard Library - A Tutorial and Reference"
* by Nicolai M. Josuttis, Addison-Wesley, 1999
*
* (C) Copyright Nicolai M. Josuttis 1999.
* Permission to copy, use, modify, sell and distribute this software
* is granted provided this copyright notice appears in all copies.
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*/
#include <bitset>
#include <iostream>
using namespace std;
int main()
{
/* enumeration type for the bits
* - each bit represents a color
*/
enum Color { red, yellow, green, blue, white, black, //...,
numColors };
// create bitset for all bits/colors
bitset<numColors> usedColors;
// set bits for two colors
usedColors.set(red);
usedColors.set(blue);
// print some bitset data
cout << "bitfield of used colors: " << usedColors
<< endl;
cout << "number of used colors: " << usedColors.count()
<< endl;
cout << "bitfield of unused colors: " << ~usedColors
<< endl;
// if any color is used
if (usedColors.any()) {
// loop over all colors
for (int c = 0; c < numColors; ++c) {
// if the actual color is used
if (usedColors[(Color)c]) {
//...
}
}
}
}
/*
bitfield of used colors: 001001
number of used colors: 2
bitfield of unused colors: 110110
*/
