Skip to content

Instantly share code, notes, and snippets.

@rkachowski
Last active June 11, 2019 14:53
Show Gist options
  • Save rkachowski/c4ae8865d307c6fee055 to your computer and use it in GitHub Desktop.
Save rkachowski/c4ae8865d307c6fee055 to your computer and use it in GitHub Desktop.
things i keep forgetting

ruby

Get match data for each regex occurance in string

  • "string to check".to_enum(:scan, /\s/).map { Regexp.last_match }

bash

generate hex chars

  • for i in $(seq 1 255); do echo -n $(printf '\\x%02x' $i); done

list env + shell vars but not functions

  • ( set -o posix ; set )

Rename multiple files

  • for i in PATTERN; do echo mv $i ${i/old/new}; done

Last argument of previous command

!$

Misc

  • ctrl + a - start of line (home)

  • ctrl + w - delete back to whitespace

  • ctrl + x, e - open editor

  • (set -o posix; set) list all shell and env vars (no functions)

  • find src/ -name *cs | xargs grep --no-filename using | sort | uniq get all the using statements in the cs files

  • reset; stty sane; tput rs1; clear; echo -e "\033c" - unscrew corrupted terminal

  • openssl aes-256-cbc -md sha256 -e -in file -out file-cipher -k $KEY - encrypt a file

  • openssl aes-256-cbc -md sha256 -d -in file-cipher -k ${KEY} >> file - decrypt

sed

Replace text across various files

  • $ grep -irl ccbResources/ccb . | xargs -I[] sed -i '' "s/ccbResources\/ccb/Resources\//g" []

print text found in lines between start and end, and quit sed once end is found

  • sed -n '/start/,/end/p;/end/q' $filename

git

delete remote tag

  • git tag -d <tag name> && git push origin :refs/tags/<tag name>

the best gitconfig

[alias]
    s = status
    cma = commit -am
    cm = commit -m
    cont = rebase --continue
    dumbass = commit --amend
    forget = update-index --assume-unchanged
    unforget = update-index --no-assume-unchanged
    root = rev-parse --show-toplevel
    lg = "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset' --abbrev-commit"
    ignored = ls-files -o -i --exclude-standard
    fetch-pr = "!f() { git fetch $1 refs/pull/$2/head:pr-$2; }; f"

awk

Filter csv

  • awk -F ',' 'BEGIN {OFS=","} { if( $1 == "COOL_CONDITION") print }' csv_file.csv - osx

generate file of a specific size

dd if=/dev/zero of=output.dat bs=1024000 count=1 - change count to number of megabytes

date

  • date +'%d %B %Y' get "30 September 2015" or w/e as output

fugitive

Stage part of a file

  • :Gdiff :diffget

Status

  • :Gstatus
  • - - stage / unstage (reset) file
  • CTRL+N - next file

jquery

  • $('img[src$=".jpg"]') - get all img tags with src attribute ending in '.jpg' ($= is 'attribute ends with' )

android

Install Referrer testing

  • adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n <packagename>/<java classname" --es "referrer" "referrer=value&stuff=url"

check jni

  • adb shell setprop debug.checkjni 0 - change 1 or 0 to activate/deactivate

keep display on when plugged in (without going through ui)

  • adb shell settings put global stay_on_while_plugged_in 3

generate keystore

  • keytool -genkey -v -keystore keystore.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

ios

  • xcrun simctl addmedia booted ./qrcode.png - upload qrcode to camera roll

misc

  • generate self signed ssl certificate openssl req -newkey rsa:2048 -nodes -sha256 -keyout keyname.key -x509 -days 3650 -out certname.crt -subj "/C=US/ST=NewYork/L=NewYork/O=IT/CN=*.wildcard.domain" -config <(cat /System/Library/OpenSSL/openssl.cnf <(printf '[SAN]\nsubjectAltName=DNS:*.wildcard.domain'))

  • then some diffie hellman openssl dhparam -out dhparam.pem 2048

  • ssh port forwarding to localhost ssh -L REMOTE_PORT:127.0.0.1:LOCAL_PORT username@remote.host

  • symbolicate ios crash DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer symbolicatecrash -d <path to dsym> -o <symbolicated>.crash <original>.crash

geometry

  • approximate drawing a circle
int inc = 5;
for (float ang = 0; ang < 360; ang +=inc)
    float rad = radians(ang);
    x = centX + (radius * cos(rad));
    y = centY + (radius * sin(rad));
    point(x,y);
}

(change radius every step for spiral)

image magick

  • split something large into smaller convert -crop widthxheight source.png icon_%d.png

screen

  • create screen ctrl+a, c
  • next screen ctrl+a, n
  • detach screen ctrl+a, d
  • kill everything ctrl+a, \

patch

  • apply a git patch to a different tree git diff HEAD^ [file or whatever to get the diff] >> [patchfilename] && patch [location to apply patch] [patchfile]

svg

  • generate a small icon for text
  function svgForText(txt){
        return '<svg width="24" height="24" ' +
            'xmlns="http://www.w3.org/2000/svg">' +
            '<rect stroke="white" fill="#640012" x="1" y="1" width="22" ' +
            'height="22" /><text x="12" y="18" font-size="12pt" ' +
            'font-family="Arial" font-weight="bold" text-anchor="middle" ' +
            'fill="white">'+txt+'</text></svg>';
     }

osx

what year was this mac made?!

curl -s http://support-sp.apple.com/sp/product?cc=`system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' | cut -c 9-` | sed 's|.*<configCode>\(.*\)</configCode>.*|\1|'

find method in library

otool -tV <lib path> -p "-[ClassName methodName]"

security

list open ports by process

  • netstat -tulpn
  • osx sudo lsof -PiTCP -sTCP:LISTEN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment