Skip to content

Instantly share code, notes, and snippets.

View we4tech's full-sized avatar

Hossain Khan we4tech

View GitHub Profile
'shun
'slid
'twas
2,4-d
30-30
a-cry
a-day
a-hey
a-one
a-row
@we4tech
we4tech / alter-owner.sql
Last active May 5, 2022 19:51
PostgresSQL alter owner for all tables
-- Geneate query
SELECT format('alter table %s owner to root;', tablename) FROM pg_tables WHERE schemaname = 'public'
-- On psql execute \gexec to eval all above queries.
\gexec
-- Generate query for sequences
select format('alter sequence %s owner to root;', sequencename) FROM pg_sequences WHERE schemaname = 'public';
@we4tech
we4tech / case.go
Last active October 23, 2020 15:09
Golang test case vs return
package envars
import "errors"
var (
ErrorVaultSecretNotFound2 = errors.New("vault secret not found")
ErrorCannotFindValue2 = errors.New("can not find value")
)
func IsNotFoundError2(err error) bool {
@we4tech
we4tech / iptables_rule.sh
Created May 4, 2020 02:07
Iptables to forward egress (outbound) request to another IP and port
##
# Redirect all outbound requests from port 80 to a specific IP and port.
#
iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination $DEST_SERVER:$DEST_PORT
@we4tech
we4tech / yaml_preserved_string_quote.rb
Created November 4, 2019 19:29
How to use double quoted a string node
class YAMLPreservedStringQuote
def initialize(*doublequoted_nodes)
@doublequoted_nodes = doublequoted_nodes
end
def load(str)
ast = YAML.parse_stream(StringIO.new(str))
ast.grep(Psych::Nodes::Mapping).each do |node|
node.children.each_slice(2) do |key, value|
@we4tech
we4tech / total_mem_usages_by_unicorn.sh
Created October 30, 2019 19:14
Capture total memory usages by all unicorn process
ps axu | grep "unicorn" | grep -v "grep" | awk '{split($0,a," "); s+=a[6]} END {print s}' | pbcopy
@we4tech
we4tech / run_docker.go
Created June 9, 2019 03:51
Use docker client to handle STDIN and STDOUT from a running container
package main
import (
"bufio"
"context"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"io"
@we4tech
we4tech / glide.yaml
Created June 4, 2019 19:10
Execute docker container with bash and binds to the streams
package: we.co/tools/oktaremember
import:
- package: github.com/moby/moby
version: master
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem 'rack'
gem 'dry-container'
gem 'minitest'
gem 'mocha'
@we4tech
we4tech / create_admin_rabbitmq_user.sh
Created October 26, 2018 14:40
create_rabbitmq_user.sh
#!/bin/sh
API_USER="<USER>:<PASSWORD>"
API_URL="https://<SOME_SERVICE>.cloudamqp.com/api"
VHOST="<VHOST>"
__colored_echo()
{
printf "\033[$1m$2\033[0m\n"
}