Skip to content

Instantly share code, notes, and snippets.

View pmgupte's full-sized avatar
🤠
busy! I may be slow to respond.

Prabhas Gupte pmgupte

🤠
busy! I may be slow to respond.
View GitHub Profile
@pmgupte
pmgupte / is_last_occurance.php
Last active October 6, 2016 07:03
PHP function to check if today’s day occurs for the last time in current month.
<?php
/**
* Copyright (C) 2016 Prabhas Gupte
*
* This is free script: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This script is distributed in the hope that it will be useful,
@pmgupte
pmgupte / count_occurances.php
Last active October 6, 2016 07:03
PHP function to count how many times given day is occurring in then given month, on given date.
<?php
/**
* Copyright (C) 2016 Prabhas Gupte
*
* This is free script: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This script is distributed in the hope that it will be useful,
@pmgupte
pmgupte / smart_swap.php
Created June 17, 2013 12:07
Many of the times we face a typical question in interviews: “swap two variables without using third variable”. well, when I ask the same question while interviewing any candidate for PHP, I get the same typical answer of adding and subtracting the two variables. But when I ask them to do it with only one executable statement, they simply can’t. …
<?php
$a=10; $b=20;
list($b, $a) = array($a,$b);
?>
@pmgupte
pmgupte / week_of_month.php
Last active October 6, 2016 07:02
In my project work, I needed to find out whether the given date falls in 1st, 2nd, 3rd, 4th or 5th week of the given month. As usual, I googled for this solution and found many functions. http://www.hotscripts.com/forums/php/37900-week-number-month.html, http://stackoverflow.com/questions/5853380/php-get-number-of-week-for-month and http://mybro…
<?php
/**
* Copyright (C) 2016 Prabhas Gupte
*
* This is free script: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This script is distributed in the hope that it will be useful,
@pmgupte
pmgupte / ordinal_number.php
Last active October 6, 2016 07:02
PHP function to get ordinal number.Pass it a number and it will return the number suffixed with either of "st" (like 1st), "th" (like 4th), "nd" (like 2nd), "rd" (like 3rd).
<?php
/**
* ordinal_number.php - PHP function to get ordinal number.
* Pass it a number and it will return the number suffixed with either
* of "st" (like 1st), "th" (like 4th), "nd" (like 2nd), "rd" (like 3rd).
* Copyright (C) 2016 Prabhas Gupte
*
* This is free script: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
# to get matching line and 5 lines before that
grep -B 5 "pattern" file
# to get matching line and 5 lines after that
grep -A 5 "pattern" file
# of course, you can combine -A and -B options together in single command. That's obvious.
# if your -A and -B values are same, you need not specify both the options. use -C instead.
grep -C 5 "pattern" file
Programming Laguages
PHP - currenly my bread and butter is earned with this language only
Javascript
Ruby
Editors
Eclipse, with PDT - on ubuntu as well as windows. This is my preferred editor
vim - only when working on terminal
nodepad++ - only when working on windows
Sublime Text 2 - trying this editor on linux as well as windows
Source Code Control
@pmgupte
pmgupte / array_in_array.php
Last active December 27, 2015 15:59
PHP function to check whether all elements from one array are present in another array.
<?php
/**
* Check whether all elements from $needle array are present in $haystack array.
* Works for single-dimentional arrays only.
* If you use multi-dimentional arrays, result could be misterious.
* @param array $needle
* @param array $haystack
* @return boolean true if all elements in $needle are found in $haystack. false otherwise.
*/
function array_in_array($needle, $haystack) {
@pmgupte
pmgupte / sites.geojson
Last active August 29, 2015 14:06
some sites and their server locations
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.