Skip to content

Instantly share code, notes, and snippets.

View miteshmap's full-sized avatar
👨‍💻
Working from home

Mitesh Patel miteshmap

👨‍💻
Working from home
View GitHub Profile
@miteshmap
miteshmap / data-analysis-and-visualisation-bootcamp.ipynb
Created January 17, 2024 17:11
data-analysis-and-visualisation-bootcamp
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@miteshmap
miteshmap / data.json
Created March 31, 2023 23:48
json api response
{"results":[{"fsq_id":"4c42bf92d691c9b601db8e0a","categories":[{"id":13034,"name":"Café","icon":{"prefix":"https://ss3.4sqi.net/img/categories_v2/food/cafe_","suffix":".png"}}],"chains":[],"distance":202,"geocodes":{"main":{"latitude":52.237009,"longitude":-0.896756}},"link":"/v3/places/4c42bf92d691c9b601db8e0a","location":{"address":"George Row","admin_region":"England","country":"GB","formatted_address":"George Row, Northampton, NN1 1DF","locality":"Northampton","post_town":"Northampton","postcode":"NN1 1DF"},"name":"All Saints Bistro - Northampton","related_places":{"parent":{"fsq_id":"5091102de4b09fc320fc18bb","name":"All Saints Church"}},"timezone":"Europe/London"},{"fsq_id":"57ff893738fa6cf9d0864e65","categories":[{"id":13016,"name":"Lounge","icon":{"prefix":"https://ss3.4sqi.net/img/categories_v2/nightlife/default_","suffix":".png"}},{"id":13034,"name":"Café","icon":{"prefix":"https://ss3.4sqi.net/img/categories_v2/food/cafe_","suffix":".png"}},{"id":13065,"name":"Restaurant","icon":{"prefix":"https://
@miteshmap
miteshmap / Makefile
Created January 30, 2023 21:20
Makefile
# Split all arguments for easier use in commands.
# You can now use the variables: ${ARGS} ${ARG_1} ${ARG_2} ${ARG_3} ${ARG_REST}
# @see https://stackoverflow.com/questions/2214575/passing-arguments-to-make-run#answer-45003119
ARGS = $(filter-out $@,$(MAKECMDGOALS))
ARG_1 = $(word 1, ${ARGS})
ARG_2 = $(word 2, ${ARGS})
ARG_3 = $(word 3, ${ARGS})
ARG_REST = $(wordlist 2, 100, ${ARGS})
## We use the following rule/recipe to prevent errors messages when passing arguments in make commands
## @see https://stackoverflow.com/a/6273809/1826109
@miteshmap
miteshmap / test.php
Last active February 23, 2022 17:30
Check the plugin is exist or not in layout builder
<?php
$display = \Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load($param->getEntityTypeId() . '.' . $param->bundle() . '.default');
if ($display && $display->isLayoutBuilderEnabled()) {
foreach($display->getSections() as $section) {
$result = (bool) array_filter(
$section->getComponents(),
function (SectionComponent $component) use ($plugin_id) {
@miteshmap
miteshmap / blob-download.js
Last active January 8, 2021 08:33
Download blob data with axios
import axios from "axios";
import { saveAs } from "file-saver";
axios(`${apiUrlPrefix}/file/5`, {
method: 'GET',
responseType: 'blob',
headers: {
'Authorization': `Bearer ${token}`,
}
}).then(response => {
@miteshmap
miteshmap / CacheSearch.js
Last active June 10, 2020 15:32
React Fetcher with cache for axios request, based on a talk of Dan Abramov: https://youtu.be/nLF0n9SACd4?t=877
/**
* Cache class for search.
*
* Avoid unnecessary api request by caching the results.
*/
class CacheSearch {
constructor() {
this.query = '';
this.queryCount = 0;
this.cache = {};
class FrogBuilder {
constructor(name, gender) {
// Ensure that the first character is always capitalized
this.name = name.charAt(0).toUpperCase() + name.slice(1)
this.gender = gender
}
formatEyesCorrectly(eyes) {
return Array.isArray(eyes) ? { left: eye[0], right: eye[1] } : eyes
}
setEyes(eyes) {
@miteshmap
miteshmap / gist:7666a0ddebf40f9fff773a61bf9ba92b
Created March 23, 2020 03:55
Measuring used JS heap size in chrome
console.log(performance.memory.usedJSHeapSize)
@miteshmap
miteshmap / Promise-fetcher.js
Last active February 28, 2020 07:38
helper method for promoise fetch. which expects promise as an argument.
// Helper method to handle error and expact only error or result.
export const createFetcher = promiseFunc => {
return {
read: arg => {
try {
return promiseFunc(arg)
.then(response => {
if (!response) {
return {error: 'error!'};
}
@miteshmap
miteshmap / OriginalServiceOverride.php
Last active February 19, 2020 03:15
Drupal 8: Service Decorators: OriginalServiceOverride.php
<?php
namespace Drupal\custom_decorator_override;
use Drupal\custom_decorator_base\OriginalService;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Class OriginalServiceOverride
*/
class OriginalServiceOverride extends OriginalService {
/**
* Original service object.