Skip to content

Instantly share code, notes, and snippets.

@ritwickdey
ritwickdey / withCORS.js
Last active December 27, 2018 06:21
CORS Middleware (Higher Order Function) for firebase function // Just Nice Syntax
//For firebase funtion.
/*
Usage:
exports.foo = functions.https.onRequest(withCORS((req, res) => {
res.send("Hello World");
});
*/
@ritwickdey
ritwickdey / cors.js
Last active November 21, 2018 06:14
CORS Setup for Node.js
const express = require('express');
const app = express();
//CORS Setup
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*'); // Allowed Origins.
res.header('Access-Control-Allow-Headers', '*'); // Allowed Headers.
res.header('Access-Control-Expose-Headers', 'token'); // Exposed Headers - means client only can access those headers.
if (req.method === 'OPTIONS') {
@ritwickdey
ritwickdey / GetRandomColorWithRandomOpacity.js
Last active August 6, 2018 09:30
Get Random Color with Random Opacity (Useful for Charts)
const hexColors = [
'#3366CC',
'#DC3912',
'#FF9900',
'#109618',
'#990099',
'#3B3EAC',
'#0099C6',
'#DD4477',
'#66AA00',
@ritwickdey
ritwickdey / ExampleOfDependencyInjection.cs
Last active January 10, 2018 10:42
Example Of Dependency Injection in C#. (BTW, I'm not 100% sure :p )
namespace SomeNamespace
{
public interface ITest
{
void hello();
}
//NO Singleton Class, Simple One.
public class Test1 : ITest
{
@ritwickdey
ritwickdey / gist:72c3e68a2366b57188a50b1a552c4190
Created December 21, 2017 11:05 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@ritwickdey
ritwickdey / Sorts.c
Last active November 29, 2017 07:02
Few Sorts in one place : Bubble Sort, Selection Sort, Insertion Sort, Marge Sort, Quick Sort, Heap Sort
/*
---------------------
Bubble Sort,
Selection Sort,
Insertion Sort,
Marge Sort,
Quick Sort,
Heap Sort
----------------------
*/
@ritwickdey
ritwickdey / Fractional_Knapsack.c
Created November 28, 2017 16:47
Fractional Knapsack (Greedy Approach) is implemented with C language
#include <stdio.h>
#include <stdlib.h>
typedef struct Item
{
int itemId;
int weight;
int profit;
float pByw; // profit/weight
float xi;
@ritwickdey
ritwickdey / JobScheduling.c
Created November 28, 2017 15:48
JobScheduling Algorithm (Greedy Approach) implemented with C
#include <stdio.h>
#include <stdlib.h>
typedef struct job
{
int id;
int deadLine;
float profit;
int isPossible;
} job;
@ritwickdey
ritwickdey / AppletDemo.java
Last active November 25, 2017 03:41
Everything in one place - Applet Life Cycle, Parameter Passing ,Drawing, ButtonEvent, MouseEvent & DialogBox
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
<applet code="AppletDemo" width="320" height="320">
<param name="myName" value="ritwick dey"/>
</applet>
*/
function fun1() {
setTimeout(function () { //normal
console.log("normal (setTimeOut)", this);
}, 0);
}
function fun2() {
setTimeout(() => { //arrow
console.log("arrow (setTimeOut)", this);
}, 0);