Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View farrokhi's full-sized avatar
🚀

Babak Farrokhi farrokhi

🚀
View GitHub Profile
@farrokhi
farrokhi / curl-web-perf.md
Last active December 22, 2020 07:25
Poor man's Connection and Transfer speed measurement using curl

Save this as curl-perf.cfg:

{\n
"time_connect":       %{time_connect},\n
"time_pretransfer":   %{time_pretransfer},\n
"time_starttransfer": %{time_starttransfer},\n
"time_total":         %{time_total},\n
"size_request":       %{size_request},\n
"size_upload":        %{size_upload},\n
"size_download": %{size_download},\n
@farrokhi
farrokhi / disable_dsstore.sh
Created September 17, 2020 09:18
Disable DS_Store file creation on USB disks and network shares
#!/bin/sh
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
defaults read com.apple.desktopservices
@farrokhi
farrokhi / go-build.md
Created January 20, 2020 13:03
Building go
@farrokhi
farrokhi / mem_swap_linux.md
Created January 19, 2020 11:19
memory usage and swap investigation in linux
grep -A1 Normal  /proc/zoneinfo  ; echo "--"; sysctl vm.min_free_kbytes ; echo "--"; numactl -H | grep free
@farrokhi
farrokhi / freebsd-ntpd.md
Created January 19, 2020 11:18
Bind FreeBSD ntpd to given IP address

In order to avoid FreeBSD ntpd listen on wildcard interface, add following lines to /etc/ntp.conf:

interface ignore wildcard
interface listen 10.0.0.1
@farrokhi
farrokhi / cscope.md
Created January 19, 2020 11:17
Setting up cscope for a (large) C project

build/update database:

cd $PROJ_DIR
find . -path .git -path .svn -prune -o -name "*.[ch]" > cscope.files
cscope -bqk

browse code:

cscope -d
@farrokhi
farrokhi / cpu-mem-online.sh
Last active September 13, 2021 09:29
Turn all CPU and RAM online in Linux under VMWare
#!/bin/bash
# Based on script by William Lam - http://engineering.ucsb.edu/~duonglt/vmware/
# Bring CPUs online
for CPU_DIR in /sys/devices/system/cpu/cpu[0-9]*
do
CPU=${CPU_DIR##*/}
echo "Found cpu: '${CPU_DIR}' ..."
CPU_STATE_FILE="${CPU_DIR}/online"
if [ -f "${CPU_STATE_FILE}" ]; then
@farrokhi
farrokhi / ensure-ssh-agent.sh
Created January 19, 2020 11:16
Ensure ssh-agent is running and you have proper env variables set (re-use if possible)
AGENT_SCRIPT=${HOME}/load-agent.sh
while true; do
[ -r ${AGENT_SCRIPT} ] && source ${AGENT_SCRIPT}
if [ -n "$SSH_AGENT_PID" ]; then
# ensure the variable actually reflects a running ssh-agent process
ps -p $SSH_AGENT_PID | grep -q ssh-agent$ && break
fi
# SSH_AGENT_PID is either not set or has stale PID
echo "Running ssh-agent"
@farrokhi
farrokhi / cleanup_memory.sh
Created January 19, 2020 11:15
Enforce dropping page cache and trigger memory page compactor for Linux MM
#!/bin/sh
set -u
NUMA_BEFORE=`numactl -H | grep free:`
SLAB_BEFORE=`grep Normal /proc/buddyinfo`
printf "Dropping page cache..."
sysctl -qw vm.drop_caches=1
echo
@farrokhi
farrokhi / hugepages_settings.sh
Created January 19, 2020 11:14
Calculate recommended value for HugePages/HugeTLB in Linux
#!/bin/bash
#
# hugepages_settings.sh
#
# Linux bash script to compute values for the
# recommended HugePages/HugeTLB configuration
#
# Note: This script does calculation for all shared memory
# segments available when the script is run, no matter it
# is an Oracle RDBMS shared memory segment or not.