Sorting out (and finding!) connection resets on Linux:

Sorting out connection resets:

tcpdump -nn -v 'tcp[tcpflags] & (tcp-rst) != 0'

or

tcpdump -ilo -nn -v 'tcp[tcpflags] & (tcp-rst) != 0'

-n is to stop resolving DNS names

-nn is to stop resolving DNS names AND port numbers to names

This is really useful when an app is logging connection resets, but not telling you what it is trying to connect to in the first place.

Converting a Scratch game to an Android app

  1. Go to: https://scratch.mit.edu/ create an account
  2. (Make your game, I'll wait)
  3. Export to Android: Log into scratch, copy the project ID from the URL
  4. Go to: Phosphorus.github.io
  5. Put the project ID that you got above into the field provided.
  6. Click "Package Project"
  7. Copy the generated URL, keep it somewhere safe
  8. Go to https://www.appsgeyser.com/ (Set up account)
  9. Click "Create Now"
  10. Choose "Website" and paste in the generated URL for your project from the phosphorus site above.
  11. Name your app
  12. Choose/Upload an icon
  13. Add a description if you want, but to test, this is unnecessary
  14. Click Download on the right side, (preview may or may not work, don't worry if it won't preview)
  15. It will download a .apk file, this needs to get loaded onto your android device, Dropbox or Seafile are the easiest, USB transfers work too.
  16. Copy the .apk file into Seafile/Dropbox/USB
  17. Open Seafile/Dropbox on the android and find the .apk file
  18. Touch it to download it
  19. Touch install when prompted (You may need to enable "Install from unknown sources" and try again)
Open the game on Android and test
Note that since it is Android, and scratch has no idea that it will become a touch app, you have to use things like "Follow Mouse" and "Click" or "Right Click" in addition to regular collision detection.
Make the sprite follow the mouse/touch: https://wiki.scratch.mit.edu/wiki/Making_a_Sprite_Follow_the_Mouse

bash tip: collapse or parse a big text doc into individual sorted words from columns

Start with list.txt like:

server7858   server7858   server7858   server7858   server7861   server7860   server8310   server8310   server7863   server8311

server7859   server7859   server7859   server7859   server8781   server8676   server8677   server8677   server8679   server8782

Which has duplicates and long lines and crap. Run this:

rm list2.txt

rm list3.txt

for word in `cat list.txt`; do echo $word ; done |sort |uniq >> list2.txt

sed -ibak -e 's/ //g' list2.txt

cat list2.txt |sort|uniq > list3.txt

vi list3.txt

ta da!

if you need word counts and such, pipe it through wc before running uniq

more metadata, this one is hard to find:

bash

list

word

parse

parsing

text

columns

sorting

collapse

words

shell

script

split

line

lines

grep

Microsoft Visual Code won't start on CentOS 7/KDE

sudo cp /usr/lib64/libxcb.so.1 /usr/share/code/ libxcb.so.1

cd  /usr/share/code/

sudo sed -ibak -e 's/BIG-REQUESTS/_IG-REQUESTS/g'  libxcb.so.1

Had the exact same problem with Atom and this worked for that too.

Bash case switches

if [[ ${TAG_VALUE}XXX == "XXX" ]]; then

echo "TAG_VALUE was blank, exiting!"

exit

fi

case ${TAG_VALUE} in

1)

echo 'I am the first box'

;;

2)

echo 'I am the second box'

;;

3)

echo 'I am the third box'

;;

4)

echo 'I am the fourth box'

;;

5)

echo 'I am the fifth box'

;;

*)

echo 'I am another box higher than 5'

;;

esac

Reading tags from CLI or bash in ec2 instances

# To read the Name tag:

TAG_NAME="Name"

INSTANCE_ID="`./ec2-metadata -i | cut -f 2 -d " " `"

REGION="`././ec2-metadata -z | cut -f 2 -d " " `"

REGION=${REGION%?}

TAG_VALUE="`aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" "Name=key,Values=$TAG_NAME" --region $REGION --output=text | cut -f5`"

Gives:

set |grep TAG_VALUE

TAG_VALUE='brad test box'

# To see ALL tags to see WTF: (use region from above)

aws ec2 describe-tags --region us-east-1 --output=text

# To read the Created-by custom tag:

TAG_NAME="created-by"

INSTANCE_ID="`./ec2-metadata -i | cut -f 2 -d " " `"

REGION="`././ec2-metadata -z | cut -f 2 -d " " `"

REGION=${REGION%?}

TAG_VALUE="`aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" "Name=key,Values=$TAG_NAME" --region $REGION --output=text | cut -f5`"

set |grep TAG_VALUE

TAG_VALUE=test-kitchen

# To read the nifi-node-num custom tag:

TAG_NAME="nifi-node-num"

echo "TAG_NAME is: " ${TAG_NAME}

INSTANCE_ID="`./ec2-metadata -i | cut -f 2 -d " " `"

echo "INSTANCE_ID is: " ${INSTANCE_ID}

REGION="`././ec2-metadata -z | cut -f 2 -d " " `"

REGION=${REGION%?}

echo "REGION is: " ${REGION}

TAG_VALUE="`aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" "Name=key,Values=$TAG_NAME" --region $REGION --output=text | cut -f5`"

echo "TAG_VALUE is: " ${TAG_VALUE}

# You need the EC2 Metadata binary for the above to work

wget http://s3.amazonaws.com/ec2metadata/ec2-metadata

chmod u+x ec2-metadata

./ec2-metadata --help

Retrieving EC2 Metadata from within an EC2 instance

## Retrieving EC2 Metadata

wget http://s3.amazonaws.com/ec2metadata/ec2-metadata

chmod u+x ec2-metadata

./ec2-metadata --help

Usage: ec2-metadata

Options:

--all                     Show all metadata information for this host (also default).

-a/--ami-id               The AMI ID used to launch this instance

-l/--ami-launch-index     The index of this instance in the reservation (per AMI).

-m/--ami-manifest-path    The manifest path of the AMI with which the instance was launched.

-n/--ancestor-ami-ids     The AMI IDs of any instances that were rebundled to create this AMI.

-b/--block-device-mapping Defines native device names to use when exposing virtual devices.

-i/--instance-id          The ID of this instance

-t/--instance-type        The type of instance to launch. For more information, see Instance Types.

-h/--local-hostname       The local hostname of the instance.

-o/--local-ipv4           Public IP address if launched with direct addressing; private IP address if launched with public addressing.

-k/--kernel-id            The ID of the kernel launched with this instance, if applicable.

-z/--availability-zone    The availability zone in which the instance launched. Same as placement

-c/--product-codes        Product codes associated with this instance.

-p/--public-hostname      The public hostname of the instance.

-v/--public-ipv4          NATted public IP Address

-u/--public-keys          Public keys. Only available if supplied at instance launch time

-r/--ramdisk-id           The ID of the RAM disk launched with this instance, if applicable.

-e/--reservation-id       ID of the reservation.

-s/--security-groups      Names of the security groups the instance is launched in. Only available if supplied at instance launch time

-d/--user-data            User-supplied data.Only available if supplied at instance launch time.

Copying to or from AWS s3 buckets

(IAM policy may be required)

sudo apt-get install -y python-pip (for aws s3 CLI library)

sudo pip install awscli

aws s3 cp --region us-east-1 s3://some-secure-bucket/.some-dot-env-file output_file_path

Linux Bash recursive search and replace

find . -type f -print0 | xargs -0 sed -i 's/MAX036/MAX10853/g'

sed can also do multi-line replacements:

sed -i -e 's/jaiken/willb179\nnext line\nand the next/g'

# Search and replace existing keys

sed -i -e 's/auto-manage-instances-settling-period-ms.*$/auto-manage-instances-settling-period-ms=30000/' /zookeeper/exhibitor/exhibitor.properties

sed -i -e 's/observer-threshold.*$/observer-threshold=4/' /zookeeper/exhibitor/exhibitor.properties

# Add this since it isn't there to begin with (note there is no logic here to handle missing then add)

sed -i -e '$aauto-manage-instances-fixed-ensemble-size=3' /zookeeper/exhibitor/exhibitor.properties

linux bash shell script scripting config file ini text replace search substitute

testing udp with nmap

Testing NTP for example:

nmap -sU -p 123 2.amazon.pool.ntp.org

Top