Skip to content

Instantly share code, notes, and snippets.

@brianz
Last active August 11, 2016 04:35
Show Gist options
  • Select an option

  • Save brianz/deb45115a8b09704c8d4beee38af3104 to your computer and use it in GitHub Desktop.

Select an option

Save brianz/deb45115a8b09704c8d4beee38af3104 to your computer and use it in GitHub Desktop.

Revisions

  1. brianz revised this gist Aug 11, 2016. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions tech-scratch-pad.md
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,11 @@ linux: netstat -lnptu
    mac: netstat -a -p tcp
    ```

    ## Find what is listening on a port

    ```
    lsof -Pnl +M -i4
    ```
    ## Reset postgres pkey sequences

    ```
  2. brianz revised this gist Aug 2, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion tech-scratch-pad.md
    Original file line number Diff line number Diff line change
    @@ -35,10 +35,11 @@ scutil --dns
    find . -name '*.py' -exec sed -i '' -e "s/OLD_PATTERN/NEW_PATTERN/g" {} \;
    ```

    ## Add a user into an existing group
    ## Add/remove users into/out of groups

    ```
    usermod -a -G GROUP_NAME USER_NAME
    usermod -G "" USER_NAME
    ```

    ## Read an SSL certificate
  3. brianz revised this gist Aug 2, 2016. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions tech-scratch-pad.md
    Original file line number Diff line number Diff line change
    @@ -35,6 +35,12 @@ scutil --dns
    find . -name '*.py' -exec sed -i '' -e "s/OLD_PATTERN/NEW_PATTERN/g" {} \;
    ```

    ## Add a user into an existing group

    ```
    usermod -a -G GROUP_NAME USER_NAME
    ```

    ## Read an SSL certificate

    ```
  4. brianz revised this gist Aug 2, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions tech-scratch-pad.md
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,10 @@

    ## List open ports

    ```
    linux: netstat -lnptu
    mac: netstat -a -p tcp
    ```

    ## Reset postgres pkey sequences

  5. brianz created this gist Aug 2, 2016.
    174 changes: 174 additions & 0 deletions tech-scratch-pad.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,174 @@
    ## Sum column using awk

    `cat count.txt | awk '{sum+=$1} END {print sum}'`

    ## List open ports

    linux: netstat -lnptu
    mac: netstat -a -p tcp

    ## Reset postgres pkey sequences

    ```
    SELECT pg_catalog.setval(pg_get_serial_sequence('TABLE_NAME', 'id'), (SELECT MAX(id) FROM TABLE_NAME)+1);
    ```

    ## List connected hosts

    ```
    netstat -n -A inet
    netstat -n -A inet | awk '{print $5}' | tr ':' ' ' | awk '{print $1}' | sort | uniq -c
    ```

    ## DNS Stuff

    ```
    dscacheutil -q host -a name admin.ccdev.vg
    scutil --dns
    ```

    ## In-place replacement

    ```
    find . -name '*.py' -exec sed -i '' -e "s/OLD_PATTERN/NEW_PATTERN/g" {} \;
    ```

    ## Read an SSL certificate

    ```
    openssl x509 -in public.pem -text -noout
    ```

    ## Execute a command for a user who has no login shell

    ```
    su -s /bin/bash -c '/path/to/your/script' testuser
    ```

    ## Remove virtual box virtual interfaces

    ```
    VBoxManage hostonlyif remove vboxnet1
    ```

    ## Purge all queues from rabbitmq

    ```
    for q in ` sudo rabbitmqctl list_queues | awk '{print $1'} | egrep "d16|celery"`;
    do celery amqp queue.purge $q;
    done
    ```

    ## Display status of loaded kernel extensions

    ```
    man kextstat
    kextstat | grep -i usb | awk '{print $6}' | sort
    ```

    ## Display the system message buffer

    ```
    dmesg
    ```

    ## Setup vim plugins

    https://github.com/tpope/vim-pathogen

    ## Push up to a specific commit

    ```
    git push origin SHA:branch_name
    ```

    ## Run a simple HTTP server using nc

    ```
    nc -kl 5432 -c 'echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\n";echo "<p>How are you today?</p>"'
    while true ; do nc -l 80 < index.html ; done
    ```

    ## Find time a process has been running

    ```
    for pid in `ps auwwwx | grep uwsgi | grep clearcare.yaml | awk '{print $2}'`; do
    ps -p $pid -o etime=
    done
    ```

    ## Add/remove 200ms delay to a network interface

    ```
    root@ccdev# tc qdisc add dev lo root netem delay 200ms
    root@ccdev# tc qdisc del dev lo root
    ```

    ## Correct perms for ssh files/dirs

    ```
    chmod 700 /home/your_user/.ssh
    chmod 600 /home/your_user/.ssh/authorized_keys
    ```

    ## Get IP address for a given network device

    ```
    ifconfig eth1 | grep "inet addr" | awk '{ print substr($2,6) }
    ```

    ## ssh-agent on the mac

    ```
    sudo launchctl load -w /System/Library/LaunchAgents/org.openbsd.ssh-agent.plist
    sudo launchctl unload /Path
    ```


    ## To start a differently named key at login:

    ```
    ssh-add -K ~/.ssh/some_key
    ```

    ## Strip multiple characters with sed

    ```
    sed 's/[<>,]//g'
    ```

    ## Default a command line arg in bash

    ```
    FOO=${VARIABLE:-default}
    ```

    ## Patching in Git

    ```
    git apply --check tests.patch
    git apply -v --check tests.patch to see where it's blaring
    ```

    ## Getting LOC changed in a commit range

    ```
    git log --author=Brian --since="Feb 15, 2014" --no-merges --numstat --pretty="%H" -- tests | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'
    ```

    ## OS X

    ```
    sudo killall -HUP mDNSResponder
    ```

    ## Ubuntu

    Uninstall and purge a debian pakages…removes conf files: dpkg -P elasticsearch
    Install a package from a file: dpkg -i elasticsearch-0.90.7.deb

    ## Reset guest additions version

    ```
    VBoxManage guestproperty set ae63d283-bd8d-44ea-be05-e61c9b2a8f73 /VirtualBox/GuestAdd/Version
    ```