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 / psql.md
Last active August 29, 2015 13:56
PSQL commands

#PSQL Commands

To dump data

schema + data

pg_dump -U dbUser --column-inserts --table=tableName

only schema

pg_dump -U dbUser --schema-only --table=tableName

only data

pg_dump -U dbUser --data-only --column-inserts --table=tableName

@pmgupte
pmgupte / whitespaces_replace
Created September 12, 2014 08:36
Replace multiple (2+) whitespaces with single space
string = string.replace(/\s+/g, ' ');
@pmgupte
pmgupte / sites.geojson
Last active August 29, 2015 14:06
some sites and their server locations
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pmgupte
pmgupte / sublime_text_2_trim_whitespaces.md
Last active August 29, 2015 14:07
Sublime Text 2: Trim trailing white spaces on save

Go to SublimeText 2 > Preferences > User Settings. This should open your User Settings as a JSON file. Add the following to your file:

"trim_trailing_white_space_on_save": true

@pmgupte
pmgupte / xml_to_array.php
Last active August 29, 2015 14:20
PHP one-liner to convert XML into Array
<?php
$arr = json_decode(json_encode(simplexml_load_string($xml, null, LIBXML_NOCDATA)), true);
?>
@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);
?>
# 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;