Skip to content

Instantly share code, notes, and snippets.

View lggomez's full-sized avatar
:fishsticks:
On a mental sabbatical

Luis Gabriel Gomez lggomez

:fishsticks:
On a mental sabbatical
View GitHub Profile
@lggomez
lggomez / tcpdump cheat sheet
Created July 6, 2023 12:56 — forked from githubfoam/tcpdump cheat sheet
tcpdump cheat sheet
----------------------------------------------------------------------------------------------------
tcpdump -s 0 #capture entire etherner header and IP packet
tcpdump -ni tap55ec3c7f-91 ip6 #locate the ICMPv6 packets
tcpdump -s0 -n -i any -w /tmp/$(hostname)-smbtrace.pcap #if the SMB client or SMB server is a Unix host,Troubleshooting Server Message Block (SMB)
tcpdump -D #Print the list of the network interfaces available on the system and on which tcpdump can capture packet
tcpdump -X -vvv -n -i eth0
@lggomez
lggomez / stacktrace.go
Created July 26, 2021 15:55 — forked from lggomezml/stacktrace.go
Get a compact stacktrace without the callsites
var newLine = []byte("\n")[0]
var goPathPrefix = "\t/go/src/"
var goUsersPrefix = "\t/Users/"
func dumpStacktrace(skipLines int) []byte {
stack := debug.Stack()
init, lines := 0, 0
// First pass: seek stack start skiping lines if necessary
if skipLines > 0 {
@lggomez
lggomez / go_cpu_memory_profiling_benchmarks.sh
Last active July 2, 2021 14:54 — forked from arsham/go_cpu_memory_profiling_benchmarks.sh
Go cpu and memory profiling benchmarks. #golang #benchmark
# Run tests for package in current location
go test -run=. -bench=. -benchtime=5s -count 5 -benchmem -cpuprofile=cpu.out -memprofile=mem.out -trace=trace.out ./ | tee bench.txt
go tool pprof -http :8080 cpu.out
go tool pprof -http :8081 mem.out
go tool trace trace.out
go tool pprof $FILENAME.test cpu.out
# (pprof) list <func name>
# go get -u golang.org/x/perf/cmd/benchstat
@lggomez
lggomez / Dockerfile
Created May 26, 2021 14:12
Base install steps for golang + oracle support
# Install tzdata (used by golang timezones) along with other base & useful commands
RUN INSTALL_PKGS="wget diffutils net-tools bind-utils iproute nmap procps-ng vim-enhanced nano less libidn git gcc tzdata libaio make tzdata git" && \
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y && \
dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
dnf update -y && \
dnf clean all -y && \
rm -rf /var/cache/dnf/*
# Install Oracle Instant Client, SQLPlus and GCC for golang interop
ARG OIC_RELEASE=19
@lggomez
lggomez / gotest.sh
Last active July 26, 2021 15:27
Generic go project pre commit runner
echo "** running formatters"
goimports -e -w -local my.domain.corp $(find . -type f -name '*.go' -not -path "./vendor/*")
# use gofumpt if available, see https://github.com/mvdan/gofumpt
if ! command -v gofumpt -version &> /dev/null
then
echo "gofumpt could not be found, defaulting to gofmt"
gofmt -s -w $(find . -type f -name '*.go' -not -path "./vendor/*")
else
echo "gofumpt found, executing as formatter"
@lggomez
lggomez / gosetup.sh
Last active December 2, 2022 19:51
Easy setup to switch between go versions (1.11+) with gvm - go version manager
#!/usr/bin/env bash
echo $BASH_VERSION
# GVM readme: https://github.com/e-nikolov/gvm/blob/master/README.md
bash < <(curl -s -S -L https://raw.githubusercontent.com/e-nikolov/gvm/master/binscripts/gvm-installer)
source $HOME/.gvm/scripts/gvm
# To view available versions to install run 'gvm listall' later on
# Older versions you'll probably not need
@lggomez
lggomez / mass_git_updater.py
Last active June 30, 2021 15:08
[Python] Mass git updater
__author__ = "lggomez"
__copyright__ = "Copyright 2017"
__credits__ = ["Luis Gomez"]
__license__ = "MIT"
__version__ = "0.3"
__maintainer__ = "lggomez"
__status__ = "Production"
import argparse
import os
public class MyStack<T>
{
readonly int m_Size;
readonly T[] m_Items;
int m_StackPointer = 0;
public MyStack(int size)
{
@lggomez
lggomez / GetTypeMethods
Created April 4, 2017 19:57
Get non System.Object methods from a given type parameter
private static List<MethodInfo> GetTypeMethods<T>()
{
List<MethodInfo> interfaceMethods = new List<MethodInfo>();
var targetType = typeof(T);
foreach (MethodInfo method in targetType.GetMethods() )
{
if (!method.IsSpecialName &&
!new List<string> { "tostring", "gethashcode", "equals", "gettype", "finalize", "memberwiseclone" }.Any(method.Name.ToLowerInvariant().Contains))
{
@lggomez
lggomez / UnityContainerExtensions.cs
Last active March 4, 2021 10:36
Extensions for Unity containers that add basic support for aspect and interceptor registrations, among other helpers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Remoting;
using Bootstrapper.IoC.Behaviors;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;