Skip to content

Instantly share code, notes, and snippets.

View ashutoshpw's full-sized avatar
:octocat:
Helping people to convert their Ideas into Reality

Ashutosh Kumar ashutoshpw

:octocat:
Helping people to convert their Ideas into Reality
View GitHub Profile
@ashutoshpw
ashutoshpw / data.js
Last active February 20, 2022 22:10
Foreach with Promise.all for faster execution than For Loop
module.exports = [
{
id:1,
data:1
},
{
id:2,
data:2
},
{
@ashutoshpw
ashutoshpw / app.sh
Created July 26, 2019 00:04
Renew SSL using Certbot
DOMAIN_NAME="domain.com"
sudo certbot --authenticator standalone --installer nginx -d $DOMAIN_NAME --pre-hook "service nginx stop" --post-hook "service nginx start"
@ashutoshpw
ashutoshpw / restart_service.sh
Created May 4, 2019 17:26
Restart Linux Service if stopped.
#!/bin/bash
service=mysql
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo $(ps -ef | grep -v grep | grep $service )
echo "$service is running!!!"
else
/etc/init.d/$service start
fi
@ashutoshpw
ashutoshpw / app.js
Created April 13, 2019 18:53
Cloudflare_Worker_Response_Like_Express
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
let res = {
json: function(json){
return new Response(JSON.stringify(json),{'headers':{'Content-Type':'application/json'}});
}
};
@ashutoshpw
ashutoshpw / Shopify tag filter groups
Created March 26, 2019 02:56 — forked from darryn/Shopify tag filter groups
Create tag filter groups in Shopify. This snippet is designed to group and separate out collection tags. It requires the tags to share a common value prepended to the tag with an underscore. E.g. to create a separate tag filter group for 'brands', each product will need to be tagged with 'brand_Nike' or 'brand_Reebok'. Some of this is probably l…
{% if template contains 'collection' and collection.all_tags.size > 1 %}
<!-- A recursive loop to catch and filter out the different tag categories -->
{% assign c = 0 %}
{% for t in collection.all_tags %}
{% capture cat %}{{ cat }}{% capture temp_cat %}{% if t contains '_' %}{% assign cat_grp = t | split: '_' %}{{ cat_grp.first }}{% endif %}{% endcapture %}{% unless cat contains temp_cat %}{% if t contains '_' %}{% assign new_cat_grp = t | split: '_' %}{{ new_cat_grp.first }}{% endif %}{% unless forloop.last %}+{% endunless %}{% assign c = c | plus: 1 %}{% endunless %}{% endcapture %}
{% endfor %}
<!-- create array of tag categories -->
{% assign cat_array = cat | split: '+' %}
@ashutoshpw
ashutoshpw / shop.js
Created March 24, 2019 00:53 — forked from dominikwilkowski/shop.js
Convert variant dropdown into swatches, multiple-option-sollution
/**************************************************************| CONVERT VARIANT TO SWATCHES |*/
$(function() {
if($(".single-option-selector").length) {
$(".single-option-selector").each(function(i) {
var $thisSelect = $(this);
var $newClass = "js-option-selector-" + i;
var $newOptions = '<ul class="new-variant-swatchs">';
var $currentOption = $thisSelect.val();
@ashutoshpw
ashutoshpw / allow.sh
Created November 15, 2018 18:36
Allow accessing website from only one IP with IP Tables
iptables -I INPUT -p tcp ! -s 139.59.13.17 --dport 80 -j DROP
@ashutoshpw
ashutoshpw / app.sh
Created November 15, 2018 18:36
Restrict Incoming ICMP (Ping) and Enable Outgoing Ping
SERVER_IP="142.93.220.116"
iptables -A OUTPUT -p icmp --icmp-type 8 -s 139.59.13.17 -d 0/0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 0 -s 0/0 -d 139.59.13.17 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -j DROP
@ashutoshpw
ashutoshpw / lua_file.lua
Created October 7, 2018 09:47
lua-nginx-redis-host
function getResponseAndWriteHeaders(sessionId)
local response = red:hgetall(sessionId)
for key,value in pairs(mapKeyValuePairs(response)) do
ngx.req.set_header(key, value)
end
end
function checkForExtension(sessionId)
local ttl = red:ttl(sessionId)
if not is Empty(ttl) and ttl < expiry() then
@ashutoshpw
ashutoshpw / server.js
Created August 19, 2018 12:16
Static Site Hosting Using Cloudflare Workers
// Normal Static Site hosting with Digital Ocean Spaces.
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const parsedUrl = new URL(request.url)
let path = parsedUrl.pathname