Skip to content

Instantly share code, notes, and snippets.

@jyotendra
jyotendra / apiHandler.ts
Created June 21, 2018 13:10
This function can be used to get files from angular observable
import { HttpClient, HttpHeaders, HttpParams } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { TokenManager } from "@app/shared/services/token-manager.service";
@Injectable()
export class ApiHandler {
constructor(private http: HttpClient) {}
apiGet(url, params?, extras?: Extras) {
let options = this.renderHeaders(extras);
@jyotendra
jyotendra / tslint.json
Created June 27, 2018 07:03
tslint for react with unnecessary rules overridden
{
"extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
"linterOptions": {
"exclude": [
"config/**/*.js",
"node_modules/**/*.ts"
]
},
"rules": {
"arrow-return-shorthand": true,
@jyotendra
jyotendra / app.tsx
Created June 27, 2018 10:09
Using observables in react app
import * as React from "react";
import { httpGet } from "./service";
import "./App.css";
import logo from "./logo.svg";
class App extends React.Component {
constructor({}) {
super({}, null);
httpGet("http://abc.com/api/location/country").subscribe({
@jyotendra
jyotendra / Program.cs
Created June 28, 2018 09:50
Super simple delegate and event
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Yo Buddy");
Subscriber myEventSubscriber = new Subscriber();
@jyotendra
jyotendra / sorter.sql
Created July 14, 2018 11:38
Usage of case statement to flag user_type and sort datasets
SELECT
*
FROM
(
SELECT
USER.id AS fetched_id,
USER.country_code,
USER.mobile,
USER.email,
user_profile.name,
@jyotendra
jyotendra / countries.json
Created July 23, 2018 13:55
This gist shows how to import json asynchronously in nodejs
[
[1, "Afghanistan", "AF", 93, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[2, "Albania", "AL", 355, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[3, "Algeria", "DZ", 213, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[4, "American Samoa", "AS", 1684, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[5, "Andorra", "AD", 376, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[6, "Angola", "AO", 244, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[7, "Anguilla", "AI", 1264, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[8, "Antarctica", "AQ", 0, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
[9, "Antigua And Barbuda", "AG", 1268, "0000-00-00 00:00:00", "0000-00-00 00:00:00"],
@jyotendra
jyotendra / chained.js
Last active August 14, 2018 09:06
Method chaining in classes in javascript
class BotResponseFormatter {
formattedResponse;
constructor(botInterpretation) {
this.formattedResponse = botInterpretation;
}
/**
*
* @param {string} replyType possible options are 'text', 'option'
*/
@jyotendra
jyotendra / client.js
Last active August 17, 2018 10:47
socket connection with middleware in node and angular
constructor() {
this.chats = [];
this.socket = io.connect(
baseUrl,
{
path: "/chat",
query: { "access-token": "---=====" },
reconnection: false
}
);
@jyotendra
jyotendra / ReadMe.md
Last active September 8, 2018 07:37
Implementing throttling on button click

Why throttling is important ?

Throttling enables you to disable input from an stream for a certain period of time, after first event. Example: You might want to call a submit button once - even after multiple clicks by a user. Or you might only want to call an api once after several keystrokes by user - as is case with "type as you search". Limiting API call on every user interaction saves you server side resources and also enhance user experience.

What you can do ?

You can either disable the button or field from taking in more user inputs. But that's not elegant.

Much elegant way .....

@jyotendra
jyotendra / intro.md
Last active November 28, 2018 11:57
Azure Identity Service - Notes

Can Azure AD be used for social login ?

Came to understand that for user authentication via social login - Azure AD is not appropriate. Its more for organizing employees in premises and to provide them access to apps. It also provides SSO capabilities for employees under organization structure.

Azure AD can be used for customer facing websites but then they will be restricted to sign-in by using work-mail or at the very best by using microsoft account (outlook, live etc).

Azure AD does not provide social login feature. However, Azure AD B2C address this exact scenario.

Azure AD B2C uses OpenId Connect protocol