Saturday, August 18, 2012

Monday, September 12, 2011

Searching code for a string not in the comments...

Every few months I need to search my code for a string but there are a bunch of references to that code in the comments and I want a regex that will remove those for me. I forget how to do it so every few months I have to figure it out again, well hopefully I will remember when I put it here:


>cat example.txt

token asdf asdf @OK
asdf token asdf @OK
//token @BAD
asdf token asdf // asdf token asdf @OK
// This is a token @BAD
/some/dir/token @OK
aaa token try again @OK
aaa token try again @OK
aaaa token try again @OK

>egrep '^.?([^/][^/])*token' example.txt

token asdf asdf @OK
asdf token asdf @OK
asdf token asdf // asdf token asdf @OK
aaaatoken try again @OK
aaa token try again @OK
aaaa token try again @OK

Thursday, April 21, 2011

USB3 Speeds

I read this little post about USB3 speeds that I found very interesting since I am working on designing USB3 hubs.


COUNTERPOINT
by Chris Karr, Director, Software/Firmware Engineering of the Branded Products Group at Western Digital Corporation (and previous author of SpeedTools (QuickBench, ZoneBench, etc.),

I read your article and have some feedback about your Key Insight #1. I strongly disagree that USB 3.0 is slower than eSATA, per se. eSATA is limited to 3 Gb/sec whereas USB 3.0 is a 5 Gb/sec interface. They both use 8b/10b encoding so they are both 80% efficient on paper. (Transport protocol overhead further reduces real world data transfer rates and this overhead varies by bus interface type.) We expect USB 3.0 to be able to crack 400 Megabinary bytes per second (MiB/sec) with the right setup. eSATA will likely never crack 275 MiB/sec unless/until they move to 6 Gb.

The limiting factor with USB 3.0 storage devices to date has been the 3 Gb SATA backend of the first generation of USB 3.0 to SATA bridge chips. The 3 Gb SATA interface limits the potential of the 5 Gb Superspeed USB interface. Plus, converting from SATA protocol to USB protocol adds a bit of additional overhead.

That said, there are two basic approaches to actually deliver max speed over USB SuperSpeed with a bridged SATA solution, neither of which, to my knowledge, have yet been done:
1) Put two 3 Gb SATA ports on the back end of the USB bridge and connect two SATA devices which can saturate both of the SATA busses (think two SandForce-based SSD's in a RAID 0).
2) Make a bridge chip with a USB 3.0 front end and a 6 Gb SATA backend and stuff a 500 MiB/sec enterprise-class 6 Gb SSD or RAM drive behind it.

You will need a very powerful PCI bus (aka Gen 2 running off north-bridge, etc.) to get the best numbers, but we believe USB 3.0 can reach at least 400 MiB/sec once the other system bottlenecks are resolved. Of course, with a single HDD all this comparison stuff doesn’t mean much because they just aren’t fast enough to be meaningfully bottlenecked by either SATA or SuperSpeed USB.

Lastly, look for well-designed integrated USB 3.0 host controllers coming in the near future to further boost USB max data transfer rates.

Wednesday, April 6, 2011

Preserving code formatting in blog posts

In my last post I needed to keep the format of the code snippets. I found this very useful tool that will keep the formatting for you and and generate the raw HTML for it:

http://www.manoli.net/csharpformat/

Vim Visual Selection Tricks





# VISUAL SELECTION TRICKS:
# You can use filters and vim's execution mode.to do some powerful things.
# A filter is any standard UNIX program (sort, awk, grep, cut, paste, sed ...) that can read from stdin and write to stdout.
# Vim's execution mode lets you read in or replace text with the output of a program. If you make a visual selection (say,
# using V or C-V), and hit :, your command prompt will immediately be :'<,'>, which means "Apply whatever command follows
# to the lines included in the visual selection." At this point, you can write !foo to replace the text with the output of
# program foo.

# For example, to sort the text by the python column, select it, hit :, and enter !sort -k5. The whole command will look like
:'<,'>!sort -k5
# Running it will produce:

a b cd 1 p
b b cd 2 y
c b cd 3 t
d b cd 4 h

# Results in:

d b cd 4 h
a b cd 1 p
c b cd 3 t
b b cd 2 y

# For more complex tasks, awk is your friend. A command like
:'<,'>!awk '{ print $1, $3, $2, $4, $5 }'

a cd b 1 p
b cd b 2 y
c cd b 3 t
d cd b 4 h

# will flip the second and third columns (but note that inter-column spacing is collapsed).
# To do maths on a column, try something like
:'<,'>!awk '{ sub($4, $4*2+1); print }'

a b cd 3 p
b b cd 5 y
c b cd 7 t
d b cd 9 h

# Could get the same result with perl if there is only one column of numbers:
:'<,'>!perl -pe 's/\d+/$&*2+1/e'

# To flip the visual selection just select the rows and then:
:'<,'>!tac

d b cd 4 h
c b cd 3 t
b b cd 2 y
a b cd 1 p

# This pipes the lines through the unix 'reverse cat' program.






These ideas were taken from here:


Sand here:

Saturday, March 5, 2011

My switch from the 3Gs iPhone to Android (Samsung EPIC on Sprint)

I just got my first android phone, the Samsung EPIC 4G through Sprint. There are many reasons why I chose this specific Android phone but here were a few of my requirements:
  • Physical keyboard (although I am also very impressed with Swype)
  • Front facing camera which will allow for video conferencing
  • At least a 1Ghz processor (The GPU helps out a lot as well)
  • AMOLED screen (Not technically a requirement but if you have ever seen it you will understand)
  • Android OS 2.2 (Froyo) -- Sprint actually just retracted this update but it should be back soon.
  • Faster network (4G)
  • Stop paying any more Apple taxes
Some may wonder why I didn't go with the new iphone. Well, I wanted a physical keyboard and I wanted the ability to create scripts on my phone so that I could get my phone to do exactly what I wanted it to do. Sprint seems to be a much better user experience so far as well, with or without 4G. As it turns out my wife was already on Sprint so our cash flow will also be much improved ($0.20 per text? c'mon AT&T).

I was tempted to wait for this summer as to let my contract with AT&T lapse. There will certainly be newer phones introduced by then as well, but I figured life is too short. Also the fees for ending the contract were not that bad and Sprint had some pretty good incentives that more than made up for it.

Is there anything I will miss about my iPhone? Honestly I don't think so. Some may miss iTunes but I never really got into iTunes that much anyway. I almost always stream my music (Slacker) anyway so the network is much more important to me.

Upside surprises

  • The network just seems much much snappier than AT&T even when I am on 3G.
  • The screen is amazing when I set it next to my old phone the iPhone seems downright dull. When I look at my Picasa pictures on the EPIC using there "gallery" app it is like looking at the pictures for the first time. I have never seen my pictures looking so good!
  • Integration with all the Google tools is excellent.
  • Swype virtual keyboard is much more usable than I ever thought it could be. It makes me question my requirement for a physical keyboard it is that good. If you are not planning to write scripts on your phone you may really not need the physical keyboard, maybe.
Downside surprises

  • The keyboard keys are a little bit too flush. I wish everyone that made physical keyboards would use the raised keys like on Blackberry's. I find myself looking at the keys a bit too much trying to find where my fingers are exactly. I was thinking about adding a dot of super glue to all the keys so that I could really feel them but I am not sure there is enough clearance.
  • I wish the four buttons at the bottom of the phone were physical keys as well so I wouldn't have to look at them to push them.
  • I find it a bit frustrating to get help with things. For instance one of the reasons I got the phone was so that I could send certain incoming calls directly to voice mail (you know who you are, jk :). If you search the intertubes you can find lots of people talking about it, but it seems like my phone does not have the option. I am not sure if it is the Android OS 2.1 or Sprints front end or what but the slight differences are a bit frustrating. On the other hand I know that eventually I will get it working where as with the iPhone I would never be able to fix it because of the closed nature of the phone.
My following posts will describe in more details my attempts to script up my phone.

Tuesday, May 25, 2010

Is DropBox a usefull tool?

hmm.... In a word, yes! I feel like I am a little late to this party but what a productivity booster DropBox can be. The greatest thing about Dropbox is that it acts like a folder on your drive and everything you put in there gets synced. Now you might not think that is so great since you would have to store all your configuration files in some random folder but all you really have to do is move your important files to the sync folder and then create a symbolic link to them from the original location. Pretty darn simple and very effective. Now I can have one .vimrc file, one plugin directory, one .alias file and all my different machines can use it!

Here is a snippet from my notes that shows you how simple this really is:

SYNCING MY FILES VIA THE CLOUD (DROPBOX)
Once dropbox is installed I ran these commands on my myth box and things were backedup and synced
mv hlp Dropbox/HOME
ln -s ~/Dropbox/HOME/hlp/ hlp
mv bin Dropbox/HOME
ln -s ~/Dropbox/HOME/bin/ bin
mv web Dropbox/HOME
ln -s ~/Dropbox/HOME/web/ web
mv .vimrc Dropbox/HOME
ln -s ~/Dropbox/HOME/.vimrc/ .vimrc
mv .tcshrc Dropbox/HOME
ln -s ~/Dropbox/HOME/.tcshrc/ .tcshrc
mv .alias Dropbox/HOME
ln -s ~/Dropbox/HOME/.alias/ .alias
On other linux machines I will have to diff these files and see if there is any way to easily merge them
tkdiff ~/Dropbox/HOME/hlp/ hlp
tkdiff ~/Dropbox/HOME/bin/ bin
tkdiff ~/Dropbox/HOME/web/ web
tkdiff ~/Dropbox/HOME/.vimrc/ .vimrc
tkdiff ~/Dropbox/HOME/.tcshrc/ .tcshrc
tkdiff ~/Dropbox/HOME/.alias/ .alias

Use this link to sign up and you get an additional 250MB of storage.