Friday, March 30, 2018

jquery select first x number of elements | Selecting the first “n” items with jQuery

Quick jQuery snippet to select first x number of elements. You can also use the jQuery .slice() function which can chop up element groups into a range for you with a combination of .get();
$("a").slice(0,20)
lso you can use lt pseudo selector: This matches the elements before the nth one (the nth element excluded). Numbering starts from 0
$(“a:lt(n)”)
Because :lt() is a jQuery extension and not part of the CSS specification, queries using :lt() cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. For better performance in modern browsers, use $("your-pure-css-selector").slice(0, index) instead

What's the best way to retry an AJAX request on failure using jQuery | The best way to retry an AJAX request on failure using jQuery | jQuery AJAX retry

$.ajax({
    url: 'http://',
    type: 'POST',
    data: {},
    tryCount: 0,
    retryLimit: 3,
    success: function (response) {
        //do something
    },
    error: function (xhr, textStatus, errorThrown) {
        this.tryCount++;
        if (this.tryCount <= this.retryLimit) {
            //try again
            $.ajax(this);
            return;
        }
        if (xhr.status == 500) {
            //handle error
        }
        else {
            //handle error
        }
    }
});

Thursday, March 15, 2018

Convert 1 Satak to Square Feet ( sq ft ) easily

Convert 1 Satak to Square Feet ( sq ft ) easily

This conversion calculator is very easy to find Satak to Square Feet. This measurement may separate from place to place. Satak is a Bangla word, so the people spell it different way in English. Someone also says shotok, sotok, sotangso, shotangsho etc. I think the following list of area conversion's will meet all your asking.
From
To
Others Area Conversion List
To Others Unit
4 Satak = 0.04 Acre
4 Satak = 1.6187441354899246 Ayer
4 Satak = 0.12100000000000001 Bigha
4 Satak = 38.72 Chotak
4 Satak = 4 Decimal
4 Satak = 1016.399999997459 Dhul
4 Satak = 145.20000000000002 Dondho
4 Satak = 2.0166666666666666 Gonda
4 Satak = 0.016187441354899246 Hectare
4 Satak = 32.266666666666666 Kak
4 Satak = 0.10083333333333334 Kani
4 Satak = 2.42 Katha
4 Satak = 24.200000000000003 Kontho
4 Satak = 8.066666666666666 Kora
4 Satak = 24.000000000000004 Kranti
4 Satak = 400.00000000000006 Ojutangsho
4 Satak = 30492.0000015246 Renu
4 Satak = 4 Satak
4 Satak = 4 Shotangsho
4 Satak = 0.4 Square Chain
4 Satak = 1742.4 Square Feet
4 Satak = 774.4000000000001 Square Hat
4 Satak = 250905.7605796868 Square Inchi
4 Satak = 161.8744135489925 Square Meter
4 Satak = 193.60000000000002 Square Yard
4 Satak = 480.00000000000006 Til

Sunday, February 11, 2018

git: Your branch and 'origin/master' have diverged - how to throw away local commits

I have the following message in git:

# Your branch and 'origin/master' have diverged,
# and have 3 and 8 different commits each, respectively.
# (use "git pull" to merge the remote branch into yours)
I would like to throw away the 3 local commits, and pull the 8 remote commits at origin/master.

(Merging is going to be too difficult, I'd rather make the 3 local commits again once master is up to date.)
To erase your latest local commit use the following:

git fetch origin
git reset --hard origin/master

You will get following message:
HEAD is now at 76b2d560 .......................

Saturday, January 27, 2018

How to create and download a csv file from php script | PHP : Array To CSV - Download CSV File | Creating downloadable CSV files using PHP

CSV (comma-separated values) is the most widely supported format for transferring tabular data between applications. The ability to export data in CSV format is a useful feature for many programs, and is becoming increasingly common in web applications. This page explains how to use PHP to create CSV files, and how to ensure that your visitor’s browser offers to download the file instead of displaying it.
<?php
header("Content-type:application/octet-stream");
header("Content-Disposition:attachment;filename='PHP Download as CSV.csv'");
$out = fopen('php://output', 'w');

# If you want to process static data
fputcsv($out, array("Name", "Roll"));
fputcsv($out, array("Pritom 1", "Roll 1", "Extra 1"));
fputcsv($out, array("Pritom 2", "Roll 2", "Extra 2"));

# Fetch data from MySQL
mysql_connect('localhost', 'root', '');
mysql_select_db('test');
$rows = mysql_query('SELECT * FROM t1');

// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows)) fputcsv($out, $row);

fclose($out);
In a real application the database connection parameters should be defined as constants in a separate configuration file.

Friday, January 26, 2018

How to revert a merge commit that's already pushed to remote branch | Revert a merge after being pushed | Undo a git merge that has been pushed to the server | Git HowTo: revert a commit already pushed to a remote repository

You could follow these steps to revert the incorrect commit(s) or to reset your remote branch back to correct HEAD/state
1. git checkout development
2. Use git log -5 to show latest 5 commits, which will result as below:
$ git log -5
commit 6e10182080307215e70d5d843d29ddfb302d776f (HEAD -> development, origin/development, origin/HEAD)
Author: Pritom K Mondal <pritomkucse@gmail.com>
Date:   Thu Jan 25 20:53:19 2018 +0600

    Test

commit f262e20f51171d2d24d9f15cd2abcf73a641ac43
Author: Pritom K Mondal <pritomkucse@gmail.com>
Date:   Thu Jan 25 20:52:34 2018 +0600

    Test

commit f808058d419e9d71b9f4bc27bf272241c0bf9971
Author: Pritom K Mondal Kumar <pritomkucse@gmail.com>
Date:   Thu Jan 25 14:45:54 2018 +0000

    Repository created
3. git reset f262e20f51171d2d24d9f15cd2abcf73a641ac43 (i.e. your commit number where you want to go)
4. run the git status to show all the changes that were part of the wrong commit, if you don't want to see untracked files run git status --untracked-files=no or as shortcut run git status -uno
5. simply run git reset --hard to revert all those changes
7. force-push your local branch to remote and notice that your commit history is clean as it was before it got polluted.
git push -f origin development
8. But by any chance if you need to abort reset you need to revert above reset option as git reset 'HEAD@{1}' as short answer.
9. Long answer is type git reflog and go to desired location.
$ git reflog
1123175 (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: reset: moving to HEAD
1123175 (HEAD -> master, origin/master, origin/HEAD) HEAD@{1}: reset: moving to HEAD
1123175 (HEAD -> master, origin/master, origin/HEAD) HEAD@{2}: reset: moving to 1123175d5b42a8f459aff1cd7bb59082e0087775
b1110db HEAD@{3}: merge remotes/origin/branch1: Merge made by the 'recursive' strategy.
1123175 (HEAD -> master, origin/master, origin/HEAD) HEAD@{4}: commit: Test from master
d81337f HEAD@{5}: commit: Test from master

Friday, January 12, 2018

Using Chrome's Element Inspector in Print Preview Mode | Is it possible in chrome to make the browser look like a print page | Inspect and Edit Pages and Styles As Print Mode

Open the Developer Tools (CTRL+SHIFT+I or F12)
 
Click the Customize and control DevTools hamburger menu button and choose More tools > Rendering settings (or Rendering in newer versions)
Check the Emulate print media checkbox at the Rendering tab and select the Print media type