Skip to content

Instantly share code, notes, and snippets.

<?php
abstract class AbstractSender
{
protected $senderChecker;
// assume typical getter/setter for $senderChecker
public function send()
{
@rparsi
rparsi / Nodejs_es6_modules_example_01.txt
Last active October 15, 2018 20:05
Nodejs custom modules with ES6 module syntax: example 01
Expected working directory structure
===========================================
./lib/ConsoleAdapter.js -- your custom modules
./App.js -- your application main entry point
./index.js -- purpose of this file is to use the esm module to do all the module loading
Preparation
=======================================
@rparsi
rparsi / Nodejs_custom_modules_example_01.txt
Created October 13, 2018 02:25
Nodejs custom modules with native Nodejs module syntax: example 01
Assumptions
==================================
Working directory structure:
./lib/Console.js
./App.js
/* in ./lib/Console.js */
"use strict";
@rparsi
rparsi / ProductSetup.php
Created July 24, 2018 20:36
Magento 2.2.x add custom product attribute
<?php
namespace MyCustomVendor\Catalog\Setup;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Setup\CategorySetup as Base;
use MyCustomVendor\Catalog\Api\CustomProductInterface; // interface with constants defining the keys for all the custom attributes
@rparsi
rparsi / Json.php
Created July 9, 2018 19:06
Handle differing serialized object/data formats between magento versions...because magento devs too stupid to do it correctly
<?php
namespace YourVendorName\FrameworkOverride\Framework\Serialize\Serializer;
use Magento\Framework\Serialize\Serializer\Json as Base;
class Json extends Base
{
public function unserialize($string) // override of base class method
@rparsi
rparsi / yolo_load_other_js.phtml
Created July 4, 2018 22:02
loading js inline in phtml file with requirejs
<script>
require(['domReady', 'jquery', 'http://you.can.also.use.urls/blah.js'], function (domReady, $, blah) {
domReady(function () {
// do jquery stuff, among other things
$("#form-validate").css('display', 'none');
var forgot = $('forgotPasswordLink');
var forgotEmail = $('email_address');
$(forgot).on('click', function(event){
event.preventDefault();
$("#form-validate").css('display', 'unset');
@rparsi
rparsi / magento2_rest_api_usage.sh
Created May 24, 2018 06:27
Magento2 Rest API Usage
# to get admin user api token
curl -X POST "http://localhost.magento2.com/index.php/rest/V1/integration/admin/token" -H "Content-Type:application/json" -d '{"username":"admin", "password":"admin123"}'
# example api token: gltdyin7xidjpmkgn2afd5p945hry64d
# use countries api
curl -X GET "http://localhost.magento2.com/index.php/rest/V1/directory/countries" -H "Authorization: Bearer c4chlm8e9j819mss4x1f6hs5jvdu7syp"
# create customer
curl -X POST http://localhost.magento2.com/index.php/rest/V1/customers" -H "Content-Type:application/json" -H "Authorization: Bearer ich23vrq4be4yj671j6u1bx12r3n03u7" -d '{"customer":{"email":"rparsi@commer.com","firstname":"Rahi","lastname":"Parsi","dob":"1976-11-28","storeId":1,"websiteId":1},"password":"Admin123"}'
@rparsi
rparsi / magento2_permissions.sh
Created May 23, 2018 05:31
minimal magento2 directory permissions
#!/bin/bash
sudo chown `whoami`:apache -R pub var app/etc
sudo chmod ug+rw -R pub var app/etc
@rparsi
rparsi / magento2_apache_vhost.conf
Created May 23, 2018 05:30
magento2 apache vhost config file
<VirtualHost *:80>
ServerName localhost.magento2.rahi
ServerAlias localhost.magento2.rahi
DocumentRoot /var/www/sites/magento2
<Directory /var/www/sites/magento2>
Require all granted
AllowOverride All
#<IfModule mod_rewrite.c>
@rparsi
rparsi / yolo-reactjs.js
Last active May 15, 2018 02:55
Yolo super simple reactjs
import React, { Component } from 'react';
import $ from 'jquery';
class Modal extends Component {
constructor(props) {
super(props); // props are always read only
this.modalRef = React.createRef();
}
checkIsOpen() {