Skip to content

Instantly share code, notes, and snippets.

@surajair
surajair / generateStyles.ts
Last active August 13, 2024 16:56
Generate Styles for blocks
import { get } from "lodash";
import getPalette from "tailwindcss-palette-generator";
import plugin from "tailwindcss/plugin";
import { createTailwindcss } from "@mhsdesign/jit-browser-tailwindcss";
export const getTailwindConfig = (options: any, plugins: any[] = []) => {
const primary = get(options, "primaryColor", "#000");
const secondary = get(options, "secondaryColor", "#ccc");
const headingFont = get(options, "headingFont", "Inter");
@surajair
surajair / re-Captcha.css
Created February 26, 2018 16:18
re-capcha.css
.g-recaptcha {
> div{
width: 100%;
height: auto;
}
}
.g-recaptcha{
iframe{
width: 100%;
@surajair
surajair / tracking-user.js
Last active October 14, 2017 12:53
Sentry Tracking User
Raven.setUserContext({
email: '[email protected]',
id: '123'
})
// call this function to rmeove the association. Normally call this when the user logs out.
Raven.setUserContext()
@surajair
surajair / sentry.js
Created October 14, 2017 12:47
Sentry Manually Logging Error
Raven.context(function() {
doSomething(a[0]) // possibly a[0] is undefined and hence will cause an exception
})
var doIt = function() {
// errorenous code here
}
setTimeout(Raven.wrap(doIt), 1000)
@surajair
surajair / Sentry-error.js
Created October 14, 2017 12:45
sentry error example
try {
doSomething(a[0]) // possibly can cause an exception
} catch(e) {
Raven.captureException(e)
}
@surajair
surajair / sentry-config.js
Created October 14, 2017 12:33
Sentry config
Raven.config('https://<key>@sentry.io/', {
release: '1.3.0'
}).install()
@surajair
surajair / functions.php
Last active April 21, 2017 19:46
WP mobile redirect for AMP
<?php
function wp_ampify_template_redirect(){
if (!wp_is_mobile() )
return;
$cur_url = esc_url((is_ssl() ? "https://" : "http://") . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] );
if(is_front_page() || is_home() || is_archive()){
$cur_url .= '?amp=1';
}
@surajair
surajair / amp-redirect-headers.php
Last active March 23, 2017 18:10
AMP form redirection headers
<?php
@header('AMP-Redirect-To: '. get_permalink($_POST['comment_post_ID']) . '#respond');
@header('AMP-Access-Control-Allow-Source-Origin: ' . $_REQUEST['__amp_source_origin'] );
@surajair
surajair / functions.php
Last active December 27, 2018 09:52
Wordpress AJAX handler for comments form submit on AMP pages
<?php
function amp_comment_submit(){
$comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
if ( is_wp_error( $comment ) ) {
$data = intval( $comment->get_error_data() );
if ( ! empty( $data ) ) {
status_header(500);
wp_send_json(array('msg' => $comment->get_error_message(),
'response' => $data,
'back_link' => true ));
@surajair
surajair / comment-form-with-errors.php
Last active March 23, 2017 18:00
Wordpress Comment Form for Google AMP Pages
<form method="post" id="commentform" target="_top" class="comment-form" novalidate="" action-xhr="<?php echo admin_url('admin-ajax.php?action=amp_comment_submit') ?>" target="_top">
<p class="comment-notes">
<span id="email-notes">Your email address will not be published.</span> Required fields are marked <span class="required">*</span>
</p>
<p class="comment-form-comment">
<label for="comment">Comment</label>
<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" aria-required="true" required="required"></textarea>
</p>
<p class="comment-form-author">
<label for="author">Name <span class="required">*</span></label>