Skip to content

Instantly share code, notes, and snippets.

View rbrahul's full-sized avatar

Rahul Baruri rbrahul

View GitHub Profile
@rbrahul
rbrahul / curry.js
Last active May 23, 2018 16:07
Curry pattern for Functional Programming in Javascript
function curry(fn) {
let i = 0;
let countedArg = 0;
let method = function(arg) {
return arg;
};
let args = [];
while(i< fn.length) {
method = (function(fun) {
return function(...params) {
@rbrahul
rbrahul / pre-commit-eslint.sh
Created May 23, 2018 11:33
Run Eslint test before committing in git repository
#!/bin/sh
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$")
ESLINT="$(git rev-parse --show-toplevel)/node_modules/.bin/eslint"
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true
@rbrahul
rbrahul / Template-parser.js
Created April 18, 2018 22:21
Simple templating in js
const message = 'Amar nam {{name}}, amar boyos {{age}}, and {{name}} er first letter R';
function render(text, values) {
let str = text;
Object.keys(values).forEach(key => {
str = str.replace(new RegExp(`{{${key}}}`, 'g'), values[key]);
});
return str;
}
@rbrahul
rbrahul / function-composition.js
Last active May 23, 2018 11:52
Function Composition native implementation in Javascript
var students = [
{
firstName: 'Rahul',
lastName: 'Baruri',
marks: 809,
group: 'science'
},
{
firstName: 'Ripan',
lastName: 'Baruri',
@rbrahul
rbrahul / currency.go
Last active March 30, 2018 20:11
Get Currency Information using Go lang
package main
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
)
@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) {
@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 / 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 / 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 / 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}`);
}