Bruno Bronosky

An occasional outlet for my thoughts on life, technology, motorcycles, backpacking, kayaking, skydiving...

Friday, February 27, 2015

Make your .profile or .bashrc idempotent.

If you are like me, you have about a dozen lines in your .profile the prefixes directories onto your $PATH environment variable. Have you ever noticed how nasty your $PATH variable gets after a few sub shells or re-sourcing your .profile after and edit? I just added an alias and then did...
. ~/.profile
...and boy things where ugly in the $PATH. So, how do you make things idempotent (able to be called mutliple times without side effects)? Well, your first modification to $PATH is probably something like:
export PATH=~/bin:$PATH
Then you probably have a bunch of others like:
export PATH=/usr/local/heroku/bin:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
Just change that first one to this:
export PATH=~/bin:$PATH_ORIGINAL
That means you create $PATH_ORIGINAL once and only once. Then you use it as the starting point for all your path appendages later.

Try doing this before and after the change and see what you get... You may be shocked by the before.
echo $PATH
for i in $(seq 10); do source .profile; done
echo $PATH

Wednesday, August 13, 2014

Seed your browser's autocomplete with important info

What do you do when you get that confirmation number after booking an airline ticket? Do you write it on a Post-It note? Lot of good that will do you when you are rushing to the airport. Do you just ignore it and trust that you got everything in an email? If your email is like mine, you may have a hard time finding it when you need it.

What you can do is copy the confirmation number "80085" and then navigate to the airline's website then add** the confirmation number as a query string Make sure that the query string is still there. Bookmark it and give it a helpful name like "Delta Flight" instead of the default "Delta Air Lines - Airline Tickets and Flights to Worldwide Destinations". Then, if you use an awesome browser like Google Chrome, your bookmarks will be synced across all of your devices. That way if you bookmarked this on your computer, when you type in "delta" on your phone you get...

Use the arrow on the right side to move the address to the address box rather than navigating straight there. Then you can select and copy just the confirmation number and have it ready to paste into the "Online Check In" form.

This is useful for lots of things. I use it for anything that I know I'm going to want to remember when I'm in a browser. I use Evernote, but not for this. I don't need the extra steps of going to the website on my phone, launch Evernote, find the note, copy the confirmation number, switch back to the browser, then paste.

**then add - I say this because sometimes the address you type. For example, gets redirected to a different address, like, and the query string may get lost. This is not the case with Delta, but it may be with others.

Thursday, February 27, 2014

Linux Oneliners

I am moving entries of my old one-liners text file to a web page for easier access.
# mount cdrom
[ -d "/mnt/cdrom" ] || mkdir -p /mnt/cdrom; mount /dev/cdrom /mnt/cdrom/

# mount a samba/cifs share (hostess is used by vmware in NAT mode)
user=rbronosky; [ -d "/mnt/smb" ] || mkdir -p /mnt/smb; mount -t cifs //hostess/$user -o username=$user /mnt/smb

# remove the leading path from a find
find . | sed 's/^..//'

# basic bash for-looping
for f in $(cat changed_files.txt) ;do vimdiff trunk/$f branches/iteration3/$f; done;
# if you have spaces in filenames
find . -type f |sed 's/^..//'|while read f; do ls "$f"; done
# or
(IFS=$'\n';for f in $(find . -type f) ; do cat ../Logs2/$f $f>../LogsCat/$f; done;)

# version number comparison using the power of the Python standard lib
[ "1" == "$(python -c "from distutils.version import *;print int(LooseVersion('3')>=LooseVersion('2.5.1'))")" ] \
&& echo Yes || echo No
# above is True, below is False...
[ "1" == "$(python -c "from distutils.version import *;print int(LooseVersion('2.3')>=LooseVersion('2.5.1'))")" ] \
&& echo Yes || echo No

# basic anonymous cvs
cvs -z3 ls

# make wget use filenames as suggested by the HTTP header Content-Disposition (requires wget>=1.11)
# becomes ps_color.vim
echo -e '\ncontent-disposition=on'>>~/.wgetrc

# copy files using ONLY ssh, not scp or sftp
tar cvf - $files_and_dirs_to_send | gzip | ssh $destination_server "cd $destination_dir; tar zxvf -"
# or to leave them compressed on the remote side...
tar cvf - $files_and_dirs_to_send | gzip | ssh $destination_server "cat > $destination_dir\archive.tar.gz"

### Help dad out via ssh (and telephone) ###
## I configure my router to forward $secret_port to port 22 on my machine.
## Because Ubuntu does not default to having and ssh server, I tell dad to do:
sudo apt-get install openssh-server
## I to tell dad to connect to my computer via:
ssh -p $secret_port -R $secret_port:localhost:22 -N $my_username@$my_router_ip & screen; kill %1
## I connect to his computer via:
ssh -v -p $secret_port $dad_username@localhost screen -x
## Now we are both looking at the same shell.  We can both type and collaborate.

## Convert/get a date from a timestamp using only Gnu Date
date -d @1199163600

## Sync the date of one server to that of another.  (Useful when firewalls prevent you from using NTP.)
sudo date -s  "$(ssh "date -u")"

## Get 255 random chars from /dev/random
uuencode -m - < /dev/random |sed 1d|tr -d \\n|head -c 255
# That is Base64 [/+a-zA-Z0-9], but you can add a substirution  to the sed.
# This one limits it to hex chars:
uuencode -m - < /dev/random |sed '1d;s/[^0-9A-F]//g'|tr -d \\n|head -c 255
# However, for storing into a DB, I like to keep the newlines so:
uuencode -m - < /dev/random |sed 1d|head -c 255

# Time stamp for a file name
date +%s
# a readable one
date +%Y%m%d%H%M%S

# Get ip addresses for all network interfaces
ifconfig | awk -e '/^[a-z]+/{sub(":",""); f=$1} /inet /{print f " " $2}'

# DiG format as a clean single line for batch processing

dig +nocmd +noall +answer

Thursday, October 4, 2012

Apple could have scored a homerun with their connector changes

What I can't understand is why, in the same year Apple changed both it's iPhone connector and it's mag safe connector and yet it didn't consolidate their profile. They could have created a single connector that would allow:

Wednesday, December 14, 2011

Why I'm done with facebook and you should be too

I promised to do a complete writeup on this and I'm running out of time. Let's start with an outline. 
  1. Involuntarily posting to facebook when you view an "article" or web page.
  2. Requiring me to install an "app" to view one of these "articles" that someone else [involuntarily] shared.
  3. External sites requiring me to install their facebook "app" to post comments on their site.
  4. External sites requiring me to install their facebook "app" to view comments on their site.
  5. facebook is making a move to be the only social service you use.
    1. facebook is not great at everything.
    2. We ought to be able to reward facebook with our loyalty for the services where they have earned it.
    3. We ought to be able to reward flickr with our loyalty for the service where they excel.
  6. facebook is making a move to use your friends as enforcers of their homogeneous vision.
    1. If your friend choses facebook, you must also chose facebook.
    2. If your friend is satisfied with the interface and the policies of facebook, they should be able to choose to use facebook to publish their content and consume yours.
    3. If you prefer the interface of another service, you should be able to choose to use that service to publish your content and consume your friend's.
  7. Their are hundreds of ways to consume RSS/Atom feeds.
    1. If RSS were just being invented today by facebook, you would only be able to consume it with facebook.
  8. Tim Berners-Lee had a vision for an open web.
    1. I owe my life to this vision.
    2. facebook is the antithesis of this vision.
  9. If the open web hadn't been a success; If facebook had come along instead; If AOL had won instead of falling; I would be stuck in the coal mining country of Appalachia with no industry.
These are a few of the points I'd like to cover. This is just a collection of thoughts. I wanted to get them down while they are fresh. The writeup will come. I have until January 1st, when I delete my facebook account. (Not sure how that is going to work yet. I want my facebook friends to read the article when it is complete.)

Wednesday, March 9, 2011

git Oneliners

This started out as a tweet but quickly became a collection of one-liners. Some of this may be able to be accomplished with switches to regular git commands, but I can write awk faster than I can read a man page. Sad but true.

# add files to the index which `git status` lists as untracked:
git add $(git status | awk 'p==1{print $2}; /git add /{p=1}')

# remove files from the index which `git status` lists as deleted:
git rm $(git status | awk '$2=="deleted:" && p==1{print $3}; /git add\/rm /{p=1}')

# add files to the index which `git status` lists as ``Changed but not updated``/modified:
git add $(git st | awk '$2=="modified:" && 'p==1{print $3}; /git add /{p=1}')

# checkout the penultimate commit (used for stepping backwards through commit to find the introduction of a bug)
git checkout $(git log | awk '/^commit /{if(i++>0){print $2; exit}}')
# That was my first day git user approach. Now I know to use
git checkout HEAD~1
# Yes, I know about HEAD^, but because HEAD^2, HEAD^3, etc. don't work I chose tilde notation.

# create a quick git repo with 50 commits for trying out git hackery
d=/tmp/git_hack; rm -rf $d; git init $d; cd $d; for i in {1..50}; do git log | md5 >test.txt; git add .; git commit -m "commit $i"; done >/dev/null

# rebase 1 commit out of a branch
read -p "hash? " hash; git rebase --onto $hash~1 $hash HEAD; files=$(git st -s | sed '/^UU/!d;s/^UU //'); [[ -n $files ]] && (git co --theirs $files; git add $files; git rebase --continue)

Sunday, December 19, 2010

Android Oneliners

The next time I have to setup a non-Eclipse (aka: VIM) Android development environment, I'm going to want to remember these commands.

# android PATH
export PATH=$PATH:/Applications/Android/sdk/android-sdk-mac_86/platform-tools:/Applications/Android/sdk/android-sdk-mac_86/tools

# complete the SDK install (adb and all other platform-tools will be missing without this)
android update sdk

# create an Android Virtual Device
android create avd -c 256M -t $(android list | awk '$1=="id:"{l=$2} END{print l}') -n latest

# start the emulator
emulator -avd Captivate2.1u1 -no-boot-anim -scale 0.65 -show-kernel
# or
emulator -avd latest -no-boot-anim

# kill the adb server (for when the adb server was started before your emulator was launched)
adb kill-server

# add sdk.dir to ant settings
sed -i.bak '/^sdk\.dir=/d'; echo "sdk.dir=$(which adb | sed 's|/[^/]*/[^/]*$||')" >>

# compile in debug mode
ant debug

# install a package in the emulator replacing the existing install
adb -e install -r bin/HelloWorld-debug.apk 


TEMPLATE ERROR: No widget data found for Profile1