Skip to content

Instantly share code, notes, and snippets.

View pmgupte's full-sized avatar
🏠
Working from home 👨‍💻

Prabhas Gupte pmgupte

🏠
Working from home 👨‍💻
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 / project-euler-01.php
Last active December 22, 2015 03:19
My PHP solution to Project Euler problem # 1 http://projecteuler.net/problem=1 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
<?php
$sum = 0;
for ($i = 0; $i < 1000; $i++) {
if (!($i % 3) || !($i % 5)) {
$sum += $i;
}
}
echo $sum;
?>
@pmgupte
pmgupte / project-euler-02-sol-2.php
Last active December 22, 2015 03:29
My PHP solution to Project Euler problem # 2 - http://projecteuler.net/problem=2 - Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not exceed four m…
<?php
$n1 = 1;
$n2 = 1;
$n3 = $n1 + $n2;
$sum = 0;
while($n3 < 4000000) {
$sum += $n3;
$n1 = $n2 + $n3;
$n2 = $n1 + $n3;
$n3 = $n1 + $n2;