Skip to content

Instantly share code, notes, and snippets.

View asifsaho's full-sized avatar
💙

Asif Nawaz asifsaho

💙
View GitHub Profile
@asifsaho
asifsaho / TypeScriptCheatSheet.ts
Created February 15, 2022 09:33
Typescript Cheatsheet
// Map Object Type
const objMap: Record<string, string> = {
alu: 'mula',
};
@asifsaho
asifsaho / interview.js
Created February 15, 2022 08:51
JS interview question
console.log(add(5, 7)) // 12
console.log(add(5)(7)) // 12
console.log(add(3)(7)) // 10
function greet(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
@asifsaho
asifsaho / mockComponent.ts
Created February 14, 2022 17:17
Mock React component with jest
jest.mock('./embed-code/embed-code', () => {
return {
__esModule: true,
default: () => {
return <div>Embed component goes here</div>;
},
};
});
let mainArray = [{ value: '/AG_TURF-123', label: 'Ag & Turf', checked: false, id: 123, children: [{ value: '/AG_TURF-123/TRACTOR-456', label: 'Tractors', checked: false, id: 456, children: [{ value: '/AG_TURF-123/TRACTOR-456/Large-7-8-9-series', label: 'Large (7, 8, 9) Series', checked: false, id: 789, children: [{ value: '/AG_TURF-123/TRACTOR-456/Large-7-8-9-series/7-family-tractor', label: '7 Family Tractor', checked: false, id: 101112 }, { value: '/AG_TURF-123/TRACTOR-456/Large-7-8-9-series/8-family-tractor', label: '8 Family Tractor', checked: false, id: 131415 }, { value: '/AG_TURF-123/TRACTOR-456/Large-7-8-9-series/9-family-tractor', label: '9 Family Tractor', checked: false, id: 161718 }] }, { value: '/app/Http/routes.js', label: 'routes.js', checked: false, id: 181920 }] }, { value: '/app/Providers', label: 'Providers', checked: false, id: 212223, children: [{ value: '/app/Http/Providers/EventServiceProvider.js', label: 'EventServiceProvider.js', checked: false, id: 242526 }] }] }, { value: '/config',
import { mount } from 'enzyme';
import React from 'react';
import InputField from './index';
function setup() {
const props = {
label: 'FieldLabel',
name: 'fieldName',
onChange: jest.fn(),
value: 'fieldValue'
@asifsaho
asifsaho / protectRestEndpoint.php
Last active July 15, 2019 12:50
Protect WP Rest API
<?php
add_filter( 'rest_api_init', 'rest_only_for_authorized_users', 99 );
function rest_only_for_authorized_users($wp_rest_server){
if ( !is_user_logged_in() ) {
wp_die('sorry you are not allowed to access this data','cheatin eh?',403);
}
}
@asifsaho
asifsaho / git-commands.sh
Last active July 17, 2019 11:36
Usefull Git Command List
Git Squash
==========
# Reset the commit
git reset --soft HEAD~3
# Add new message for the new commit
git commit -m "New message for the combined commit"
# Change Commit Author in X Amount of commits
@asifsaho
asifsaho / mysql-backup_restore.md
Last active June 22, 2020 20:06 — forked from milon/mysql-backup_restore.md
Mysql: Backup and Restore

#Mysql: Backup and Restore

Mysql Backup and restore through command line.

Backup

mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
mysqldump -u root -p --all-databases > alldb.sql

@asifsaho
asifsaho / svg.css
Last active April 30, 2018 13:53
CSS SVG Background
.selector {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23d9534f' viewBox='-2 -2 7 7'%3E%3Cpath stroke='%23d9534f' d='M0 0l3 3m0-3L0 3'/%3E%3Ccircle r='.5'/%3E%3Ccircle cx='3' r='.5'/%3E%3Ccircle cy='3' r='.5'/%3E%3Ccircle cx='3' cy='3' r='.5'/%3E%3C/svg%3E");
}
Data URL convert online tool
https://yoksel.github.io/url-encoder/
// ## Globals
var argv = require('minimist')(process.argv.slice(2));
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create();
var changed = require('gulp-changed');
var concat = require('gulp-concat');
var flatten = require('gulp-flatten');
var gulp = require('gulp');
var gulpif = require('gulp-if');
var imagemin = require('gulp-imagemin');