Skip to content

Instantly share code, notes, and snippets.

@maxgaurav
maxgaurav / browser.ts
Last active September 22, 2023 11:59
PKCE Code Challenge and Code Verifier Generation along with verification process
// browser part
const codeVerifier = crypto.getRandomValues(new Uint8Array(128));
function toBase64(buffer: Uint8Array): string {
return btoa(String.fromCharCode(...buffer))
.replace(/=/g, '')
.replace(/\+/g, '-')
.replace(/\//g, '_')
}
import { FormControl, SyncValidator } from "universal-reactive-forms";
import { ErrorKeys } from "@/components/ErrorKeys";
/**
* Returns valid when the value is not null|undefined|empty string or when array is not empty
* @param value
* @constructor
*/
export const Required: SyncValidator = (value) => {
if (value instanceof Array) {
@maxgaurav
maxgaurav / functional-http-service.ts
Last active September 15, 2023 11:44
A Interceptor system for raw ajax on rxjs to get same functionality as in angular http client interceptor.
import { ajax, AjaxConfig, AjaxResponse } from 'rxjs/ajax';
import { from, Observable, of, OperatorFunction, switchMap } from 'rxjs';
export type BeforeInterceptors = (config: AjaxConfig) => Promise<AjaxConfig> | AjaxConfig | Observable<AjaxConfig>;
export type AfterInterceptors<T extends any = any> = (response: AjaxResponse<T>) => Observable<AjaxResponse<T>> | AjaxResponse<T> | Promise<AjaxResponse<T>>;
const BEFORE_INTERCEPTORS: BeforeInterceptors[] = [];
const AFTER_INTERCEPTORS: AfterInterceptors[] = [];
interface ConfigInterceptor {
@maxgaurav
maxgaurav / index.html
Created July 30, 2019 07:44
Random Number Dice Animation
<html>
<head>
<title>Title</title>
<style>
body {
margin: 0;
}
canvas {
width: 100%;
@maxgaurav
maxgaurav / ReflectionClassExample.php
Last active May 4, 2018 04:40
Reflection Method Example
class ABC {
protected function test()
{
echo "Will not echo from an instance for protected";
}
private function otherTest($content)
{
echo "WIll not echo from an instance for private and content is $content";
}
@maxgaurav
maxgaurav / LaravelFlashSessionHelper.php
Created October 20, 2016 05:49
Laravel Flash session helper with various types of messages
/**
* Function sets the flash message with type
* @param string $message [contains message to be displayed]
* @param string $type [contains type of message]
*/
public static function setFlashMessage ($message, $type = 'success'){
if(session()->has('flashMessages')){
$data = session('flashMessages');
}else{
$data = [
@maxgaurav
maxgaurav / laravelsetup.sh
Created July 6, 2016 11:21
Codeship laravel project testing script
#This scripts installs and setups the eviornment for laravel with database and seeding
# We support all major PHP versions. Please see our docs for a full list
# https://codeship.com/documentation/languages/php/
#setting the phpenv
phpenv local 5.6
# Install dependencies through Composer
rm -f /home/rof/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
#setting the composer cache directory
COMPOSER_HOME=${HOME}/cache/composer
@maxgaurav
maxgaurav / Handler.php
Created June 23, 2016 09:58
Laravel Env based Error Handling
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Validation\ValidationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;