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 / time-calculate.php
Last active January 30, 2020 05:56
calculate time to execute a script.
<?php
//Create a variable for start time
$time_start = microtime(true);
//Create a variable for end time
$time_end = microtime(true);
// total execution time.
$execution_time = ($time_end - $time_start) / 60;
@miteshmap
miteshmap / savings_func.js
Last active January 2, 2020 16:37
small savings
/**
* The script is created purely based the video I saw on youtube about
* Personal finance on how to save money with small savings.
*
* If you invest 2 INR a day,In a year you can save around 133590 INR.
*
* The calculation goes like if on the 1st of january you save 2 rupees
* 2nd january you have to save 2*2 = 4 and 3 day 2*3 = 6 and likewise.
*
* You can not ideally transac this small amount to the bank, so I created
// With Jquery.
$('.year-select').once('current-year').on('change', function () {
var month = $('.month-select');
var currentYear = (new Date()).getFullYear().toString();
var selectedYear = jQuery('.year-select option:selected').val();
if (currentYear === selectedYear) {
var currentMonth = (new Date()).getMonth();
@miteshmap
miteshmap / memory-usage.php
Created February 6, 2019 17:38
Check memory used by a script.
<?php
// Add these lines at the end of your code.
echo PHP_EOL;
echo "Memory Usage :" . memory_get_usage();
echo PHP_EOL;
echo "Real Memory Usage :" . memory_get_usage(true);
echo PHP_EOL;
echo "Real Peak Memory Usage :" . memory_get_peak_usage(true);
echo PHP_EOL;
@miteshmap
miteshmap / sample.php
Last active June 1, 2018 06:41
Drupal 8: Service Decorators: sample.php
<?php
$base = \Drupal::service('custom_decorator_base.base');
print $base->helper();
@miteshmap
miteshmap / OriginalService.php
Last active June 1, 2018 06:21
Drupal 8: Service Decorators: OriginalService.php
<?php
namespace Drupal\custom_decorator_base;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Class OriginalService
*/
class OriginalService implements CustomDecoratorInterface {
@miteshmap
miteshmap / TokenServiceProvider.php
Created June 1, 2018 06:20
Drupal 8: Service Decorators: TokenServiceProvider.php
<?php
/**
* Replace drupal core token service with our own.
*/
class TokenServiceProvider extends ServiceProviderBase {
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container) {
@miteshmap
miteshmap / custom_decorator_override.yml
Created June 1, 2018 06:19
Drupal 8: Service Decorators: custom_decorator_override.yml
services:
custom_decorator_override.base:
class: Drupal\custom_decorator_override\OriginalServiceOverride
decorates: custom_decorator_base.base
decoration_priority: 9
public: false
arguments: ['@custom_decorator_override.base.inner', '@request_stack']
@miteshmap
miteshmap / custom_decorator_base.yml
Created June 1, 2018 06:17
Drupal 8: Service Decorators: custom_decorator_base.yml
services:
custom_decorator_base.base:
class: Drupal\custom_decorator_base\OriginalService
arguments: ['@request_stack']
@miteshmap
miteshmap / example.libraries.yml
Last active April 15, 2018 13:47
Drupal 8: libraries “css” naming convention and weights
example:
css:
theme:
css/example.css: {}
js:
js/example.js: {}