Skip to content

Instantly share code, notes, and snippets.

@ManishLSN
ManishLSN / for vishal file
Created December 8, 2016 07:06
this is just a testing gist
<pre>
<?php
$origarray1 = array(2.4, 2.6, 3.5);
$origarray2 = array(2.4, 2.6, 3.5);
print_r(array_map('floor', $origarray1)); // $origarray1 stays the same
// changes $origarray2
array_walk($origarray2, function (&$v, $k) { $v = floor($v); });
@ManishLSN
ManishLSN / db-connect-test.php
Created February 8, 2017 11:06 — forked from chales/db-connect-test.php
Script for a quick PHP MySQL DB connection test.
<?php
# Fill our vars and run on cli
# $ php -f db-connect-test.php
$dbname = 'name';
$dbuser = 'user';
$dbpass = 'pass';
$dbhost = 'host';
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
<?php
function processURL($url){
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2
));
@ManishLSN
ManishLSN / node-and-npm-in-30-seconds.sh
Created May 3, 2017 12:27 — forked from isaacs/node-and-npm-in-30-seconds.sh
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@ManishLSN
ManishLSN / saveIPandReferer.php
Created July 12, 2017 09:19
Save IP address and referrer of our page Let's suppose we want to record the IP address and Referrer of all visitors to our page. The script bellow may be placed within the code of our page and it will create two files to store both data: "ips_file.txt" to store IP addresses and "ref_file.txt" to store referrers. Additionally, this script may be…
<?
// save ip
$ip=$_SERVER["REMOTE_ADDR"];
if ($ip!=""){
$ipfile= "ips_file.txt";
$allips = file_get_contents ($ipfile);
if (strpos($allips," $ip ")>0){
$allips = preg_replace ("/ $ip /"," $ip x",$allips);
$tempvar= fopen($ipfile, "w");
fwrite ($tempvar, $allips);
@ManishLSN
ManishLSN / curlBackground.php
Created July 13, 2017 06:39
curl in backgroupd by php
<?php
$request = array("abc"=> $abcd, "adsf"=> $asdf, "duration" => $duration, "callback_url"=>$callBackUrl);
// echo "<pre>"; print_r($request); die;
$json = json_encode($request);
$ch = curl_init(HUB_MEDIA_SERVER_TEXT2VIDEO.'phpfile.php');
// $ch = curl_init(HUB_MEDIA_SERVER_TEXT2VIDEO.'textToVideoDev.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
@ManishLSN
ManishLSN / indiaMap.c
Created August 1, 2017 12:28
make india map by c language code
#include <stdio.h>
int main()
{
int a = 10, b = 0, c = 10;
char* str = "TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq "
"TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBL"
"OFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm "
"SOn TNn ULo0ULo#ULo-WHq!WFs XDt!";
while (a != 0)
{
@ManishLSN
ManishLSN / replace_str_inFile.php
Created September 11, 2017 13:41
replace text in a file.
<?php
function replace_in_file($FilePath, $OldText, $NewText)
{
$Result = array('status' => 'error', 'message' => '');
if(file_exists($FilePath)===TRUE)
{
if(is_writeable($FilePath))
{
try
{
@ManishLSN
ManishLSN / postgres-cheatsheet.md
Created September 15, 2017 06:21 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@ManishLSN
ManishLSN / getDistance.php
Created November 13, 2017 14:50
get the distance from two geo location point
<?php
// $details = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=Seattle&destinations=San+Francisco&mode=driving&sensor=false";
//you can also pass latitude/longitude values in origins
// $details = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=41.43206,-81.38992&destinations=San+Francisco&mode=driving&sensor=false";
// $details = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=indore+mp&destinations=dewas+mp&mode=driving&sensor=false";
$details = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=22.720816,75.874925&destinations=22.721786,75.878326&mode=driving&sensor=false";