Skip to content

Instantly share code, notes, and snippets.

View himanshu-myupchar's full-sized avatar
:octocat:
Focusing

himanshu-myupchar

:octocat:
Focusing
View GitHub Profile
@himanshu-myupchar
himanshu-myupchar / amp-access.amp
Last active September 4, 2019 11:13
AMP ACCESS html
<section amp-access="loggedIn">
<template amp-access-template type="amp-mustache">
<amp-img src={{image}} width="29px" height="29px" class="round-logged-in-img"/>{{name}}
</template>
</section>
<script id="amp-access" type="application/json">
{
"authorization": "/amp-access/authorization?rid=READER_ID&url=CANONICAL_URL&ref=DOCUMENT_REFERRER&_=RANDOM",
"pingback": "/amp-access/authorization?rid=READER_ID&url=CANONICAL_URL&ref=DOCUMENT_REFERRER&_=RANDOM",
"authorizationFallbackResponse": {
"error": true,
"loggedIn": false,
"powerUser": false
}
}
@himanshu-myupchar
himanshu-myupchar / front-webp.html.erb
Last active March 28, 2019 08:05
Frontend to handle webp
<picture>
<source type="image/webp" srcset="<%=@post.asset.url(:webp)%>">
<source type="<%=@post.asset_content_type%>" srcset="<%=@post.asset.url%>">
<img class="img-fluid img-center img-responsive" data-original="<%=@post.asset.url%>" alt="<%=@post.title%>" src=""/>
</picture>
module Paperclip
# Paperclip processors allow you to modify attached files when they are
# attached in any way you are able. Paperclip itself uses command-line
# programs for its included Thumbnail processor, but custom processors
# are not required to follow suit.
#
# Processors are required to be defined inside the Paperclip module and
# are also required to be a subclass of Paperclip::Processor. There is
# only one method you *must* implement to properly be a subclass:
# #make, but #initialize may also be of use. #initialize accepts 3
@himanshu-myupchar
himanshu-myupchar / webp.rb
Created March 28, 2019 07:49
Convert any image format to webp
class Post
has_attached_file :asset,
:storage => :s3,
:processors => [:webp],
:url => ":s3_alias_url",
:path => ":id/:filename",
:s3_region => "your-region",
styles: {
webp: {
format: 'webp'