Skip to content

Instantly share code, notes, and snippets.

Avatar
🏡
Working from home

Swashata Ghosh swashata

🏡
Working from home
View GitHub Profile
@swashata
swashata / index.html
Created May 1, 2022
Separate Lifetime & Annual Buy Button Freemius
View index.html
<html>
<body>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://checkout.freemius.com/checkout.min.js"></script>
<button id="purchase_lifetime">Buy Lifetime License</button>
<button id="purchase_annual">Buy Annual License</button>
<script type="text/javascript">
const handler = FS.Checkout.configure({
@swashata
swashata / api.php
Created Aug 13, 2021
CORS in WordPress Plugin
View api.php
<?php
// CHECK BLOG POST HERE
// https://www.wpeform.io/blog/handle-cors-preflight-php-wordpress/
function acme_preflight_api() {
// preset option for allowed origins for our API server
$allowed_origins = [
'https://yoursite.com',
'https://preflight.yoursite.com',
'https://app.yoursite.com',
@swashata
swashata / php.code-snippet
Created May 9, 2021
VSCode Snippet PHPUNIT
View php.code-snippet
{
"testDox": {
"prefix": "__t",
"body": [
"/**",
" * @testdox ${1:what it does}",
" *",
" * @return void",
" */",
"public function test${2:${TM_FILENAME_BASE/(.*)Test$/$1/}}${1/(.*)/${1:/pascalcase}/}() {",
@swashata
swashata / callback.js
Created Mar 5, 2021
Callbacks and Promises in JS with nesting
View callback.js
// Below are some sample functions which take a callback and does some async action
// When the action is successful, it will call the callback with the data
function fetchPosts(callback) {
// somehow we get our posts
const posts = [
'Awesome Posts',
'Another one',
];
// call the callback with posts
View AnimateIn.tsx
import React from 'react';
import styled, { useTheme } from 'styled-components';
import { useSpring, animated } from 'react-spring';
import VisibilityObserver, {
useVisibilityObserver,
} from 'react-visibility-observer';
export const CONTROLCLASS = 'wpeform-component-animatein';
const Container = styled.div`
@swashata
swashata / .gitlab-ci.yml
Created Jul 4, 2020
Deploy WordPress Plugin with GitLab CI/CD
View .gitlab-ci.yml
# Our base image
image: registry.gitlab.com/wpquark/docker-containers/php-node:2.0.0-php-7.3-node-12.13.0
# Select what we should cache
cache:
key: "$CI_COMMIT_REF_SLUG-$CI_JOB_NAME"
paths:
- .yarn-cache
- .composer-cache
@swashata
swashata / dict.ts
Created Dec 24, 2019
A small dictionary in typescript
View dict.ts
export type Dictionary<T> = {
[x: string]: T;
};
export function convertListToDictionary<T extends { id: string }>(
items: T[]
): Dictionary<T> {
const dict: Dictionary<T> = {};
items.forEach(item => {
dict[item.id] = item;
@swashata
swashata / index.html
Last active Sep 16, 2019
Simple React App - No Tooling
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Simple React Application</title>
<!-- Add React and React DOM from CDN -->
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
@swashata
swashata / index.html
Created Sep 13, 2019
Promises - The Easy Way
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<button id="fetch">Start the fetch</button>
@swashata
swashata / Base.php
Last active May 31, 2019
Sample implementation of GraphQL integration test
View Base.php
<?php
/**
* Copyright (C) 2018 Swashata Ghosh <swashata@wpquark.com>
*
* This file is part of eForm - WordPress Builder.
*
* eForm - WordPress Builder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.