Skip to content

Instantly share code, notes, and snippets.

View tamalchowdhury's full-sized avatar
🔍
exploring open source

Tamal Chowdhury tamalchowdhury

🔍
exploring open source
View GitHub Profile
@tamalchowdhury
tamalchowdhury / index.js
Last active April 16, 2023 11:51
Node js backend server code from Tamal Anwar Chowdhury's Reel
const express = require("express")
const app = express()
app.get("/", function(req, res) {
res.send(`<h1>Hello World</h1>`)
})
app.listen(5000, function() {
console.log("Server is running on port 5000");
@tamalchowdhury
tamalchowdhury / app.jsx
Created May 10, 2022 08:41
Upload image in the client using Base64 strings
import { useState } from "react"
/**
* Takes a file from the file browser and
* converts into a base64 string
* Shows an alert when the file type does not match
* Function is outside so it can be portable
* @param {Blob} file
* @returns {Promise}
*/
// Fetch API
// Fetch is a built in browser API built into JavaScript.
fetch('https://example.com/api/')
.then(res => res.json())
.then(data => data)
.catch(err => err)
fetch('https://example.com/api/')
@tamalchowdhury
tamalchowdhury / widget.html
Created January 11, 2021 12:56
Show Current Year in WordPress widgets without PHP
<span id="my_date">1999</span>
<script>
var d = new Date();
document.getElementById("my_date").innerText = d.getFullYear();
</script>
@tamalchowdhury
tamalchowdhury / convert_date.py
Last active December 30, 2020 12:26
Convert date to dd-mm-yyyy with Python
# This function takes a date and converts into
# desired format dd-mm-yyyy
# Use inside a loop to make the conversion
def convert_date(dateobject):
return dateobject.strftime('%d-%m-%Y')
# Example
from datetime import datetime
@tamalchowdhury
tamalchowdhury / solution.md
Created November 26, 2020 10:14
Solution for nested comments in reddit clone

Nested comments implementation in reddit clone

I found an elegant soultion to our nested comments problems.

I found the Solution from StackOverflow:

[https://stackoverflow.com/a/36829986]

Originally, the comments will be inserted into the database one after another.

@tamalchowdhury
tamalchowdhury / index.html
Last active August 30, 2020 08:03
Update page content with data from JSON API
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
table,
th,
td {
@tamalchowdhury
tamalchowdhury / Shuffle_List.js
Last active September 4, 2019 14:49
This function takes a list items and randomizes them.
/**
* @param {array} array which is an array of items to be shuffled
* A function which returns an array of random chests like:
* ['gold', 'half', 'silver']
* or
* ['silver', 'gold', 'fifty']
*/
function shuffleArray(array) {
let output = [];
// While we still have items, keep rolling
const multerOptions = {
storege: multer.memoryStorage(),
fileFilter(req, file, next) {
const isPhoto = file.mimetype.startsWith('image/');
if(isPhoto) {
next(null, true)
} else {
next({message: 'You must supply an image'}, false)
}
}
@tamalchowdhury
tamalchowdhury / infinityGauntlet.js
Last active August 1, 2019 16:33
infinity gauntlet
const infinityGauntlet = {
powerStone: {
equipped: true,
info: 'Controls all of the power in the universe. It can be used to augment or inhibit any force.',
use() {
if(this.equipped) {
return 'Using super strength to crash the moon and throw it over to the Avengers!!';
} else {
return 'No power stone!'
}