Skip to content

Instantly share code, notes, and snippets.

Avatar

Ram Ratan Maurya mauryaratan

View GitHub Profile
@mauryaratan
mauryaratan / scrollable-container.js
Last active Jun 16, 2018
Adds a top/bottom shadow for scrollable area depending on current scroll position.
View scrollable-container.js
const scrollable = document.querySelectorAll( '.scrollable' );
scrollable.forEach( function( el ) {
if ( el.offsetHeight < el.scrollHeight ) {
el.classList.add( 'bottom-shadow' );
}
el.addEventListener( 'scroll', function( e ) {
const scrollHeight = e.target.clientHeight;
const scrollPosition = scrollHeight + e.target.scrollTop;
@mauryaratan
mauryaratan / shortcuts.js
Created May 22, 2018
Shortkeys (Custom Keyboard Shortcuts) custom settings
View shortcuts.js
[{"action":"prevtab","blacklist":false,"exported":true,"key":"a","open":false,"sites":"*mail.google.com*","sitesArray":["*mail.google.com*"]},{"action":"nexttab","blacklist":false,"exported":true,"key":"s","open":false,"sites":"*mail.google.com*","sitesArray":["*mail.google.com*"]},{"action":"newtab","blacklist":false,"exported":true,"key":"t","open":false,"sites":"*mail.google.com*","sitesArray":["*mail.google.com*"]},{"action":"closetab","blacklist":false,"exported":true,"key":"c","open":false,"sites":"*mail.google.com*","sitesArray":["*mail.google.com*"]},{"action":"back","blacklist":false,"exported":true,"key":"z","open":false,"sites":"*mail.google.com*","sitesArray":["*mail.google.com*"]},{"action":"forward","blacklist":false,"exported":true,"key":"x","open":false,"sites":"*mail.google.com*","sitesArray":["*mail.google.com*"]},{"action":"reload","blacklist":false,"exported":true,"key":"r","open":false,"sites":"*mail.google.com*","sitesArray":["*mail.google.com*"]},{"action":"copyurl","blacklist":false,"e
@mauryaratan
mauryaratan / .eslint.json
Created Jan 31, 2018
ESLint configuration.
View .eslint.json
{
"root": true,
"env": {
"browser": true,
"es6": true
},
"plugins": [
"wordpress",
"async"
],
@mauryaratan
mauryaratan / insertPost.js
Last active Jan 5, 2018
Insert a post manually to put correct data back in its place.
View insertPost.js
// Embassy Suites Amarillo,"550 Buchanan Street, Amarillo, TX 79101","Amarillo, TX",Hilton,Open,226,,,35.207672,-101.8324899
async function fetchAsync(string) {
const response = await fetch(ajaxurl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
},
credentials: 'same-origin',
@mauryaratan
mauryaratan / chrome-snippets.json
Created Jul 28, 2017
Google Chrome Snippets, can be imported/exported from here https://gist.github.com/soundyogi/03df95505604c8351212 since Chrome doesn't offers any methods to sync it.
View chrome-snippets.json
{
"snippets": [
{
"name": "dataurl.js",
"content": "// dataurl.js\n// https://github.com/bgrins/devtools-snippets\n// Print out data URLs for all images / canvases on the page.\n\n((() => {\n\n console.group(\"Data URLs\");\n\n [].forEach.call(document.querySelectorAll(\"img\"), i => {\n const c = document.createElement(\"canvas\");\n const ctx = c.getContext(\"2d\");\n c.width = i.width;\n c.height = i.height;\n\n try {\n ctx.drawImage(i, 0, 0);\n console.log(i, c.toDataURL());\n }\n catch(e) {\n console.log(i, \"No Permission - try opening this image in a new tab and running the snippet again?\", i.src);\n }\n });\n\n [].forEach.call(document.querySelectorAll(\"canvas\"), c => {\n try {\n console.log(c, c.toDataURL());\n }\n catch(e) {\n console.log(c, \"No Permission\");\n }\n });\n\n console.groupEnd(\"Data URLs\");\n\n}))();"
},
{
"name": "jqueryify.js",
"content": "// jquerify.js\n// https://github.c
View keybase.md

Keybase proof

I hereby claim:

  • I am mauryaratan on github.
  • I am mauryaratan (https://keybase.io/mauryaratan) on keybase.
  • I have a public key whose fingerprint is F252 EF6D FB8D 11BB 9DCE CC0D 496A 6132 0080 FF1D

To claim this, I am signing this object:

@mauryaratan
mauryaratan / random-color.php
Created Feb 7, 2016
Generate a random color string in PHP.
View random-color.php
<?php
function random_color_value() {
return str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT );
}
function random_color() {
return random_color_value() . random_color_value() . random_color_value();
}
View pagespeed-rules
pagespeed on;
# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
View compile-nginx.sh
# Install dependencies
#
# * checkinstall: package the .deb
# * libpcre3, libpcre3-dev: required for HTTP rewrite module
# * zlib1g zlib1g-dbg zlib1g-dev: required for HTTP gzip module
apt-get install checkinstall libpcre3 libpcre3-dev zlib1g zlib1g-dbg zlib1g-dev && \
OLD_DIR=`pwd` && \
WDIR=~/sources/ && \
OPENSSL_VER=1.0.2 && \
@mauryaratan
mauryaratan / public-access.json
Created Aug 14, 2014
Set Amazon S3 to allow requests publicly. Make sure to replace 'Codestag' with your Amazon bucket name.
View public-access.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
You can’t perform that action at this time.