Skip to content

Instantly share code, notes, and snippets.

View itmyprofession's full-sized avatar

Santosh Moktan itmyprofession

  • Kathmandu , Nepal
View GitHub Profile

Table of Contents

Core Concepts

  • Elements and JS
  • Components and Props
  • Lists and Keys
  • Events and Event Handlers

React Hooks

  • State and useState
  • Side Effects and useEffect
  • Performance and useCallback
  • Memoization and useMemo
  • Refs and useRef

Advanced Hooks

  • Context and useContext
  • Reducers and useReducer
  • Writing custom hooks
  • Rules of hooks

Core Concepts

Elements and JSX

This is the basic syntax for a React element:

// In a nutshell, JSX allows us to write HTML in our JS
// JSX can use any valid html tags (i.e. div/span, h1-h6, form/input, etc)

@itmyprofession
itmyprofession / index.php
Created January 28, 2019 16:11 — forked from amfeng/index.php
Stripe OAuth Example -- PHP
<?php
define('CLIENT_ID', 'YOUR_CLIENT_ID');
define('API_KEY', 'YOUR_API_KEY');
define('TOKEN_URI', 'https://connect.stripe.com/oauth/token');
define('AUTHORIZE_URI', 'https://connect.stripe.com/oauth/authorize');
if (isset($_GET['code'])) { // Redirect w/ code
$code = $_GET['code'];
@itmyprofession
itmyprofession / countries.sql
Created February 6, 2018 15:48 — forked from adhipg/countries.sql
Sql dump of all the Countries, Country Codes, Phone codes.
CREATE TABLE IF NOT EXISTS `country` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`iso` char(2) NOT NULL,
`name` varchar(80) NOT NULL,
`nicename` varchar(80) NOT NULL,
`iso3` char(3) DEFAULT NULL,
`numcode` smallint(6) DEFAULT NULL,
`phonecode` int(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
@itmyprofession
itmyprofession / gist:81261dbc78585a448b6bba092b772b40
Created January 31, 2018 09:25 — forked from CodeTheInternet/gist:9312404
JSON with country data, including base64 encoded flag images
[{"id":1,"name":"Afghanistan","isoAlpha2":"AF","isoAlpha3":"AFG","isoNumeric":4,"currency":{"code":"AFN","name":"Afghani","symbol":"؋"},"flag":"iVBORw0KGgoAAAANSUhEUgAAAB4AAAAUCAIAAAAVyRqTAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo3REQwQzQwNjE3NTMxMUUyODY3Q0FBOTFCQzlGNjlDRiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo3REQwQzQwNzE3NTMxMUUy
<?php
class Collection implements IteratorAggregate
{
/**
* The collection contents.
*
* @var array
*/
protected $items;
<?php
/**
* @file
* Contains \Drupal\mymodule\Plugin\QueueWorker\MyModuleTaskWorkerEntityUpdate.
*/
namespace Drupal\mymodule\Plugin\QueueWorker;
use Drupal\Core\Queue\QueueWorkerBase;
<?php
# Reading configuration
$config = \Drupal::config('system.maintenance');
$message = $config->get('message');
?>
<?php
// Writing in Configuration
$config = \Drupal::service('config.factory')->getEditable('system.performance');
@itmyprofession
itmyprofession / gist:5c7128bd5b40dee4d11651d54b2b80e0
Created June 7, 2016 18:28 — forked from abdev/gist:3083037
Magento - format date from local format to magento internal format
$myDate = '07/10/12';//2012-07-10
$format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$date = Mage::app()->getLocale()->date(
$myDate,
Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
null,
false
);