Posts

Showing posts from 2016

How to execute a file in node js.

With a text editor, create a file called web-server.js, with the following contents: var http = require('http'); var serv = http.createServer(function (req, res) {     res.writeHead(200, { 'Content-Type': 'text/html' });     res.end('<marquee>Debug Report</marquee>'); }); serv.listen(3000); Run the file: node web-server.js

Enable debugging in Firebase Android

You can enable debugging in Firebase using following code. Firebase.getDefaultConfig().setLogLevel(Logger.Level.DEBUG);   Output will be look like following snapshot. 05-14 02:32:11.089 6645-7531/com.aybits.discoversaints.discoversaints D/PersistentConnection: pc_0 - Listening on /saints/video:{} 05-14 02:32:11.089 6645-7531/com.aybits.discoversaints.discoversaints D/PersistentConnection: pc_0 - Adding listen query: /saints/video:{} 05-14 02:32:18.001 6645-7531/com.aybits.discoversaints.discoversaints D/PersistentConnection: pc_0 - unlistening on /saints/video:{} 05-14 02:32:18.001 6645-7531/com.aybits.discoversaints.discoversaints D/PersistentConnection: pc_0 - removing query /saints/video:{} 05-14 02:32:18.002 6645-7531/com.aybits.discoversaints.discoversaints D/PersistentConnection: pc_0 - Listening on /saints/video:{} 05-14 02:32:18.002 6645-7531/com.aybits.discoversaints.discoversaints D/PersistentConnection: pc_0 - Adding listen query: /saints/video:{}

Converting Density Independent Pixels (dp) to Pixels (px) in Android

Sometimes we need to convert density independent pixels(dip/dp) to pixels to set view properties like width or height. Here how it is done using Java.     Resources r = getResources();     int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 300,       r.getDisplayMetrics());     myEditText.setWidth(px);

How to check the size of primitive data types in C++

The sizes of variables might be different depending on the compiler and the computer you are using. Following code will produce correct size of various data types on your system. #include <iostream> using namespace std; int main() {    cout << "Size of char : " << sizeof(char) << endl;    cout << "Size of int : " << sizeof(int) << endl;    cout << "Size of short int : " << sizeof(short int) << endl;    cout << "Size of long int : " << sizeof(long int) << endl;    cout << "Size of float : " << sizeof(float) << endl;    cout << "Size of double : " << sizeof(double) << endl;    cout << "Size of wchar_t : " << sizeof(wchar_t) << endl;    return 0; } Following is the sample result. Results may be differ according to your system. Size of char : 1 Size of int : 4 Size of

Vector container in C++ STL

Following code demonstrates the vector container (a C++ Standard Template) in C++. #include <iostream> #include <vector> using namespace std; int main() {    // create a vector to store int    vector<int> vec;    int i;    // display the original size of vec    cout << "vector size = " << vec.size() << endl;    // push 5 values into the vector    for(i = 0; i < 5; i++){       vec.push_back(i);    }    // display extended size of vec    cout << "extended vector size = " << vec.size() << endl;    // access 5 values from the vector    for(i = 0; i < 5; i++){       cout << "value of vec [" << i << "] = " << vec[i] << endl;    }    // use iterator to access the values    vector<int>::iterator v = vec.begin();    while( v != vec.end()) {       cout << "value of v = " << *v << endl;       v++;    }

Enable Strict Mode in Android.

StrictMode works on a set of policies. There are presently two categories of policies: VM policies and thread policies. The former represent bad coding practices that pertain to your entire application, notably leaking SQLite Cursor objects and kin. The latter represent things that are bad when performed on the main application thread, notably flash I/O and network I/O. The simplest thing to do is call the static enableDefaults() method on StrictMode from onCreate() of your first activity. import android.app.Activity; import android.os.Build; import android.os.Bundle; import android.os.StrictMode; public class FilesDemo extends Activity {     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);         if (BuildConfig.DEBUG                 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {                        StrictMode.setThreadPolicy(buildPolicy())