Skip to content

Instantly share code, notes, and snippets.

View luanbe's full-sized avatar

Luan Nguyen luanbe

View GitHub Profile
@luanbe
luanbe / postgres_queries_and_commands.sql
Created August 2, 2023 09:52 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- 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%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@luanbe
luanbe / google_drive_create_file_example.go
Created July 13, 2022 10:00 — forked from atotto/google_drive_create_file_example.go
google drive example (v3 create file)
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
@luanbe
luanbe / add_intellij_launcer
Created May 6, 2022 04:17 — forked from rob-murray/add_intellij_launcer
Add Intellij launcher shortcut and icon for ubuntu
// create file:
sudo vim /usr/share/applications/intellij.desktop
// add the following
[Desktop Entry]
Version=13.0
Type=Application
Terminal=false
Icon[en_US]=/home/rob/.intellij-13/bin/idea.png
Name[en_US]=IntelliJ
@luanbe
luanbe / scheduler.py
Created September 22, 2021 11:59 — forked from Santhin/scheduler.py
APscheduler with scrapy
#source stack
from scrapy import spiderloader
from scrapy.utils import project
from scrapy.crawler import CrawlerRunner
from twisted.internet import reactor, defer
from scrapy.utils.log import configure_logging
import logging
from datetime import datetime
@luanbe
luanbe / string.py
Created September 16, 2021 10:10
Python utils
def find_subs(s1, s2):
subs = []
loc = 0
while s1:
s1_copy = s1
while s1_copy:
while s1_copy and s1_copy not in s2:
s1_copy = s1_copy[:-1]
if s1_copy:
subs.append((loc, s2.index(s1_copy), s1_copy))
@luanbe
luanbe / TorPrivoxyPython.md
Created May 19, 2021 09:21 — forked from DusanMadar/TorPrivoxyPython.md
A step-by-step guide how to use Python with Tor and Privoxy

A step-by-step guide how to use Python with Tor and Privoxy

Tested on Ubuntu 18.04 Docker container. The Dockerfile is a single line FROM ubuntu:18.04. Alternatively, you can simply run docker run -it ubuntu:18.04 bash.

NOTE: stopping services didn't work for me for some reason. That's why there is kill $(pidof <service name>) after each failed service <service name> stop to kill it.

References

This guide is basically a compilation of all the resources listed below.

@luanbe
luanbe / install_firefox_selenium.sh
Last active July 12, 2021 19:07
Install Python, Firefox, and Geckodriver in Ubuntu
#!/usr/bin/env bash
# Test on Ubuntu 18.04.5 LTS
# Install dependencies.
sudo apt-get update
sudo apt-get install -y unzip openjdk-8-jre-headless xvfb libxi6 libgconf-2-4 git-all firefox python3 python3-dev libpq-dev python3-pip python3-venv libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev
# Install geckodriver
export GECKO_DRIVER_VERSION='v0.29.1'
wget https://github.com/mozilla/geckodriver/releases/download/$GECKO_DRIVER_VERSION/geckodriver-$GECKO_DRIVER_VERSION-linux64.tar.gz
@luanbe
luanbe / install_chrome_selenium.sh
Last active May 17, 2021 11:45
Install Chrome, Chrome Driver and Python in Ubuntu
#!/usr/bin/env bash
# This file edited from https://gist.github.com/ziadoz/3e8ab7e944d02fe872c3454d17af31a5
# Test on Ubuntu 18.04.5 LTS
# Versions
CHROME_DRIVER_VERSION=`curl -sS https://chromedriver.storage.googleapis.com/LATEST_RELEASE`
SELENIUM_STANDALONE_VERSION=3.9.1
SELENIUM_SUBDIR=$(echo "$SELENIUM_STANDALONE_VERSION" | cut -d"." -f-2)
# Remove existing downloads and binaries so we can start from scratch.