Skip to content

Instantly share code, notes, and snippets.

Avatar

Hossain Khan we4tech

View GitHub Profile
View lower-case-words.txt
'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
PostgresSQL alter owner for all tables
View alter-owner.sql
-- 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 Oct 23, 2020
Golang test case vs return
View case.go
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
Iptables to forward egress (outbound) request to another IP and port
View iptables_rule.sh
##
# 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 Nov 4, 2019
How to use double quoted a string node
View yaml_preserved_string_quote.rb
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 Oct 30, 2019
Capture total memory usages by all unicorn process
View total_mem_usages_by_unicorn.sh
ps axu | grep "unicorn" | grep -v "grep" | awk '{split($0,a," "); s+=a[6]} END {print s}' | pbcopy
@we4tech
we4tech / run_docker.go
Created Jun 9, 2019
Use docker client to handle STDIN and STDOUT from a running container
View run_docker.go
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 Jun 4, 2019
Execute docker container with bash and binds to the streams
View glide.yaml
package: we.co/tools/oktaremember
import:
- package: github.com/moby/moby
version: master
View Gemfile
# 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'
View create_admin_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"
}