Friday, January 11, 2019

Encoding binary data into python source code

source

Effectively

python import base64
image = open('deer.gif', 'rb')
image_read = image.read()
image_64_encode = base64.encodestring(image_read)
image_64_decode = base64.decodestring(image_64_encode)
image_result = open('deer_decode.gif', 'wb') # create a writable image and write the decoding result image_result.write(image_64_decode)

Thursday, January 10, 2019

Post commit hook for terraform


source

A commit hook to check that terraform files are created properly:


#!/usr/bin/env bash
set -e

# Formats any *.tf files according to the hashicorp convention
files=$(git diff --cached --name-only --diff-filter=d)
for f in $files
do
  if [ -e "$f" ] && [[ $f == *.tf ]]; then
    /usr/local/bin/terraform fmt -check=true $f
  fi
done


Place into:

/usr/share/git-core/templates/hooks/

Wednesday, December 12, 2018

GCE Terraform notes

Getting started: https://cloud.google.com/community/tutorials/managing-gcp-projects-with-terraform

Wednesday, December 5, 2018

Make yourself work when you just don't want to..

Reason #1 You are putting something off because you are afraid you will screw it up.
Solution: Adopt a “prevention focus.”
There are two ways to look at any task. You can do something because you see it as a way to end up better off than you are now – as an achievement or accomplishment. As in, if I complete this project successfully I will impress my boss,or if I work out regularly I will look amazing. Psychologists call this a promotion focus – and research shows that when you have one, you are motivated by the thought of making gains, and work best when you feel eager and optimistic. Sounds good, doesn’t it? Well, if you are afraid you will screw up on the task in question, this is not the focus for you. Anxiety and doubt undermine promotion motivation, leaving you less likely to take any action at all.
What you need is a way of looking at what you need to do that isn’t undermined by doubt – ideally, one that thrives on it. When you have a prevention focus, instead of thinking about how you can end up better off, you see the task as a way to hang on to what you’ve already got – to avoid loss. For the prevention-focused, successfully completing a project is a way to keep your boss from being angry or thinking less of you. Working out regularly is a way to not “let yourself go.” Decades of research, which I describe in my book Focus, shows that prevention motivation is actually enhanced by anxiety about what might go wrong. When you are focused on avoiding loss, it becomes clear that the only way to get out of danger is to take immediate action. The more worried you are, the faster you are out of the gate.
I know this doesn’t sound like a barrel of laughs, particularly if you are usually more the promotion-minded type, but there is probably no better way to get over your anxiety about screwing up than to give some serious thought to all the dire consequences of doing nothing at all. Go on, scare the pants off yourself. It feels awful, but it works.
Reason #2 You are putting something off because you don’t “feel” like doing it.
Solution: Make like Spock and ignore your feelings. They’re getting in your way.
In his excellent book The Antidote: Happiness for People Who Can’t Stand Positive Thinking, Oliver Burkeman points out that much of the time, when we say things like “I just can’t get out of bed early in the morning, ” or “I just can’t get myself to exercise,” what we really mean is that we can’t get ourselves to feellike doing these things. After all, no one is tying you to your bed every morning. Intimidating bouncers aren’t blocking the entrance to your gym. Physically, nothing is stopping you – you just don’t feel like it. But as Burkeman asks, “Who says you need to wait until you ‘feel like’ doing something in order to start doing it?”
Think about that for a minute, because it’s really important. Somewhere along the way, we’ve all bought into the idea – without consciously realizing it – that to be motivated and effective we need to feel like we want to take action. We need to be eager to do so. I really don’t know why we believe this, because it is 100% nonsense. Yes, on some level you need to be committed to what you are doing – you need to want to see the project finished, or get healthier, or get an earlier start to your day. But you don’t need to feel like doing it.
In fact, as Burkeman points out, many of the most prolific artists, writers, and innovators have become so in part because of their reliance on work routines that forced them to put in a certain number of hours a day, no matter how uninspired (or, in many instances, hungover) they might have felt. Burkeman reminds us of renowned artist Chuck Close’s observation that “Inspiration is for amateurs. The rest of us just show up and get to work.”
So if you are sitting there, putting something off because you don’t feel like it, remember that you don’t actually need to feel like it. There is nothing stopping you.
Reason #3 You are putting something off because it’s hard, boring, or otherwise unpleasant.
Solution: Use if-then planning.
Too often, we try to solve this particular problem with sheer will: Next time, I will make myself start working on this sooner. Of course, if we actually had the willpower to do that, we would never put it off in the first place. Studies show that people routinely overestimate their capacity for self-control, and rely on it too often to keep them out of hot water.
Do yourself a favor, and embrace the fact that your willpower is limited, and that it may not always be up to the challenge of getting you to do things you find difficult, tedious, or otherwise awful. Instead, use if-then planning to get the job done.
Making an if-then plan is more than just deciding what specific steps you need to take to complete a project – it’s also deciding where and when you will take them.
If it is 2pm, then I will stop what I’m doing and start work on the report Bob asked for.
If my boss doesn’t mention my request for a raise at our meeting, then I will bring it up again before the meeting ends.
By deciding in advance exactly what you’re going to do, and when and where you’re going to do it, there’s no deliberating when the time comes. No do I really have to do this now?, or can this wait till later? or maybe I should do something else instead. It’s when we deliberate that willpower becomes necessary to make the tough choice. But if-then plans dramatically reduce the demands placed on your willpower, by ensuring that you’ve made the rightdecision way ahead of the critical moment.

Thursday, October 18, 2018

Help Your Team Do More Without Burning Out

Source

As we begin our coaching session, Nick is fired up. He radiates energy, his eyes are beaming with determination, and he never really comes to a full rest. He speaks passionately of a new initiative he is spearheading, taking on the looming threats from Silicon Valley, and rethinking his company’s business model completely.
I recognize this behavior in Nick, having seen it many times over the years since he was first singled out as a high-potential talent. “Restless and relentless” have been his trademarks as he has risen through the ranks and aced one challenge after another.
But this time, I notice something new. Beneath the usual can-do attitude there is an inkling of something else: Mild disorientation and even signs of exhaustion. “It’s like sprinting all you can, and then you turn a corner and find that you are actually setting out on a marathon,” he remarks at one point. And as we speak, this sneaking feeling of not keeping pace turns out to be Nick’s true concern: Is he about to lose his magic touch and burn out?
Nick is not alone.
In a psychologist’s practice, common themes rise and wane across a cohort of clients. Right now, I see a surge of concern about speed: getting ahead and staying ahead. More clients use similar metaphors about “running to stand still” or feeling “caught on a track.” Invariably, their first response is to speed up and run faster.
But the impulse to simply run faster to escape friction is obviously of no use for the long haul of a life-long career. In fact, our immediate behavioral response to friction shares one feature with much of the general advice about speeding up: It is plainly counterproductive and leads to burn out rather than break out.
To add insult to injury, the way to wrestle effectively with the challenge of sustainable speed is somewhat counterintuitive and even disconcerting — especially to high-performing leaders who have successfully relied on their personal drive to make results.

From ego-drive to co-drive

The key to speeding up without burning up is a concept I call co-drive. Sustainable speed does not come from ego-drive, that is, your own personal performance or energy level, but rather from a different approach to engaging with people around you.
Rather than running faster, Nick needs to make different moves altogether. First, he must let go of his obsession with his own development, his own needs, his own performance, and his own pace. Second, he must start obsessing about other people.
It may seem illogical, but the leap to a new growth curve begins by realizing that the recipe is not to take on more and speed up, but to slow down and let go of some of the issues that have been your driving forces: power, prestige, responsibility, recognition, or face-time.
The talent phase in our careers tends to be profoundly self-centered, even narcissistic. If you need to move on from the first growth curve in your career, and want to take on more challenges, you need to exchange ego-drive for co-drive.
Co-drive requires that you momentarily forget yourself — and instead focus on others. The shift involves an understanding that you have already proven yourself. At this stage, the point is to help those around you perform. The change to co-drive involves moving from a stage of grabbing territory to a stage characterized by letting go of command and control.

Beyond teamwork

So here is what Nick needs to do: Rather than striving to be energetic, he should aim to be energizing. Rather than setting the pace, he should aspire to make teams self-propelling. Instead of delegating tasks, he should learn to lead by congregating.
Be energizing, not energetic. Here is the paradox: You can actually speed things up by slowing down. There is no doubt that being energetic is contagious and therefore a short-term source of momentum. But if you lead by example all the time, your batteries will eventually run dry. You risk being drained at the vey point when your leadership is needed the most. Conveying a sense of urgency is useful, but an excess of urgency suffocates team development and reflection at the very point it is needed. “Code red” should be left for real emergencies.
Nick has always had a weak point for people, who, like himself, are high-energy and get things done. These “Energizer Bunnies” are his star players. However, with the co-drive mindset, Nick needs to widen his sights and recognize and reward people who are good at energizing others. Energizing behavior is unselfish, generous, and praises, not just progress, but personality too.
Seek self-propulsion, not pace-setting. If you lead by beating the drum, setting tight deadlines, and burning the midnight oil, your team becomes overly dependent on your presence. Sustainable speed is achievable only if the team propels itself without your presence. Jim Collins wrote that great leaders don’t waste time telling time, they build clocks.
Self-propulsion comes from letting go of control, resisting the urge to make detailed corrections and allowing for informal leadership to flourish. As Ron Heifetz advocates, true leadership is realizing that you need to “give the work back” instead of being the hero who sweeps in and solves everybody’s problems.
In Nick’s case, he should resist the urge to take the driver’s seat and allow himself to take the passenger seat instead. Leading from the side-line, not the front line will change his perspective. Instead of looking at the road and navigating traffic, he is able to monitor how the driver is actually doing and what needs to improve. In his mind, he should fire himself — momentarily — and see what happens to his team when he sets them free and asks them to take charge instead of looking to him for answers, deadlines and decisions.
Congregate, don’t delegate. From very early on in our careers we learn that in order to solve big, complex issues fast, we must decompose the problem into smaller parts and delegate these pieces to specialists to get leverage. Surely, you can make good music by patching together the tracks of individual recordings. But true masterpieces come alive when the orchestra plays together.
One example is the so-called Trauma Center approach. When a trauma patient comes in, all specialists are in the room assessing the patient at the same time, but constantly allowing the most skilled specialist to take the lead (and talk), not the designated leader.
The most well-run trauma teams I have observed know when to jump in and when to step back. To put it simply, it’s no use working on a finger if the heart is failing. A trauma team relies on trust and patience. They trust each other’s specialty and work very symmetrically. There is a very strong “no one leaves before we are done” mentality in those teams.
To Nick, this may sound like good old teamwork, and while Nick is certainly driven by a good measure of self-interest, he is also an accomplished leader who masters the dynamics of teamwork: Having shared goals, assigning roles and responsibilities, and investing in the team.
But there is more to co-drive than plain teamwork. It is about re-working the collaborative process it self. Rather than cubicled problem-solving, sustainable speed requires a shift toward more collective creation: Gathering often, engaging issues openly and inviting others to improve on your own thoughts and decisions.
Co-drive requires a different mindset. And it goes beyond team-work. Adam Grant from Wharton has done research demonstrating that a generous and giving attitude towards others enhances team performance.
Try, for instance, to take a look at your own behavior yesterday and gauge the balance between giving and taking. Givers offer assistance, share knowledge, and focus on introducing and helping others. Takers attempt to get other people to do something that will ultimately benefit them, while they act as gatekeepers of their own knowledge.
Grant’s conclusion is clear: a willingness to help others is not just the essence of effective cooperation and innovation — it is also the key to accelerating your own performance.

Maturity and Caliber

Headhunters call this change of perspective from ego-drive to co-drive “executive maturity.” The mature leader’s burning question is: how do I help others perform?
The developmental psychologist Robert Kegan calls the leap a subject/object shift. You progress from seeing and navigating in the world on the basis of your own needs and motives — and allowing yourself to be governed by these needs — to seeing yourself from an external position as a part of an organism.
It requires a certain caliber and self-assuredness to act in this way. The ability to put your ego on hold may require a great effort. It might be worthwhile reminding yourself of the words of the American President Harry Truman: “It is incredible what you can achieve, if you don’t care who gets the credit.” If you succeed in making this shift, and thereby improving the skills of the people around you, then you will also experience a greater degree of freedom.

So next time you are feeling stuck, don’t ask: “How can I push harder?” but “Where can I let go?”

Wednesday, October 3, 2018

Closer to emacs as a window manager

Multi-term - finally (probably for a while) has support for remapping important keys.

auto-dim-other - very useful as it dims other buffers making it easier to know which is the active buffer

windmove - built in since emacs 21, allows binding keys to 'windmove-[left|right|up|down]. Decided that C-cC-n, C-cC-p, C-cC-a, C-cC-f are the easiest for moving around the buffers and the most similar to current functionality (C-n moves down a line, C-p moves up a line, C-a moves to the front of a line, C-e to the end). This does mean unbinding these keys from all the various modes that want to use these keys as well, the biggest pain being elpy-flymake, which doesn't seem to want to honor hooks attached to elpy-flymake-mode-hook or elpy-mode-hook.


ivy - much nicer matching and drop-down menus for things such as M-x functions
counsel - provides lots of symbol completion for various modes and in particular, ivy.
codesearch - tool for using google codesearch

counsel-codesearch - counsel bindings for codesearch

find-file-in-repo - a faster code search tool using the indexing provided by git (or other dvcs).

Tuesday, October 2, 2018

Building Emacs

source

Enable 'Source code' in 'Ubuntu Software' in
/usr/bin/python3 /usr/bin/software-properties-gtk

install build tools
sudo apt install build-essential checkinstall
build emacs dependencies

sudo apt-get build-dep emacs24
clone emacs git repo

git clone -b master git://git.sv.gnu.org/emacs.git
create and run config script

 ./autogen.sh && ./configure
make and make install

make && sudo make install