Skip to content

Instantly share code, notes, and snippets.

@xriu
xriu / postgres_queries_and_commands.sql
Created December 18, 2023 09:27 — 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%'
@xriu
xriu / install.sh
Created March 20, 2021 07:42 — forked from rjnienaber/install.sh
Compile ImageMagick with WEBP and HEIC support on Ubuntu 16.04
# $ lsb_release -a
# No LSB modules are available.
# Distributor ID: Ubuntu
# Description: Ubuntu 16.04.5 LTS
# Release: 16.04
# Codename: xenial
# $ uname -a
# Linux xps 4.4.0-134-generic #160-Ubuntu SMP Wed Aug 15 14:58:00 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
@xriu
xriu / github_multiple-accounts.md
Created December 26, 2020 10:27
How to Work with GitHub and Multiple Accounts

Step 1 - Create a New SSH Key

We need to generate a unique SSH key for our second GitHub account.

ssh-keygen -t rsa -C "your-email-address"

Be careful that you don't over-write your existing key for your personal account. Instead, when prompted, save the file as id_rsa_COMPANY. In my case, I've saved the file to ~/.ssh/id_rsa_work.

Step 2 - Attach the New Key

@xriu
xriu / trash.sh
Created August 22, 2020 10:32 — forked from geek-at/trash.sh
The script used to trash a banking phishing site
#!/bin/bash
while :; do
verf=$(cat /dev/urandom | tr -dc '0-9' | fold -w 8 | head -n 1)
pin=$(cat /dev/urandom | tr -dc '0-9' | fold -w 5 | head -n 1)
ip=$(printf "%d.%d.%d.%d\n" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))")
@xriu
xriu / change-openssl-version.md
Created July 11, 2020 14:05 — forked from zulhfreelancer/change-openssl-version.md
How to switch OpenSSL version on Mac using Homebrew?

How to switch OpenSSL version on Mac using Homebrew?

Scenario: you have both OpenSSL 1.0 and 1.1 installed (using Brew) in your OSX system and you want to switch the current active version without removing other versions that already installed. Here is how to do it.

Step 1 - List all OpenSSL versions

$ ls -al /usr/local/Cellar/openssl*

/usr/local/Cellar/openssl:
@xriu
xriu / README.md
Created June 4, 2019 10:28
Give API Gateway permissions to write to CloudWatch logs

Necessary for API Gateway Logging

Give API Gateway permissions to write to CloudWatch logs

Solves the CloudFormation error that yields the message:

CloudWatch Logs role ARN must be set in account settings to enable logging (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: ...)

NOTE: This is a one time process. As long as you have this enabled once in a region, you can

@xriu
xriu / Java8DateTimeExamples.java
Created August 25, 2018 12:15 — forked from mscharhag/Java8DateTimeExamples.java
Examples for using the Java 8 Date and Time API (JSR 310)
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import static java.time.temporal.TemporalAdjusters.*;
public class Java8DateTimeExamples {
@xriu
xriu / Install_selenium.sh
Created June 9, 2018 08:44 — forked from jconstance-amplify/Install_selenium.sh
SeleniumConf 2017 Amplify Code Snippets
install_selenium_server_standalone() {
local desired_version=${1:-latest}
# Create our shell user
init_shell_user "selenium" "*"
local selenium_download_site="http://selenium-release.storage.googleapis.com"
local selenium_releases=$(curl --silent --show-error "$selenium_download_site" | grep --only-matching --perl-regexp '[0-9\.-\w]+?/selenium-server-standalone.*?\.jar' | sort --reverse)
if [ "$desired_version" == "latest" ]; then
@xriu
xriu / gist:6d343012df4aa16d3300db928858c06d
Created January 27, 2018 11:47 — forked from trongthanh/gist:2779392
How to move a folder from one repo to another
# source: http://st-on-it.blogspot.com/2010/01/how-to-move-folders-between-git.html
# First of all you need to have a clean clone of the source repository so we didn't screw the things up.
git clone git://server.com/my-repo1.git
# After that you need to do some preparations on the source repository, nuking all the entries except the folder you need to move. Use the following command
git filter-branch --subdirectory-filter your_dir -- -- all
# This will nuke all the other entries and their history, creating a clean git repository that contains only data and history from the directory you need. If you need to move several folders, you have to collect them in a single directory using the git mv command.
@xriu
xriu / Dockerfile
Created December 27, 2017 10:47 — forked from ankitpopli1891/Dockerfile
Dockerizing a web app using Nginx
# https://docs.docker.com/engine/userguide/eng-image/multistage-build/
# The following example shows a way to bundle a node package & serve it using Nginx,
# while keeping the image size small & the image build time shorter, using
# the Multi-Stage Builds
########### Stage 0
# the node 8 alpine image is ~63MB, while the node image is around ~670MB
# the alpine image is resource efficient, smaller in bundle size
# saves downloading time & precious bandwidth
FROM node:8.0.0-alpine