Skip to content

Instantly share code, notes, and snippets.

View sibu-github's full-sized avatar

Sibaprasad Maiti sibu-github

  • http://thetaonelab.com/
View GitHub Profile
@sibu-github
sibu-github / index.html
Created October 23, 2018 14:26
HTTP/2 test
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test HTTP2 Protocol</title>
<link rel="stylesheet" href="style.css">
<script src="scripts/d3.js"></script>
@sibu-github
sibu-github / index.js
Last active October 23, 2018 15:02
http2-test
const HTTPS_PORT = 3000;
const HTTP2_PORT = 3001;
/**
* create an http2 server
*/
const http2 = require("http2");
// read and send file content in the stream
const sendFile = (stream, fileName) => {
@sibu-github
sibu-github / .eslintrc.json
Last active January 12, 2019 18:31
eslint configuration for js project
{
"extends": "airbnb",
"parser": "babel-eslint",
"plugins": ["react", "jsx-a11y", "import"],
"env": {
"browser": true,
"jest": true,
"node": true
},
"settings": {
@sibu-github
sibu-github / fetchAPI.js
Created January 14, 2019 14:16
A common function which can handle all fetch calls with proper error handling
/**
* Common fetchAPI which can handle GET and POST method
* Content-Type is set to 'application/json'
* payload should be in JSON format
*/
export async function fetchAPI(url, data, method = 'POST') {
// raise an error if url is missig
if (!url) {
throw new Error('url is missing');
}
@sibu-github
sibu-github / convertToCamelCase.js
Last active February 7, 2019 01:16
convert a JSON keys to camel case
// convert a key string to camelcase
function toCamelCase(str) {
// when str is not define reuturn
if (!str) {
return str;
}
let letters = str.split("");
let idx = letters.indexOf("_");
while (idx > -1) {
@sibu-github
sibu-github / main.go
Created September 15, 2019 15:32
http basic authentication with gin-gonic/gin library
package main
import (
"encoding/base64"
"fmt"
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
@sibu-github
sibu-github / lib.rs
Created January 6, 2022 14:25
Function for Modular exponentiation. Modular exponentiation is the remainder when an integer b (the base) is raised to the power e (the exponent), and divided by a positive integer m (the modulus); that is, c = be mod m. From the definition of division, it follows that 0 ≤ c < m.
fn modPow(base: u64, exponent: u64, modulus: u64) -> u64 {
if m == 1 {
return 0;
}
let mut r = 1;
let mut pow = exponent;
let mut num = base % modulus;
loop {
if pow == 0 {
break;
@sibu-github
sibu-github / fibonacci.rs
Created March 31, 2022 19:24
Get nth Fibonacci number in Rust
fn fibonacci(term: u64) -> u64 {
let (_, tot) = (0..=term).fold((0_u64, 1_u64), |acc, t| {
match t {
0 => (0_u64, 0_u64),
1 => (0, 1_u64),
2 => (1, 1_u64),
_ => {
let (prev, tot) = acc;
(tot, tot + prev)
@sibu-github
sibu-github / main.rs
Created April 12, 2022 11:48
URL Parse
// URL Parser
#![allow(dead_code, unused_imports)]
use std::io;
use std::num::ParseIntError;
use std::str::FromStr;
#[derive(Debug, PartialEq, Eq)]
enum CustomError {
@sibu-github
sibu-github / main.rs
Created April 13, 2022 03:47
Compress & decompress tarball
use flate2::read::GzDecoder;
use flate2::write::GzEncoder;
use flate2::Compression;
use std::fs::File;
use tar::Archive;
const TEST_DIR: &str = "test";
const TAR_FILE_NM: &str = "test.tar.gz";
// compress input directory into a _.tar.gz file