Skip to content

Instantly share code, notes, and snippets.

View moshiurse's full-sized avatar
🎯
Focusing

Moshiur Rahman moshiurse

🎯
Focusing
View GitHub Profile
@moshiurse
moshiurse / AddingDates.js
Last active December 11, 2019 15:54
add days to date in javascript
Date.prototype.addDays = function (days) {
return new Date(this.valueOf() + days * 864e5);
}
var date = new Date("2019-10-01");
date.addDays(50);
// Or
@moshiurse
moshiurse / FormValidWithCallback.php
Created December 30, 2019 09:57
Codeignitter form validation with Callback function
public function check_unique() {
$conf_group = $this->input->post('conf_group');
$label = $this->input->post('label');
$code = strtolower(str_replace(' ', '_', $label));
$this->db->select('code');
$this->db->from('acc_meta_conf');
$this->db->where('code', $code);
$this->db->where('conf_group', $conf_group);
$query = $this->db->get();
@moshiurse
moshiurse / AddMultiDimensionalArray.js
Created January 5, 2020 08:49
Add Data to multidimensional array
for (var i = 0; i < rows.length; i++) {
item_id[i] = rows[i].book_id;
item_name[i] = rows[i].bookname;
item_quantity[i] = rows[i].item_quantity;
item_rate[i] = rows[i].item_rate;
item_price[i] = rows[i].itemcost;
strickerArray.push({'id': item_id[i], 'name': item_name[i], 'price': item_rate[i]});
}
@moshiurse
moshiurse / WeeklyTransaction.sql
Created January 6, 2020 10:59
Get top Bills from by week days
SELECT DAYNAME(inv_date+1), SUM(`total_cost`), COUNT(*) FROM `sales_invoice`
GROUP BY DAYNAME(inv_date)
ORDER BY SUM(`total_cost`) DESC
@moshiurse
moshiurse / RemainingDate.js
Created January 27, 2020 14:05
Get Remaining date
var rem = new Date('2020-05-05') - new Date();
var days = Math.floor(rem / 86400000);
var hour = Math.floor((rem % 86400000)/3600000);
var min = Math.floor(((rem % 86400000) % 3600000) / 60000);
var second = Math.round((((rem % 86400000) % 3600000) / 60000)/1000);
var remaining = days + ' days ' + hour + ' hour ' + min + ' Minute ' + second + ' second.';
function unitConverter(value, precession, lvl1, lvl2){
var level1,level2,level3, rem, formatedUnit;
if(lvl1 && lvl1 > 0){
level3 = value % lvl1;
rem = parseInt(value /lvl1);
formatedUnit = rem + "-"+ level3;
}else{
<?php
function unit_converter($value, $precession, $lvl1, $lvl2){
$level1 = "";
$level2 = "";
$level3 = "";
$rem = "";
$formatedUnit = "";
if($lvl1 && $lvl1 > 0){
DELIMITER $$
DROP FUNCTION IF EXISTS `unit_conversion`$$
CREATE FUNCTION `unit_conversion`(value_to_convert DECIMAL(10,2), precission INT, au_lbl_1 INT, au_lbl_2 INT)
RETURNS VARCHAR(50) CHARSET utf8 COLLATE utf8_unicode_ci
DETERMINISTIC
BEGIN
DECLARE level1 VARCHAR(10);
DECLARE level2 VARCHAR(10);
@moshiurse
moshiurse / convertJsonObjectToArray.js
Created February 12, 2020 07:07
Get data from request and converting to array using key value
var url1 = "<?php echo base_url('issue/UnitDemandController/subdepotWiseStoreOrg') . '/'; ?>" + orgID + '/' + vocab_id;
$.ajax({
url: url1,
type:'post',
datatype:'json',
async: false,// without it array cannot process on time
success: function(result){
var i=0;
JSON.parse(result).map(item => {
@moshiurse
moshiurse / FileConvertBase64.js
Created March 16, 2020 05:55
Convert any file to base64 in JS
$(document).ready(function (){
function getBase64File (file){
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
console.log(reader.result);
};
reader.onerror = function (error) {