Skip to content

Instantly share code, notes, and snippets.

nhm tanveer hossain khan (hasan) we4tech

Block or report user

Report or block we4tech

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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"
}
@we4tech
we4tech / comparison-2.4.1.md
Last active Sep 14, 2018
Benchmark ruby eval VS RubyVM::InstructionSequence
View comparison-2.4.1.md

Ruby 2.4.1

eval-vs-iseq

Eval (global) | 0.120000 | 0.120000 | 0.140000 | 0.140000 | 0.150000 | 0.150000 | 0.150000 | 0.150000 | 0.140000 | 0.140000 | 0.190000 | 0.150000 | 0.150000 | 0.150000 | 0.120000 | 0.150000 | 0.130000 | 0.130000 | 0.140000 | 0.150000 | 0.160000 | 0.150000 | 0.150000 | 0.150000 | 0.160000 | 0.130000 | 0.150000 | 0.140000 | 0.130000 | 0.160000 | 0.140000 | 0.140000 | 0.150000 | 0.140000 | 0.160000 | 0.150000 | 0.140000 | 0.140000 | 0.150000 | 0.130000 | 0.140000 | 0.140000 | 0.120000 | 0.140000 | 0.140000 | 0.130000 | 0.160000 | 0.130000 | 0.140000 | 0.140000 | 0.130000 | 0.130000 | 0.140000 | 0.130000 | 0.140000 | 0.130000 | 0.130000 | 0.130000 | 0.140000 | 0.130000 | 0.140000 | 0.140000 | 0.130000 | 0.140000 | 0.140000 | 0.130000 | 0.160000 | 0.120000 | 0.130000 | 0.130000 | 0.140000 | 0.130000 | 0.140000 | 0.130000 | 0.130000 | 0.130000 | 0.130000 | 0.13

@we4tech
we4tech / dtrace_for_ruby_c_call.d
Created Aug 16, 2018
Ruby Dtrace probe script that fires whenever a cmethod is about to call
View dtrace_for_ruby_c_call.d
ruby*:::cmethod-entry
{
printf("%s(%d) called from %s#%s\nSource:%s:%d\n", execname, pid, copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3)
}
@we4tech
we4tech / chain_middelware_call.rb
Created Aug 7, 2018
How to chain middleware call in Ruby?
View chain_middelware_call.rb
# Create a middleware class
class Middleware
def call(*args)
puts "Args: #{args}"
yield
end
end
def call_in_chain(chain)
traverse_chain = lambda do
You can’t perform that action at this time.