Skip to content

Instantly share code, notes, and snippets.

View rbrahul's full-sized avatar

Rahul Baruri rbrahul

View GitHub Profile
function getSumProductPurchaseAmount($product_id){
$CI=&get_instance();
$result=$CI->db->select_sum('amount','total')->get_where('purchase',['product_id'=>$product_id])->row()->total;
return $result;
}
function getSumProductSaleAmount($product_id){
$CI=&get_instance();
myApp.config(function($stateProvider,$urlRouterProvider){
$stateProvider.state('task',
{
url:'/task',
controller:'TaskController',
views:{
"sidebar":{templateUrl:'/partial/task/taskcreateform.html'},
"content":{templateUrl:'/partial/task/taskgrid.html'}
},
@rbrahul
rbrahul / LinkedInEndoresmentScript.js
Last active March 30, 2018 20:19
Run this script in your browser console while visiting profile page of any linked user then it will automatically endorse skills :)
var endorsPlusButtons = document.querySelectorAll(".endorsable");
var index = 0;
if (endorsPlusButtons.length) {
var interval = setInterval(() => {
if (index < (endorsPlusButtons.length)) {
setTimeout((indx) => {
endorsPlusButtons[indx].querySelector(".endorse-plus").click();
}, parseInt(Math.random() * 11) * 400, index);
} else {
@rbrahul
rbrahul / findLastNodeInObject-tree.js
Last active February 5, 2017 12:54
This script finds the last child node in any tree like object implementing recursion in javascript
const data = {
first: {
second: {
user: {
name:'Rahul',
title: 'Baruri'
},
third: {
info: {
salary: 70000,
@rbrahul
rbrahul / flattenArray.js
Last active March 30, 2018 20:16
Flaten Array using javascript
var originalArray = [1, [2], [3, 4, [5, [6,7]]]];
function flatten(arr) {
var flattenarr = [];
arr.forEach(item => {
if(Array.isArray(item)) {
var arrItem = item;
while(Array.isArray(arrItem)) {
arrItem.forEach(next => {
if(Array.isArray(next)) {
@rbrahul
rbrahul / Async-Await.js
Created September 2, 2017 14:13
Async and Await example using Github Api
const fetch = require("node-fetch");
const fs = require('fs');
function getAllRepos() {
return fetch('https://api.github.com/users/rbrahul/repos');
}
function getRepoInfo(repoName) {
return fetch(`https://api.github.com/repos/rbrahul/${repoName}`);
}
@rbrahul
rbrahul / Custom-EventDispatcher.js
Last active March 30, 2018 20:15
Pretty Small Custom EventDispatcher
var EventDispatcher= function() {
this.events = {};
}
EventDispatcher.prototype.add = function(name, handler) {
if(!(name in this.events)) {
this.events[name] = [handler];
} else {
this.events[name].push(handler);
}
@rbrahul
rbrahul / OLOO-Pattern.js
Created September 3, 2017 12:39
Inheritance using Object Literal (Object Linked with Other Object ) - OLOO
Object.prototype.oloo = function(o1, o2){
if( o1 && o2 && typeof o1 === "object" && typeof o2 === "object"){
// create new object
var o0 = Object.create(o1);
// copy all props to the brand new obj
for( var key in o2 ){
if(o2.hasOwnProperty(key)){
o0[key] = o2[key];
}
}
@rbrahul
rbrahul / bengali-digit-converter.js
Last active September 7, 2017 18:14
Convert a Number to it's bengali number representation
function toBengaliNumber(number) {
var numbers = {
'1': '১',
'2': '২',
'3': '৩',
'4': '৪',
'5': '৫',
'6': '৬',
'7': '৭',
'8': '৮',
@rbrahul
rbrahul / holiday-scrapper.js
Last active March 30, 2018 20:10
Holiday Scrapper for Tanim vai :p
var holidays = [];
$(document).ready(function () {
$(".list-table").find("tbody").find("tr").each(function (index, item) {
var holiday = {};
$(item).find("td").each(function (indx, colunm) {
if (indx == 1) {
var timeTag = $(colunm).find("time");
var timeStamp;
var dateText;
if (timeTag.length) {