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 / .htaccess
Last active August 3, 2020 07:00
apache-htaccess-reverese-proxy
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:8000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:8000/$1 [P,L]
@ashutoshpw
ashutoshpw / catch-all-route.js
Last active July 27, 2020 22:09
express-errors
// Place this after all the routes and middlewares
app.all("*", (req, res, next)=>{
return res.send("Route Doesn't exists");
})
@ashutoshpw
ashutoshpw / chrome.js
Created July 16, 2020 18:33
puppeteer-chrome
const p = require('puppeteer');
async function vo(){
const b = await p.launch({args: ['--no-sandbox']});
const page = await b.newPage();
await page.goto("https://www.opinionstage.com/polls/2462945/poll?sembed=1&wid=0");
page.on('console', msg => {
for (let i = 0; i < msg.args.length; ++i)
console.log(`${i}: ${msg.args[i]}`);
});

Raspberry Pi VPN Router

This is a quick-and-dirty guide to setting up a Raspberry Pi as a "router on a stick" to PrivateInternetAccess VPN.

Requirements

Install Raspbian Jessie (2016-05-27-raspbian-jessie.img) to your Pi's sdcard.

Use the Raspberry Pi Configuration tool or sudo raspi-config to:

@ashutoshpw
ashutoshpw / query.sql
Created April 4, 2020 20:31
mysql_queries_for_analytics
# Select Count for each Day
SELECT DATE(created_at) Date, COUNT(DISTINCT id) totalCOunt
FROM table_name
GROUP BY DATE(created_at)
@ashutoshpw
ashutoshpw / postgres_queries_and_commands.sql
Last active September 23, 2019 13:54 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- Show queries running since 2 minutes (Sometimes, remove waiting)
SELECT now() - query_start as "runtime", usename, datname, waiting, state, query
FROM pg_stat_activity
WHERE now() - query_start > '2 minutes'::interval
ORDER BY runtime DESC;
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
@ashutoshpw
ashutoshpw / export_table_column_sequelize.js
Created September 9, 2019 07:59
Export Database table columns to a file
const models = require('./models');
models.sequelize.query("SELECT table_schema || '.' || table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema')").then(function(rows) {
let d = JSON.parse(JSON.stringify(rows))
let my_tables = [];
for(let i=0;i<d.length;i++){
var n = (d[0][i]['?column?']).split(".");
if(n[0] == "public"){
let column_query = `select column_name, DATA_TYPE,NUMERIC_PRECISION, NUMERIC_SCALE
from INFORMATION_SCHEMA.COLUMNS
@ashutoshpw
ashutoshpw / install.sh
Created August 19, 2019 19:17 — forked from ziadoz/install.sh
Install Chrome, ChromeDriver and Selenium on Ubuntu 16.04
#!/usr/bin/env bash
# https://developers.supportbee.com/blog/setting-up-cucumber-to-run-with-Chrome-on-Linux/
# https://gist.github.com/curtismcmullan/7be1a8c1c841a9d8db2c
# http://stackoverflow.com/questions/10792403/how-do-i-get-chrome-working-with-selenium-using-php-webdriver
# http://stackoverflow.com/questions/26133486/how-to-specify-binary-path-for-remote-chromedriver-in-codeception
# http://stackoverflow.com/questions/40262682/how-to-run-selenium-3-x-with-chrome-driver-through-terminal
# http://askubuntu.com/questions/760085/how-do-you-install-google-chrome-on-ubuntu-16-04
# Versions
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
@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"