Skip to content

Instantly share code, notes, and snippets.

View swashata's full-sized avatar
🏡
Working from home

Swashata Ghosh swashata

🏡
Working from home
View GitHub Profile
@swashata
swashata / api.php
Created August 13, 2021 13:51
CORS in WordPress Plugin
<?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 / .gitlab-ci.yml
Created July 4, 2020 14:29
Deploy WordPress Plugin with GitLab CI/CD
# 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 / index.html
Created May 1, 2022 08:49
Separate Lifetime & Annual Buy Button Freemius
<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 / php.code-snippet
Created May 9, 2021 08:46
VSCode Snippet PHPUNIT
{
"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 March 5, 2021 12:45
Callbacks and Promises in JS with nesting
// 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
@swashata
swashata / AnimateIn.tsx
Created September 19, 2020 08:08
AnimateIn
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 / bd3d4befe38185704bf0fc875e9deed6|configuration.json
Last active May 16, 2020 12:58
Visual Studio Code Settings Sync Gist
{"contents":{"launch":{"version":"0.2.0","configurations":[{"type":"node","request":"launch","name":"Launch Program","program":"${workspaceFolder}/importPhotosForEachVendor.js"}]}},"overrides":[],"keys":["launch.version","launch.configurations"]}
@swashata
swashata / dict.ts
Created December 24, 2019 01:31
A small dictionary in typescript
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 September 16, 2019 04:52
Simple React App - No Tooling
<!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 September 13, 2019 05:30
Promises - The Easy Way
<!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>