Skip to content

Instantly share code, notes, and snippets.

🐳
Working from home

Oshan Wisumperuma oshanz

🐳
Working from home
Block or report user

Report or block oshanz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View php file
if (!is_dir('uploads/')) {
mkdir('./uploads/', 0777, TRUE);
}
$fopen = fopen('./uploads/' . $date_time . '-' . $date . '.json', "w+");
$fwrite = fwrite($fopen, $_REQUEST['jsonString']);
@oshanz
oshanz / php mysql speed insert
Last active Aug 29, 2015
php mysql speed insert
View php mysql speed insert
$userData = array();
foreach ($userList as $user) {
$userData[] = '("' . $user['first_name'] . '", "' . $user['last_name'] . '")';
}
$query = 'INSERT INTO users (first_name,last_name) VALUES' . implode(',', $userData);
==========>>>>>>>>
INSERT INTO users (first_name,last_name) VALUES("John", "Doe"),("Jane", "Doe")...
//////////////////////////////////////////////////
View php get ip
function getUserIpAddr() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { //if from shared
return $_SERVER['HTTP_CLIENT_IP'];
} else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //if from a proxy
return $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
return $_SERVER['REMOTE_ADDR'];
}
}
View validate insert
public function placeStockProduct($dataArray) {
print_r($dataArray);
$count = $dataArray['count2'];
$sql = "INSERT INTO `outlet_stock_check` (`outlet_name`, `outlet_id`, `product_name`, `product_id`, `qty`) VALUES ";
$do = FALSE;
for ($index = 0; $index < $count; $index++) {
if (isset($dataArray['product_name_' . $index]) && !empty($dataArray['product_qty_' . $index])) {
$sql.="('', '', '" . $dataArray['product_name_' . $index] . "', ''," . $dataArray['product_qty_' . $index] . ")";
if (!$do) {
$do = TRUE;
View mysql tip
cast(field as decimal(14, 2)) as formatted
@oshanz
oshanz / mysql date
Last active Aug 29, 2015
mysql date
View mysql date
date_format(now(), '%Y-%m-01') AND LAST_DAY(curdate())
SELECT
DATE_SUB(DATE_FORMAT(NOW(),'%Y-%m-%d'),INTERVAL 1 DAY) AS GetLastDay,
DATE_FORMAT(NOW(),'%Y-%m-%d') AS GetTodaysDate,
DATE_ADD(DATE_FORMAT(NOW(),'%Y-%m-%d'),INTERVAL 7 DAY) AS Add7DaysFromTodaysDate,
DATE_SUB(DATE_FORMAT(NOW(),'%Y-%m-%d'),INTERVAL 7 DAY) AS Substract7DaysFromTodaysDate,
DATE_ADD(DATE_FORMAT(NOW(),'%Y-%m-%d'),INTERVAL 1 MONTH) AS Add1MonthFromTodaysDate,
@oshanz
oshanz / mapsearch view
Last active Aug 29, 2015
island report
View mapsearch view
//https://drive.google.com/file/d/0B-zS4yAhFGgEYTZzeVJlTkVmUlk/edit?usp=sharing
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
@oshanz
oshanz / js
Created Feb 6, 2014
jquery month year only
View js
$(function() {
$('#from_date_txt').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
maxDate: 0,
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
View gist:9038832
var product_Name_id = $j('#product_Name_1 option:selected').attr("id");
var product_Name = $j('#product_Name_1 option:selected').text();
View check
$('input:checkbox').prop('checked', false);
$("input[name=type]:checked").val()
You can’t perform that action at this time.