Monday, December 31, 2018

Why More Women are Victims of Scams (WSJ)

Bill Francavilla : Women outlive men, so there are more older woman. Studies have found that men fall for investment scams and women fall for lottery (you just won a XYZ car and you just have to pay for title and shipping) scams.

Who would have guessed? A 24 year old Indian dude made $300m by running the IRS scam. Phew.. The Americans know him as Shaggy btw..

Simon Lovell - the British con man who later became a stage magician said : "I love it when someone says they can't be scammed." If you've read Joe Weil's autobiography, you know that even con men are not immune!


Sunday, December 30, 2018

An Authoritative Python Cheat Sheet (WIP)

All plagiarized of course, credits at bottom..

Make the script both a module and an executable :

if __name__ == '__main__'

The __whatever__ is a "dunder" - double-underscore. There are some useful ones you'll pick up - like __init__ , __repr__ , __eq__ (that goes along with decorators), etc.

Enumerate :

for i, var in enumerate( list_name ) :
     some_useful_code using i and var

List comprehension (build a list on the fly ) :

[ x * 3 for x in data if x > 10 ]

Build a dict out of two lists :

d = dict( zip( key_list, val_list ) )

Flatten a list of lists :

>>> l_of_lists = [list(range(10)), list(range(20,30)), list(range(50,60))]
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [20, 21, 22, 23, 24, 25, 26, 27, 28, 29], [50, 51, 52, 53, 54, 55, 56, 57, 58, 59]]
>>> l = [y for x in l_of_lists for y in x]
>>> l
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]


Count number of elements in your list greater than a certain value :

sum(i > 5 for i in j)

Reverse a list :

list_name[::-1]

Parse JSON data :

import json
import requests
response = requests.get( url, params=paramDict)
parsed_json = response.json()     # then do a pprint (pretty print) to see how to use..

Pandas :

import pandas as pd
df = pd.read_csv( 'somefile.csv')
matching_list = df['field1'][df['fieldN' == 'something_specific']

import matplotlib.pyplot as plt
from matplotlib import style

style.use('classic')
df['some field'].plot()
plt.show()

To convert from JSON to dataframe :

from pandas.io.json import json_normalize
df = json_normalize( parsed_json['key name'] )

Fill out a matrix using a list or dict ( while you count from 0 to 8 generate (0,0),(0,1),(0,2),(1,0)..(2,2) )

from itertools import product

i=0
for t1, t2 in product( sorted_tags, sorted_tags ) :
    row = i // num_tags
    col = i % num_tags
    i += 1
    t_mx[row][col] = transition_counts[ (t1,t2) ]

Actually, more pythonically (maybe) :


from itertools import product

for i,j in product( range( num_tags), range(num_tags) ) :
 t_mx[i,j] = transition_counts[ (sorted_tags[i], sorted_tags[j] ) ]

QEI

http://safehammad.com/downloads/python-idioms-2014-01-16.pdf
https://coderwall.com/p/rcmaea/flatten-a-list-of-lists-in-one-line-in-python


Saturday, December 29, 2018

Installing Your Own Personal Python Module

That is, when you do

import myModule

Python shouldn't barf.

Put your .py file in a reasonable place (i.e., a directory named meaningfully :)

In the same directory, have a setup.py file that looks like

from setuptools import setup

setup (
    name='myModule',
    version='1.0',
    description='A useful personal module',
    author='me',
    author_email='me@memail.com',
    url='me.com',
    py_modules=['myModule'],
)

Then, run :

$ python setup.py sdist

You will see a warning that there is no README file.

Now, to install :

$ pip install /path/to/myModule-1.0.tar.gz

Easy enough?

Spyder++

What *would* be nice is to incorporate some 20+ year old technology such as what NEdit already has - that is, let users record interaction with the GUI and create custom macros that they can then bind keyboard shortcuts to.

For example, based on my mood, I'd like to toggle between the light and dark theme. You listening Pierre Raybaut? Please …

Google "spyder keyboard shortcut toggle between light and dark theme" and see what you get..

Friday, December 28, 2018

Hans Fangohr++ aka A Better Spyder Tutorial

Why not anticipate users' problems - especially when you give them advanced tips?

He says, set IPython Console to do symbolic math (Tools > Preferences) and then you'll see cuter stuff.

He doesn't say :

Start a new console.
What happens if you run into ..

These commands were executed:
from __future__ import division
from sympy import *
x, y, z, t = symbols('x y z t')
k, m, n = symbols('k m n', integer=True)
f, g, h = symbols('f g h', cls=Function)

Warning: pylab (numpy and matplotlib) and symbolic math (sympy) are both
enabled at the same time. Some pylab functions are going to be overrided by
the sympy module (e.g. plot)


expr = (x + y) ** 3
Traceback (most recent call last):

  File "<ipython-input-1-530ade24fb9f>", line 1, in <module>
    expr = (x + y) ** 3

NameError: name 'x' is not defined

In short, what an ass!

Fortunately, we have some online angels :

https://github.com/spyder-ide/spyder/issues/3255
https://stackoverflow.com/questions/43915513/how-to-get-latex-style-output-from-sympy-in-spyder-ipython-console
https://github.com/nteract/hydrogen/issues/1119

I go to Start > Anaconda > Anaconda Prompt and then do

> conda install -c conda-forge miktex

Dat fix it? No!!

What did?

The commands that *IT* (see above) says *were* executed apparently weren't! So, you have to manually do :

x, y, z, t = symbols( 'x y z t') 
only to find that

NameError: name 'symbols' is not defined

And then,

from sympy import symbols

That gets

expr = (x + y)**3
To NOT complain.

Now, when you do expr, you get the Unicode formatted pretty thing with the 3 really looking like a superscript. Not what you want obviously :)

So, what does work :

from sympy import init_printing
init_printing()

Now, when you do

expr

You get




Wednesday, December 26, 2018

Where We Need Alex Skorkin and Stephen Jungels to Deliver

Do a version of ALT-LEFT and ALT-BKSPCE (for bash) that will treat underscore as a word delimiter..

How do you do this?

There are times when I want to treat whole_word as one word and some times, as two.

Yes, I have OCD :)

Tuesday, December 25, 2018

Eugen Sandow : Strength and How to Get It

The man was ahead of his time. He knew that really was about mind over matter :

HUNDREDS of letters reach me daily, asking "Can I become strong?" Yes; you can all become strong if you have the will and use it in the right direction. But, in the first place, you must learn to exercise your mind. This, first of all lessons in physical training is of the utmost importance. For on it the whole of my system depends. If physical exercise alone and unaided could achieve the desired end, then would every one who, like the breaker of stones, has to use his muscles to earn his daily bread, become, in a popular acceptation of the term, "a strong man." The breaker of stones, however, never uses his mind. He has to get through a given amount of work, and his method is purely mechanical. Though he may use his muscles in hard work every day of the year it is unlikely that his strength will ever materially increase.

Exercise, indeed, without using the mind in conjunction with it, is of no use. It is the brain which develops the muscles, Physical exercise must be commenced by degrees, first bringing into play one muscle, then two, then three, and so on, being careful all the time to put the mind into every movement. Let me strongly advise every student to study well the anatomical chart which is published with this book. By its aid you will be able not only to receive a useful lesson in anatomy, but you will also be able to see at a glance the exercise by which each muscle may be developed.

So charming, the last word :

The reader will probably ask if special means were adopted during this and succeeding engagements to maintain my strength. The answer is very simple : The performance itself provides the necessary amount of daily training. I eat, drink, smoke and sleep quite in the ordinary way, taking care to observe in all things that guiding rule of moderation to which reference is made in the preceding chapter. I only practice, in order that grace and perfection may be attained, when some new feat is introduced. Personally, it may be added, I find that the best time for a performance is about three hours after a meal.

Saturday, December 22, 2018

Productivity Manifesto

Commandment What it Really Means
Plan your day the night before Begin with the end in mind :)
Get the big rocks in Don't sweat the small stuff - make a start on the big!
Do the hardest task first If you have three similar blocks to design, design the most complicated one and you've done all three. If you go in ascending order of complexity, you'll be doing three blocks :)
Single-task: For high level work Focus -  with talmudic intensity!
Multi-task: For low level work Fold clothes and talk on the phone - that's ok :)
Ditch the unimportant Don't sweat the small stuff. Watch your portfolio
Use a to-list Mental accounting is the bane of modern existence
Use a do-later list: For unimportant tasks Excel helps to not-lose them
Create your productivity system Know what works for you
First be effective, then be efficient Getting it done more important than how you do it - just ask your boss :)
Quit procrastinating Applies to getting out of bed as well :)
Use productivity tools Know what works for you
Meditate: Clears your mind, increases focus And can improve other functions as well
Get a headstart Move the worry curve in - there's always some bad news lurking out there :)
Practice 80/20 rule Watch your portfolio of goals and targets
Clear your mind: Do a brain dump Mental accounting is the bane of modern existence
Be organized Losing time searching for things is sin :)
Delegate where needed Leverage the network of helpers
Outsource work better done by others Leverage the network of helpers
Eliminate time wasters Don't sweat the small stuff - is it important?
Master your skills Plan / Excecute / Debrief to become the best
Tap into your productivity periods Know when you're at your best. A shower can help :)
Go with the path of peak enjoyment wha?
Just do it Make a start. Editing will follow naturally
Be well rested Know when you're at your best. A shower can help :)
Learn from the best Heredity can only do so much - seek mentors/coaches out
Search and reapply Make it easy to find your own tools
lmprovise on your performance Incremental advances add up
Read productivity materials Know what works for you
Create your life handbook But you have to remember to use the checklist :)
Batch similar tasks Plans are useless but planning is indispensible
Use the best tools You *can* program in assembly language if you want
Reward yourself But practise healthy habits
Learn to say No Watch your portfolio of goals and targets
Quit to win Keep your eye on the ROI - is it important?
Create a conducive environment Know what works for you
Improve your posture Get the adjustable desk unless you're a luddite
Delete limiting thoughts Self awareness is your friend
Cut down on commuting time If you're reading this, you like being in control. When you're commuting, you're NOT!
Time box: Set a fixed amount of time Move on and let the brain process it
Set a target Begin with the end in mind :)
Set a deadline Work always expands to fill the time available for it
Keep your emails in check Check email just a couple times a day - or try to :)
Plan your task And debrief - what? Right? Wrong? Why? Learning?
Be on time Bloomberg - 80% of success if show up - early
Visualization Leave no stone unturned
Practice makes perfect No! Perfect practice makes perfect. Practice makes permanent
Use overwhelming force Leave nothing to chance
Get a coach How?
Time out (Have a vacation/break) Recharge and sharpen them saws

Bill Crawford : Excecution != Excellence

Being stuck in execution is like being the hamster on the treadmill.

Plan, Execute, Debrief, Repeat... if you want to be the best at what you do.

Debrief :
  • What happened?
  • Why?
  • What went right?
  • What went wrong?
  • Why?
  • What can we learn?

Wednesday, December 19, 2018

The Moscow Rules

  1. Assume nothing
  2. Never go against your gut
  3. Everyone is potentially under opposition control (except Iniesta)
  4. Don't look back. You are never completely alone
  5. Go with the flow. Blend in!
  6. Vary your pattern and stay within your cover
  7. Lull them into a sense of complacency
  8. Don't harass the opposition
  9. Pick the time and place for action
  10. Keep your options open
Guess there's something to it - else we couldn't have won the cold war :)



About building rapport :

  1. Don't come across as judgy. Avoid statements like, "I don't get why you would do or think that."
  2. Avoid giving advice. What people want is approval. You want to say something along the lines of, "That was a smart move," rather than, "You should do it this way."
  3. Don't be the person who has to win the argument - let the target win.
  4. Don't be a one-upper. If the target tells you about his biggest sales coup, don't top it with a story about how you actually sold more.
  5. Avoid interrupting the target when they're speaking.
  6. Never downgrade their status or profession.
  7. Never finish their sentences for them.

After Jason Hanson, What?

Survive Like a Spy is Ok. Cute - Like Clint Emerson's work.

Try getting your hands on Spy Combatives. It's good to know how to be able deescalate situations. You know how annoying some immature coworkers can be :) The co-author trained with Chuck Norris for 36 years!

SOE Close Combat Syllabus taught by badass Brits :) : http://www.gunthorp.com/Close%20Combat%20Syllabus.pdf

Get Tough by W. E. Fairbairn

The best of Jason Hanson :

How do you keep your identity private?


Did you use TOR in relation to your work? How can you assure your identity will not be discovered when navigating an open web or deep website using Tor/Tails (say, by an ISP, man in the middle, or an attack from the server designed to reveal your identity)?
Hanson: “I do use a VPN on my computer. I stay out of any places where I’m worried I will be discovered. Truthfully, I’m much more worried about my physical safety and making sure people can’t find me, which is why I have nothing delivered to my house (I use a UPS store as my address) and why my driver’s license and my car registration, etc. all have the UPS store address.

You can use an LLC or a Trust to buy your house. (And have the LLC address be your P.O. Box or UPS store address).”

What John and Hector (code name for the Korean professor who know the Hungarians) accomplished :

https://apps.dtic.mil/dtic/tr/fulltext/u2/a064354.pdf : Army Missile Research and Development Command : Holographic Optics for Missile Guidance Systems. B Guether and C Leonard. Who are these geniuses? The tech material reads like Walter Scott for me! Poetry! On page 1, they misspell the former Duke Professor's name … it is Guenther.. I don't recall watching anything before on YT with an awe-inspired jaw-gape.

BTW, what does spymaster (well, with six kids, how do you choose to be a spy in the first place - don't you want to be there for your kids and NOT put your life on the line?) keep in his bugout bag :

  1. A tomahawk (ensure the bag, fully loaded, is less than 25 lbs he says)
  2. A kukri (dagger)
  3. Collapsible backback (nice, a bag within a bag)
  4. Survival blaze - firestarter ($5)
  5. Survfilter - world's best water filter unless you go look at what the Israelis have ($99)
  6. Tourniquet
  7. First-aid kit
  8. Tube tent
  9. Bic lighters
  10. Paper map
  11. Food (survival food - just add water)
  12. Pancho (deal with rain)
  13. Knives - NOC
  14. Mess kit (pots,pans, silverware) for food prep
  15. Water purification kit (Chlor-flocc)
  16. Versa knife
  17. Multi-tool
  18. Matches (multiple ways to start a fire)
  19. Gun oil
  20. Scalpel. 
  21. Flashlight
  22. Dryer lint
  23. Bandana
  24. Emergency drinking water pouch.
  25. Emergency blanket
  26. Medical tape

Sunday, December 16, 2018

Stephen Jungels is Cool, But..

Why not tell people what to do when you don't have lynx on your Cygwin?

https://github.com/transcode-open/apt-cyg#quick-start

Ans :

$ wget rawgit.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg

$ install apt-cyg /bin

An NEdit Shortcut for Inserting the Date

You need to execute a unix command (depending of course on the format you want. This applies to 12/16/18 style date ) like

$ date +%m/%d/%y

das große problem : NEdit interprets the "%" :(

So you have to tell it to send unix something that date can then use. That is, the 

"%m/%d/%y" needs to magically appear before the date command is executed.

Enter command substitution and the answer :

$ date +`perl -e 'print "\045m/\045d/\045y";'`

You see how it arbeitet? First, the perl command is executed and the result is placed in the date command. The perl command uses octal codes to put the % in the print statement - so NEdit is clueless. 

So, what do YOU do? Do ALT-x, and enter this, and see that it works. Then, go into record macro mode and record this, and then do the Preferences > Default Settings > Customize Menus .. thing :)

Enjoy!

Now, what if you want something like "Dec 16 2018" :

date "+%b %d %Y"

Phew - how little I know :) If you use backticks for command substitution, this new one will give you grief. Turns out, the professional way to do command substitution is $( )

So, start with (in NEdit ALT-x execute command dialog ) :

date "+$(perl -e 'print "\045b \045d \045Y";')"

And all is well :) Thanks to the maestros :)

Friday, December 14, 2018

Killer Excel Macro : A Button to Toggle Hide/Unhide of Rows

  • Start with a file that's already named .xlsm . Save time later :)
  • Know which rows? Say 10 to 12 (inclusive)
  • Right click on the name of the Sheet on the bottom of the Excel window and choose "View Code"
  • Now, paste :
Sub sbHidingUnHideRows()
    If Rows("10").EntireRow.Hidden Then
    'To unHide Rows 10 to 12
        Rows("10:12").EntireRow.Hidden = False
    Else
    'To Hide Rows 10 to 12
        Rows("10:12").EntireRow.Hidden = True
    End If
End Sub

  • And tweak it to be what you want. Then, do ALT-Q. If you go into Macros, you'll see this one..
  • Then, to create the button, go to Insert (File, Home, Insert, Draw, on the top of the Excel window)
  • Here, choose Shapes and put down something nice. Remember da Vinci : Simplicity is the ultimate sophistication.
  • Edit the Text associated with this shape.
  • Then, right-click on the shape and choose Assign Macro, pick the one you just created. And..
  • You're in business.. 

Autodesk's Beginners PCB Design Tips

(Right click and choose Open in New Tab, and, there, your mouse pointer turns into a magnifying glass)

https://www.autodesk.com/products/eagle/blog/top-10-pcb-component-placement-tips-pcb-beginner/

Sunday, December 02, 2018

Using a File on Your PC as the Background Image in CSS

This one's hard to find online for some reason

body {
         background-image : url("C:\path\to\file");
}

Seems right intuitively, except, it doesn't work. What does work? "file:///C:/path/to/image"

How should you know? Open the file in your browser first - and pay attention :)