Skip to content

Instantly share code, notes, and snippets.

View sagrawal31's full-sized avatar
🧑‍💻
😊

Shashank Agrawal sagrawal31

🧑‍💻
😊
View GitHub Profile
@sagrawal31
sagrawal31 / README.md
Created June 18, 2022 10:30
My first Angular v14 Standalone Component - Click to Copy

Click to Copy - An Angular v14 Standalone Component

Two dependencies- Angular Material & Tailwind are used in this example that you can always remove and replace with your own.

Usage

Importing in your existing module

@NgModule({
const urls: string[] = [];
const gallery = [
{id: 1, url: 'http://example.com/1.png'},
{id: 2, url: 'http://example.com/2.png'}
];
// Long code
gallery.forEach((item) => {
urls.push(item.url);
});
@sagrawal31
sagrawal31 / parseString.groovy
Created April 13, 2021 07:35
Convert string to any actual desired format in Groovy
import groovy.json.*
Object getValue(String value) {
try {
JsonSlurper slurper = new JsonSlurper()
return slurper.parseText(value)
} catch (JsonException e) {
// supress the exception - means it's unparceable
}
@sagrawal31
sagrawal31 / README.md
Last active July 9, 2020 16:27
Opening external link from Cordova WebView & in normal browser

Open External Link in New Tab

Problem Statement

Consider we have an external URL http://xyz.com which has some links (for example, http://example.com/privacy-policy) that needs to be opened in the new tab. The solution is very simple-

<a href="http://example.com/privacy-policy" target="_blank">
 Privacy Policy
@sagrawal31
sagrawal31 / events.ts
Last active January 26, 2024 13:22
Alternative to Events which got removed in Ionic 5
import {Injectable} from '@angular/core';
import {Subject, Subscription} from 'rxjs';
/**
* A custom Events service just like Ionic 3 Events https://ionicframework.com/docs/v3/api/util/Events/ which got removed in Ionic 5.
*
* @author Shashank Agrawal
*/
@Injectable({
providedIn: 'root'
@sagrawal31
sagrawal31 / home.component.ts
Last active May 15, 2023 15:12
Angular & Typescript wrapper around Razorpay checkout to be quickly used in any Angular/Ionic application
/**
* Example component file
*/
import {Component, NgZone} from '@angular/core';
import {RazorpayWrapper} from '../utils/razorpay/wrapper';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
@sagrawal31
sagrawal31 / dashboard.component.html
Created February 8, 2020 07:04
Debugging components in Angular 9
<div class="page-layout simple fullwidth">
<div class="header accent p-24" fxLayout="row" fxLayoutAlign="start center">
<h2>{{title}}</h2>
</div>
<div class="content p-24">
<h1 class="m-0">Quick stats and links</h1>
<h4 class="secondary-text">coming soon..</h4>
</div>
@sagrawal31
sagrawal31 / url-wrapper-test.ts
Last active December 27, 2019 10:30
A simple wrapper in TypeScript to easily parse & handle the URL
const url = new URLWrapper('https://example.com/?foo=bar&name=undefined&age=3');
console.log(url.getParam('foo') === 'bar');
console.log(url.getParam('name') === undefined);
console.log(url.getParam('age') === '3');
alias i='ionic'
alias is='i serve'
alias ib='i build'
alias ic='i cordova'
alias icb='ic build'
alias icp='ic prepare'
alias cr='cordova '
alias crun='cordova run '
alias crp='cordova platform'
@sagrawal31
sagrawal31 / git-bash-aliases.sh
Created May 12, 2019 08:00
A list of bash aliases used at WizPanda
alias guntrack='git update-index --assume-unchanged'
alias gtrack='git update-index --no-assume-unchanged'
alias gco='git checkout'
alias gs='git status'
alias gl='git log'
## Git log version 1
alias gl1="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --branches"
## Git log version 2
alias gl2='git log --graph --pretty=oneline --abbrev-commit'
## Git log version 3