Saturday, June 27, 2020

How to Column Grep a CSV File (Perl)

You know what I mean.. only show rows where entries in a particular column match a certain criterion.

You only want to see the rows, where field number 10 (index 11 for hackers :) matches your regex. How?

Good news is, phew, perl trumps awk hands down AFAIK.

$ > perl -F, -ane 'print if $F[ordinal_field_num_minus_1] =~ /regex/;' filename

Does it.
So, if you're interested in the first column (i.e., ordinal number is 1, then use $F[0]. YGTI :)

Wha?

-a is the autosplit option - it auto splits each line read in into the @F array, but it uses ' ' (space) as the character to split on. You change that using -F (same as awk). Note that you can do -F'regex' if you want, for -F'[:,]'

If you need to get up to speed on -a, -n, -e, -F and the very useful -l, read $ > man perlrun

Stand Out, with Tips from Markus Adhiwiyogo - the Gloss in Your Consultant Chops

It's not plagiarism mate - I'm just worried this good stuff might not be around forever :)

A deer in the headlights—that’s how I felt during the first few weeks in my consulting career. While I’ve heard people telling me romanticized jet setting stories, and earning miles or hotel rewards; surprisingly, not many told me about what I can do to prepare for a career in consulting.

PowerPoint
Value in consulting is derived from a consultant's ability to solve problems for their clients. The vehicle to communicate those solutions is PowerPoint. Consultants must be able to take incredibly complex and challenging client issues, create solutions, and communicate those solutions succinctly. Clients, normally, are not interested in seeing a complicated 50-slide deck. Clients want to know solutions up front. I have been in plenty of client meetings where we have spent an entire meeting discussing the first two slides and leaving the other 15-20 as appendix/support items. In addition to expressing complicated problems/solutions, consultants must also create decks that are professional looking. DO NOT UNDERESTIMATE THIS! PowerPoint skills gained in industry often do not compare to the skills and expectations in management consulting.

Finally, Something Useful on Quora

  1. The first computer dates back to Adam and Eve. It was an Apple with limited memory, just one byte. And then everything crashed.
  2. We live in a society where pizza gets to your house before the police.
  3. I find it ironic that the colors red, white, and blue stand for freedom until they are flashing behind you.
  4. Alcohol is a perfect solvent: It dissolves marriages, families and careers.
  5. What is the best thing about living in Switzerland? Well, the flag is a big plus.
  6. If you're not supposed to eat at night, why is there a light bulb in the refrigerator?
  7. My therapist says I have a preoccupation with vengeance. We'll see about that.
  8. A recent study has found that women who carry a little extra weight live longer than the men who mention it.
  9. Hospitality is making your guests feel like they're at home, even if you wish they were.
  10. Good health is merely the slowest possible rate at which one can die.
  11. We never really grow up, we only learn how to act in public.
  12. Having sex is like playing bridge - if you don't have a good partner, you'd better have a good hand.
  13. Team work is important; it helps to put the blame on someone else.
  14. I was born to be a pessimist - my blood type is B Negative.
  15. Nostalgia isn’t what it used to be.

Sunday, June 14, 2020

Learn Thou zip Ahmet Taspinar!

And watch Jeff Knupp's talk (or read the Writing Idiomatic Python book :) as well :)

Obviously this guy is super smart, else Nikhil wouldn't be referring us to him..

But, ..

x_value = np.linspace( 0, t_n, N)
amplitudes = [4, 6, 8, 10, 14]
frequencies = [6.5, 5, 3, 1.5, 1]
y_vals = [amplitudes[ii] * np.sin( 2 * np.pi * frequencies[ii] * x_value) for ii in range( 0 , len(amplitudes))]
y_total = np.sum( y_vals, axis=0 )

Yikes! I learnt better from Mr. NB :

y_values = [ A * np.sin( 2 * np.pi * f * x_value) for A,f in zip( amplitudes, frequencies)]
y_composite = np.sum( y_values, axis=0 )

Keep it readable and idiomatic! That's the python way

Easy to verify both give you the same.. as they should.

OMG!!!!!!! How did this guy even graduate?

In the get_fft_values function above, the scipy.fftpack.fft function returns a vector of complex valued frequencies. Since they are complex valued, they will contain a real and an imaginary part. The real part of the complex value corresponds with the magnitude, and the imaginary part with the phase of the signal. Since we are only interested in the magnitude of the amplitudes, we use np.abs() to take the real part of the frequency spectrum.

Jeez!!