Finding Alice and Bob in Wonderland: a writeup of Croupier, the Keybase bot

You may have observed that plenty respectable, prolific Hacker News users0 have added a Keybase signature to their profile:

Hacker_News
Seems that 20%+ of the Hacker News leaderboard has a Keybase signature in their profile…

So. What is Keybase?

Keybase’s mission is to

make cryptographically secure communication, cryptocurrency, and identity management into a user-friendly experience

Well, that’s a tall order…1 

Anyway, Keybase is like Slack, except free.  

keybase_chat_screenshot____.png

And transparently encrypted.  And early stage software; all of the error handling is transparent.  And open source.  And the currently-small user population of ~300,000 is mostly programmers.  And the team is responsive to community requests2.

In March 2019, Keybase issued a pair of press releases that made it to the top of Hacker News. 

Please allow me to TL;DR these:

  • Users may now generate randomness, in a way that’s indisputably fair, within Keybase chat conversations.

    coin_animation2
  • Users may now send money in chat in a conversational way.
    keybase salad.png
  • The Stellar foundation, backed by some of the smartest people in tech including Patrick Collison and Keith Rabois, backs Keybase.  Sure, social proof matrices have their flaws, but if it worked for Google and PageRank…

Anyway, the sudden emergence of these two technologies – integrated moneysending and trustable randomness – led to a few synapses sparking and – as neural connections and memories tangled – sent me down a rabbit hole of nostalgia:

The year is 2002. I’m a pimply-faced youth attending high school, living most of my life in an online fantasy world, a MMORPG called Nexus: TK.

nexustk

My main character was a rogue, but I had the opportunity to specialize in the merchant subpath, and I learned a spell called ✨ gamble ✨.

Either player could ante up to 250,000 coins and then the winning player (presumably based on the outcome of a Random Number Generator) would be awarded the proceeds.  There would be a cool little animation around the winning character, so anyone could spectate the outcome of the gamble, celebrating with the winner and taking schadenfreudian delight in the loser’s defeat.

Anyway, it clicked to me that with the launch of Keybase’s new tech, I could implement the gamble spell within Keybase.  I decided to roll up my sleeves, and the result?

Croupier.

Keybase_2

Keybase_1

Keybase

Players start a round by sending croupier money in chat, with a minimum bet size of 0.01XLM:

+0.01XLM@croupier

The countdown clock begins, allowing people 60 seconds to join the betting round. After any contribution to the pot, the clock resets, giving people another 60 seconds to join.  Once the clock runs out, each player is assigned a numerical range proportional to the size of their bet. Keybase randomly generates a number and the proceeds (minus the transaction fees to receive the bets – extremely small, approximately 100 stroops or 0.000001XLM) are directed to whoever’s range contains the number.

Yes, this means that with a bet of just 0.01XLM, one could win a pot containing hundreds of lumens. Note: If the flip fails to resolve or there aren’t 2+ participants in the game, participants are automatically refunded.

Here’s the source code….

Build it with:

 tsc --lib es2015 index.ts

And then run it with:

node index.js
import * as _ from "lodash";
import * as mysql from "mysql";
import * as os from "os";
import * as Bot from "./keybase-bot";

import "source-map-support/register";

const bot: Bot = new Bot(os.homedir());
const bot2: Bot = new Bot(os.homedir());

const botUsername: string = "croupier";
const paperkey: string = process.env.CROUPIER_PAPERKEY_1;
const paperkey2: string = process.env.CROUPIER_PAPERKEY_2;

import { ChatChannel, MessageSummary, Transaction } from "./keybase-bot";

interface IParticipant {
  username: string;
  transaction: Transaction;
}

interface ISnipe {
  participants: Array;
  betting_open: boolean;
  clock: string;
  timeout: string;
}

function documentSnipe(channel: ChatChannel, winner: string, wasCancelled: boolean): void {
  const participants: string = JSON.stringify(activeSnipes[JSON.stringify(channel)].participants);
  const connection: mysql.Connection = mysql.createConnection({
    database : process.env.MYSQL_DB,
    host     : process.env.MYSQL_HOST,
    password : process.env.MYSQL_PASSWORD,
    user     : process.env.MYSQL_USER,
  });

  connection.connect();

  if (winner !== null) {
    winner = `'${winner}'`;
  }

  connection.query(`INSERT INTO snipes
    (participants, winner, was_cancelled)
    VALUES
    ('${participants}', ${winner}, ${wasCancelled})`, (error, results, fields) => {
      if (error) {
        console.log(error);
      }
    });

  connection.end();
}

function processRefund(txn: Transaction, channel: ChatChannel): void {
  console.log("refunding txn", txn);
  // API returns a response, number of stroops
  const transactionFees: number = 300 * 0.0000001;
  console.log("refunding txn fees", transactionFees);
  const refund: number = _.round(txn.amount - transactionFees, 7);
  console.log("total refund is", refund);
  bot.chat.sendMoneyInChat(channel.topicName, channel.name, refund.toString(), txn.fromUsername);
}

function extractTxn(msg: MessageSummary): void {
  const txnId: string = msg.content.text.payments[0].result.sent;
  bot.wallet.details(txnId).then((details) => processTxnDetails(details, msg.channel));
}

function sendAmountToWinner(winnerUsername: string, channel: ChatChannel): void {

  let bounty: number;
  const snipe: ISnipe = activeSnipes[JSON.stringify(channel)];

  bounty = 0;

  snipe.participants.forEach((participant) => {
     bounty += parseFloat(participant.transaction.amount);
     bounty -= (300 * 0.0000001); // transaction fees for receiving the transaction
  });

  bounty = _.round(bounty, 7);
  console.log("now rounded", bounty);

  bot.chat.sendMoneyInChat(channel.topicName, channel.name, bounty.toString(), winnerUsername);

}

function resolveFlip(channel: ChatChannel, winningNumber: number): void {

  let winnerUsername: string;
  const bettorRange: object = buildBettorRange(channel);
  Object.keys(bettorRange).forEach((username) => {
    if (bettorRange[username][0] <= winningNumber && bettorRange[username][1] >= winningNumber) {
      winnerUsername = username;
    }
  });

  sendAmountToWinner(winnerUsername, channel);
  bot.chat.send(channel, {
    body: `Congrats to @${winnerUsername}`,
  });

  documentSnipe(channel, winnerUsername, false);
}

function buildBettorRange(channel: ChatChannel): any {
  const bettorMap: object = {};
  activeSnipes[JSON.stringify(channel)].participants.forEach((participant) => {
    if (typeof(bettorMap[participant.username]) === "undefined") {
      bettorMap[participant.username] = Math.floor(participant.transaction.amount / 0.01);
    } else {
      bettorMap[participant.username] += Math.floor(participant.transaction.amount / 0.01);
    }
  });

  const bettorRange: object = {};
  let start: number = 0;
  Object.keys(bettorMap).forEach((key) => {
    bettorRange[key] = [start + 1, start + bettorMap[key]];
    start += bettorMap[key];
  });

  return bettorRange;
}

function flip(channel: ChatChannel): void {

  const bettorRange: object = buildBettorRange(channel);
  const bettingValues: Array = Object.values(bettorRange);
  const flatBettingValues: Array = _.flatten(bettingValues);

  const minBet: number = flatBettingValues.reduce((a, b) => Math.min(a, b));
  const maxBet: number = flatBettingValues.reduce((a, b) => Math.max(a, b));

  let bettingTable: string = "Betting table\n";

  Object.keys(bettorRange).forEach((username) => {
    bettingTable += `\n@${username}: \`${bettorRange[username][0]} - ${bettorRange[username][1]}\``;
  });

  bot2.chat.send(channel, {
    body: bettingTable,
  });
  bot2.chat.send(channel, {
    body: `/flip ${minBet}..${maxBet}`,
  });
}

function processTxnDetails(txn: Transaction, channel: ChatChannel): void {
  if (txn.toUsername !== botUsername) {
    return;
  }
  const isNative: boolean = txn.asset.type === "native";
  if (!isNative) {
    return;
  }
  if (parseFloat(txn.amount) < 0.01) {     bot.chat.send(channel, {       body: "Thanks for the tip, but bets should be >= 0.01XLM",
    });
    return;
  }

  const snipe: ISnipe = activeSnipes[JSON.stringify(channel)];
  if (typeof(snipe) === "undefined") {
    launchSnipe(channel);
    activeSnipes[JSON.stringify(channel)].participants.push({
      transaction: txn,
      username: txn.fromUsername,
    });
  }

  console.log("betting_open 178");
  if (snipe.betting_open === false) {
    bot.chat.send(channel, {
      body: `Betting has closed - refunding`,
    });
    processRefund(txn, channel);
    return;
  }

  activeSnipes[JSON.stringify(channel)].participants.push({
    transaction: txn,
    username: txn.fromUsername,
  });
  bot.chat.send(channel, {
    body: `@${txn.fromUsername} is locked into the snipe!`,
  });
  resetSnipeClock(channel);
}

function resetSnipeClock(channel: ChatChannel): void {

  const snipeTimeout: number = 60;
  clearTimeout(activeSnipes[JSON.stringify(channel)].timeout);
  bot.chat.delete(channel, activeSnipes[JSON.stringify(channel)].clock, {});
  bot.chat.send(channel, {
    body: `Betting stops in ${snipeTimeout} seconds`,
  }).then((sentMessage) => {
    runClock(channel, sentMessage.id, snipeTimeout);
    activeSnipes[JSON.stringify(channel)].clock = sentMessage.id;
  });
  const finalizeBetsTimeout: NodeJS.Timeout = setTimeout(() => {
    finalizeBets(channel);
  }, snipeTimeout * 1000);
  activeSnipes[JSON.stringify(channel)].timeout = finalizeBetsTimeout;

}

const activeSnipes: object = {};

function launchSnipe(channel: ChatChannel): void {
  // Tell the channel: OK, your snipe has been accepted for routing.

  const snipeTimeout: number = 60;
  let message: string = "The snipe is on.  Bet in multiples of 0.01XLM.  Betting format:";
  message += `\`\`\`+0.01XLM@${botUsername}\`\`\``;

  activeSnipes[JSON.stringify(channel)] = {
    betting_open: true,
    clock: null,
    participants: [],
    timeout: null,
  };

  bot.chat.send(channel, { body: message });

  bot.chat.send(channel, {
    body: `Betting stops in ${snipeTimeout} seconds`,
  }).then((sentMessage) => {
    runClock(channel, sentMessage.id, snipeTimeout);
    activeSnipes[JSON.stringify(channel)].clock = sentMessage.id;
  });

  const finalizeBetsTimeout: NodeJS.Timeout = setTimeout(() => {
    finalizeBets(channel);
  }, snipeTimeout * 1000);
  activeSnipes[JSON.stringify(channel)].timeout = finalizeBetsTimeout;

}

function finalizeBets(channel: ChatChannel): void {
  bot.chat.send(channel, {
    body: "No more bets!",
  });

  console.log("betting_open 255");
  activeSnipes[JSON.stringify(channel)].betting_open = false;
   // Give 5 seconds to finalize transactions + 1 extra.
  setTimeout(() => {
    executeFlipOrCancel(channel);
  }, 6 * 1000);
}

/* TODO: check that there are _different_ participants not someone betting against themself multiple times */
function executeFlipOrCancel(channel: ChatChannel): void {
  const snipe: ISnipe = activeSnipes[JSON.stringify(channel)];
  if (typeof(snipe) !== "undefined") {
    const participantUsernames: Array = snipe.participants.map((participant) => participant.username);
    const uniqParticipants: Array = _.union(participantUsernames);
    if (uniqParticipants.length > 1) {
      flip(channel);
    } else if (uniqParticipants.length === 1) {
      snipe.participants.forEach((participant) => {
        processRefund(participant.transaction, channel);
      });
      bot.chat.send(channel, {
        body: "The snipe has been cancelled due to a lack of participants.",
      });
      documentSnipe(channel, null, true);
      activeSnipes[JSON.stringify(channel)] = undefined;
    } else {
      bot.chat.send(channel, {
        body: "The snipe has been cancelled due to a lack of participants.",
      });
      documentSnipe(channel, null, true);
      activeSnipes[JSON.stringify(channel)] = undefined;
    }
  }
}

function cancelFlip(conversationId: string, channel: ChatChannel, err: Error): void {
  clearInterval(flipMonitorIntervals[conversationId]);
  if (typeof(activeSnipes[JSON.stringify(channel)]) !== "undefined") {
    bot.chat.send(channel, {
      body: `The flip has been cancelled due to error, and everyone is getting a refund`,
    });
    activeSnipes[JSON.stringify(channel)].participants.forEach((participant) => {
      processRefund(participant.transaction, channel);
    });
    documentSnipe(channel, null, true);
    activeSnipes[JSON.stringify(channel)] = undefined;
  }
}

const flipMonitorIntervals: object = {};

function monitorFlipResults(msg: MessageSummary): void {

  flipMonitorIntervals[msg.conversationId] = setInterval((() => {
    try {
      bot.chat.loadFlip(
        msg.conversationId,
        msg.content.flip.flipConvId,
        msg.id,
        msg.content.flip.gameId,
      ).then((flipDetails) => {
        if (flipDetails.phase === 2) {
          console.log("results are in");
          resolveFlip(msg.channel, flipDetails.resultInfo.number);
          clearInterval(flipMonitorIntervals[msg.conversationId]);
          activeSnipes[JSON.stringify(msg.channel)] = undefined;
        } else {
          console.log("results are NOT in", flipDetails);
        }
      }).catch((err) => {

        cancelFlip(msg.conversationId, msg.channel, err);

      });
    } catch (err) {
      cancelFlip(msg.conversationId, msg.channel, err);
    }
  }), 1000);
}

const allClocks: Array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].reverse();
const runningClocks: object = {};

function runClock(channel: ChatChannel, messageId: string, seconds: number): void {
  try {
    bot.chat.edit(channel, messageId, {
      message: {
        body: ":clock" + allClocks[seconds % 12].toString() + ":" + ` betting stops in ${seconds}s`,
      },
    });
  } catch (e) {
    return;
  }

  if (seconds > 1) {
    setTimeout(() => {
      runClock(channel, messageId, seconds - 1);
    }, 1000);
  } else {
    setTimeout(() => {
      bot.chat.edit(channel, messageId, {
        message: {
          body: "~:clock" + allClocks[seconds % 12].toString() + ":" + ` betting stops in 1s~ no longer accepting bets`,
        },
      });
    }, 1000);
  }
}

async function main(): Promise {
  try {
    await bot.init(botUsername, paperkey);
    console.log(`Bot initialized with username ${botUsername}.`);
    await bot2.init(botUsername, paperkey2);
    console.log("Second key initialized");
    console.log("Listening for all messages...");

    const channel: object = {
       membersType: "team", name: "mkbot", public: false, topicName: "test3", topicType: "chat",
    };
    const message: object = {
      body: `${botUsername} was just restarted...[development mode] [use at own risk] [not functional]`,
    };

    bot.chat.send(channel, message);

    await bot.chat.watchAllChannelsForNewMessages(
      async (msg) => {
        try {
          if (msg.content.type === "flip" && msg.sender.username === botUsername) {
            monitorFlipResults(msg);
            return;
          }
          if (msg.content.type === "text" && msg.content.text.payments && msg.content.text.payments.length === 1) {
            extractTxn(msg);
          }
        } catch (err) {
          console.error(err);
        }
      },
      (e) => console.error(e),
    );
  } catch (error) {
    console.error(error);
  }
}

async function shutDown(): Promise {
  await bot.deinit();
  await bot2.deinit();
  process.exit();
}

process.on("SIGINT", shutDown);
process.on("SIGTERM", shutDown);

main();

You might notice that this is mostly written in TypeScript!  As the project grew to 500 lines of code, I found it a bit difficult to manage bugs.  Converting the JS into TypeScript was mostly really easy.  A few rounds of TSLint and ESHint and TypeScript compilation later, everything was pretty much smooth sailing.

Misc note: I found the Type system something a bit counterintuitive to grapple with, especially when dealing with JSON and partially undocumented APIs.  Fortunately, the keybase-bot project has been partially implemented in typescript and all the types were already prepared for me. Niiiiice.

1C88E460-A57B-4EA2-B2C5-2C6ECFA2DFB5
v1 of the bot was designed on pen and paper, and then redesigned around some limitations3 I ran into as well as UX conveniences that seemed obvious in hindsight.

A few notes on deploying the bot…

@dxb, the leader of the @mkbot Keybase channel and the most helpful person in the testing and iterative development process4, showed me how to use Docker to deploy the bot.  I actually hadn’t had an opportunity to use Docker in production, so it was super informative!

Here was my deployment process:

  1. apt-get install docker-compose
  2. Added my current logged in user to the docker group with
    usermod -aG docker
  3. Logged out and logged back in
  4. Created a new folder and included a file called
    Dockerfile

    Here’s the Dockerfile:

    FROM archlinux/base
    
    RUN pacman -Sy && \
        pacman -S --ask 20 --noconfirm \
        base \
        binutils \
        fakeroot \
        git \
        jq \
        gcc \
        tcl \
        expect \
        nodejs-lts-dubnium \
        npm \
        sudo \
        keybase
    
    RUN useradd -m keybase && \
        mkdir /keybase && \
        chmod 777 /keybase
    
    RUN echo 'keybase ALL=(ALL) NOPASSWD: ALL' | EDITOR='tee -a' visudo
    
    USER keybase
    WORKDIR /home/keybase
    
    ENV PATH=/home/keybase:$PATH
    
  5. In the same folder, created a file called
    docker-compose.yaml

    Here’s the contents:

    version: '3.2'
    services:
        croupier:
            image: keybase_dxb:latest
            environment:
                BOT_OWNER: zackburt
                CROUPIER_PAPERKEY_1: warrior laugh...redacted...
                CROUPIER_PAPERKEY_2: warrior laugh...redacted...
                MYSQL_HOST: croupier-cluster.redacted.us-east-1.rds.amazonaws.com
                MYSQL_USER: croupier
                MYSQL_PASSWORD: redacted
                MYSQL_DB: croupier
            entrypoint: /home/keybase/scripts/start.sh
            restart: always
            volumes:
              - type: volume
                source: 0_home
                target: /home/keybase
              - type: bind
                source: ./0_scripts
                target: /home/keybase/scripts
    
    volumes:
        0_home:
    

    Note: we use two paper keys.  Due to limitations of the keybase client, the Keybase paperkey that launched the flip doesn’t have the ability to read the flip, so we use another paperkey for that.

     

  6. Built the Docker file with
    docker build --no-cache -t keybase_dxb .
  7. Created a folder called 0_scripts/ and put these scripts in it, sendmoney.sh and start.sh.  Notice that line in the docker-compose.yaml where start.sh is automatically invoked once the container starts.  Here they are:
    1. sendmoney.sh
      #!/bin/bash
      
      KB_TEAM=$1
      KB_CHAN=$2
      KB_AMT=$3
      KB_RCPT=$4
      WORKING_DIR=$5
      HOME_DIR=$6
      KB_SPAWN="expect -c 'spawn ${WORKING_DIR}/keybase --home ${HOME_DIR} chat send --channel ${KB_TEAM} ${KB_CHAN} \"+${KB_AMT}XLM@${KB_RCPT}\" ; expect \"if you are sure\" ; send -- \"sendmoney\r\" ; expect eof'"
      eval $KB_SPAWN
      

      Note: the keybase client requires some interaction to send money in chat, so @dxb cooked up this little expect script.

      Note as well: by default, sendMoneyInChat() is not a method in the keybase-bot library.  So we hacked up keybase-bot.js to add this method to the Chat class that extends ClientBase:

      sendMoneyInChat(channel, team, amount, recipient) {
      
        console.log('sendMoneyInChat: 1');
        const child = child_process.spawn('/home/keybase/scripts/sendmoney.sh',
          [channel, team, amount, recipient, this._workingDir, this.homeDir]);
      
        child.stdout.on('data', (data) => {
          console.log(`stdout: ${data}`);
        });
      
        child.stderr.on('data', (data) => {
          console.log(`stderr: ${data}`);
        });
      
        child.on('close', (code) => {
          console.log(`child process exited with code ${code}`);
        });
      
        child.on('error', (err) => {
          console.log(`child process errored with err ${err}`);
        });
      
      }
      
    2. start.sh
      #!/bin/bash
      
      # start keybase service without kbfs and gui
      keybase oneshot --username croupier --paperkey "warrior laugh redacted.."
      run_keybase -fg
      
      # put the commands to run at startup here
      sudo pacman -Scc
      
      keybase chat send $BOT_OWNER "$(date) - starting bot"
      
      sudo npm install -g typescript
      killall keybase
      rm -rf croupier 
      git clone https://github.com/codeforcash/croupier.git
      cd croupier
      npm install
      tsc --lib es2015 index.ts
      node index.js
      
  8. chmod +x 0_scripts/start.sh

    and

    chmod +x 0_scripts/sendmoney.sh
  9. Started the container with
    docker-compose up croupier

You’ll notice that the Docker container automatically builds based on the source code in the GitHub repo.  In fact, @dxb has it rigged so that his bots restart automatically whenever there’s a new commit to the codebase… but that’s outside the scope of this article as I haven’t followed him to that level yet. 🙂

Want to try croupier yourself?  Join the @mkbot channel on Keybase and get a game going with +0.01XLM@croupier.  Or, invite @croupier into any Keybase team you’re in and start the game the same way.

Is this legal?

Let it be said: I’m not a lawyer.  And Croupier does not take a rake except arguably that refunds and winnings are issued less transaction fees (maybe rounded up a few stroops – à la the salami slicing scheme described in Office Space and Superman 3).

As far as I know, in New York, skill games are legal and new legislation continues to reify that.  Now, is Croupier a skill game, given outcomes are determined by the provably just randomness features implemented on Keybase?

I say: yes!

  • One has the ability to increase one’s chance of winning through adding additional bets (although this doesn’t affect the expected value of one’s outcome, since one’s odds are always directly proportional to one’s bet commitment).
  • Croupier is inherently a social bot, and bet sizing has to be done in a way that doesn’t draw the ire of one’s companions – nobody wants to be steamrolled by someone with an unfairly large bankroll.
  • If somebody jukes the odds at the last minute, one has the ability to force a draw – and a refund of everybody’s bets: if two users with the same paper keys subscribe to the chat channel, Keybase doesn’t certify the randomness. In practice, Croupier refunds all bets. Forcing a duplicate registration event is a strategy, even though there are social consequences to being a bad actor.

Footnotes:

[0] Hacker News: social media for elite/elitist technologists who claim to despise social media and yet maintain some presence on the site.

[1] The Keybase founders, Max and Chris, previously launched SparkNotes and then OKCupid.

So perhaps indeed they could make cryptography cross the chasm.

[2] @pzduniak, thoroughly polite all the way through my plentiful nagging, added flip support to the keybase-bot library.

[3] Keybase has this cool feature where users may request money, but as of writing there was no convenient API for accessing it.

[4] @dxb, @locknload, @jessecooper, and @max were especially helpful testers! 

[5] Code For Cash is recruiting a developer to join Keybase and fully own development of the Windows Keybase client.  

[6] Croupier’s namesake is Dan Egan from the HBO series Veep.

dan egan
Dan’s colleagues undermined him by telling his boss he would “make a good croupier” – not a political operator.

Unlocking the information that candidates really care about when considering a new position

Here at Code For Cash, we are a 3rd party tech recruiter, which means that we are basically running a funnel.

funnel purple bg.png

Based on my background as a growth and revenue engineer at Lookout (which my colleagues turned into a $1b+ company 🦄), I know that the recipe for success is systematically testing tactics for optimizing each segment of the funnel.

Here’s a table of some of our open campaigns:

Landing Page URL Visits Applications Conv Rate
https://codefor.cash/bermi-backend 1144 20 1.75%
https://codefor.cash/betterment-engineering-manager 291 11 3.78%
https://codefor.cash/clearbit-backend-engineer 117 5 4.27%
https://codefor.cash/clearbit-fullstack-engineer 69 5 7.25%
https://codefor.cash/keybase-windows-developer 128 0 0.00%
https://codefor.cash/leverdata 406 8 1.97%
https://codefor.cash/pcap-sr-dev 557 14 2.51%
https://codefor.cash/pinchme-frontend-engineer 155 17 10.97%
https://codefor.cash/pinchme-product-manager 38 1 2.63%
https://codefor.cash/seated-head-engagement 333 18 5.41%

As you can see, we are running a weighted average conversion rate of 3.06%– plenty of room for improvement.  Through tons of iteration, I have grinded landing page conversion rates up from 0.5% to 10%+ – it’s all about kaizen.  Improving, getting more traffic, talking to the customer base, rinse and repeat.  I know it’s possible to improve because I have the successful experiential reference points.

So we recently bore witness to the Twitter activity of @jenistyping who was early employee and Head of People at Lever, and we were impressed…the radar went off, the alarm bells in my head started ringing: we should be paying attention to this.  So we got in touch and Jen made a referral to Peoplism.  Liz Kofman-Burns did a quick (hey, we’re bootstrapping!) review of our processes and came up with the following recommendations regarding information that we could include on each of our landing pages:

  1. URM candidates (but everyone really) wants to know: Will I belong? Is this a place where I’ll be treated fairly? How do I know that?
    1. Some ways to answer this are: getting an inventory of the team’s personalities and interests; understanding whether the company has historically been promoting from within; checking out the company’s Glassdoor presence; measuring employee tenure by reviewing LinkedIn profiles of current employees.
  2. What’s the impact the company has on the world?  (An evidentiated huge priority for millennials).
  3. What colleagues are they going to be interacting with day to day, and who benefits from their work?  i.e. what is this role’s impact on their colleagues?
  4. What are the growth and learning opportunities for everyone in the company?
  5. What’s work of this position like day to day?
  6. What are they going to be doing in 6 months?  In a year?
  7. What specific skills and values are you looking for? What will candidates be evaluated on?
  8. What are the interview questions?
  9. What is the interview *process*?
  10. Clear delineation of absolute hard skill requirements vs. nice-to-have
  11. Any compensation hints or guidelines

So, step one of improving our conversion rate is rewriting the stories we’re telling on the landing page to include the aforementioned information.

A lot of our clients are startups, “reassembling the airplane in the air.”  So it’s not always possible to provide absolute clarity regarding these topics.  But we’re going to systematically provide as much information as we have, and when we’re limited, we’re going to be clear about that.

Another improvement that’s almost always an easy win is to give the landing pages a facelift from the design team – doing the work of design improvements shows people that you care.  Here’s a preview of what the new design looks like:

Jobs Details

And one of the secrets in the digital community is that your content is not your content – it’s the title and the thumbnail image.  So we’re going to be careful about what thumbnail images we provide our various landing pages.  This is the guide we’re following to keep a strong technical handle on how our preview images render. 

Yes, a well-run funnel is only as good as the quality and relevancy of the people entering… we are not gonna speak to our experiments regarding this yet.

Thanks for staying tuned.

Go Givers Sell More: Compressing a 160 page book into 4 pages of quick notes

My parents recently went traveling in Vietnam and Laos and they met a couple that owns a really successful recruiting agency. They said one book, called Go Givers Sell More, made a huge impact. Since I am building a recruiting agency I figured that I should read it.

The book really resonated with my experience, especially now that I am doing a ton of sales and cold outreach. Here are my notes. I did my best to compress a 160 page book into 4 pages of notes. So if anything is vague or cryptic just ask.

Here are my notes.

The basic premise of the book is that you have to give value in order to receive.

If your goal in sales is to create value for other people, how do you do that? Here are five ways: excellence, consistency, attention, empathy, and appreciation.

  • Excellence: When you thank an employee for something at an excellent hotel, the answer is My Pleasure! rather than no problem.
  • Consistency: Do what you say you are going to do.
  • Attention: Pay phenomenal attention to detail and exhibit thoughtfulness.
  • Empathy: Put yourself in the other person’s shoes and make their life easier.
  • Appreciation: Say thank you, and mean it. Write thank-you notes… not just emails, but actual handwritten notes. Publicly and privately praise what you truly appreciate in other people.

With these five value-generating activities, it’s not formulaic that if you perform X acts of appreciation you will get Y sales in return. You give because it’s who you are and therefore what you do. The only way to get more is to continuously give away these acts of value and eventually repayment will emerge. But if you go about creating value with the ulterior motive of receiving more value, it tends to show through on some level and sabotage the result. Give without emotional attachment to the return — knowing confidently that there will be return.

If someone approaches you to do business but we know for their purpose that a competitor would be better, we make a referral. Our focus is on providing value for the customer.

Psychology: in order to become givers, we willingly suspend our self-interest. We don’t erase or deny it; we simply set it aside for a moment so we can gain emotional access to the full experience of the Law of Value.

Providing more value than you receive in payment is the trade secret of all exceptional businesses.

Rapport formula: F-O-R-M. Family, Occupation, Recreation, Message. Conversations that meander along these topics will strike a vein of connection and rapport.

Quick rapport rules:

  • Be polite.
  • Don’t interrupt.
  • Listen. Just try to understand exactly what the person is saying. Honor their perspective.
  • Smile (again).
  • Say please and thank you.
  • Find a genuine interest in the other person.

Rapport can be as subtle as honoring a person’s native tongue or expressing your genuine mutual interests. It’s about being human.

Going to the trouble of getting someone’s name right is one of the simplest gestures of respect there is — and mispronouncing, mangling, or misremembering another’s name is one of the surest ways to offend.

Remember to keep your focus on providing value for the other person. When you feel uncomfortable on a call, you are thinking about yourself.

Emotional maturity is the ability to keep your focus on others’ feelings even as you acknowledge and honor your own.

The essence of professionalism, is showing up for work even when you don’t feel like it. Feelings and moods come and go. There may be times when you don’t really feel you’re interested in this other person, don’t feel like creating value for them, or don’t feel like being friendly. That’s okay. Take the action anyway.

Genuine influence accrues to those who become known as the sort of person who is committed to helping other people get what they want.

Approach each business relationship with; What have I done for you lately?

Give credit away rather than seek it; be kingmakers rather than kings; be constantly on the lookout for ways they can help to elevate other people’s lives.

All things being equal, people will do business with and refer business to those people they know, like, and trust. Key aspect of likability: great grooming. Pay attention to it daily, even when working remotely. It shines through in your voice and subtle mannerisms, even through text.

The majority of your best customers will come from people you vaguely know: not exactly friends but not exactly strangers. The teller at your bank; your kids’ friends’ moms, and so forth. Improve weak ties.

The philosophy for attending meetups: just making friends. Why? To make friends. Don’t mention our service at all. How to make the perfect meetup pitch? Don’t. Your aim is to have fun and make friends. Go for quality, not quantity. And don’t pitch. Instead, ask great questions:

  • How did you get started in the [_____] business?
  • What do you enjoy most about what you do?
  • {Name}, how can I know if someone I’m talking to would be a good connection for you?

Meetups must be accompanied by followthrough.

  • Send a personalized, handwritten thank-you note that says what a pleasure it was to meet them.
  • Connect them to other people and suggest ways they could do business with each other or benefit in some way from the relationship.
  • Send them info they might find interesting or valuable – not about your product or service but about something they’re personally interested in.

A feature is about our service. A benefit is about the other person.

If someone asks, what do you do? That describes the benefits people derive from doing business with you.

You cannot “make a sale”. What you can do is create value. People will do what people will do. All you can do is seek to serve, look for ways to create value… and trust.

Emotional clarity is your understanding of the difference between your economic need (which is real) and your emotional need for this person to be the solution to that economic need. Emotional discipline is your ability to hold onto that clarity and consistently choose your responses to each situation, rather than acting impulsively.

The combination of clarity and discipline is posture: stepping into the truth of who you are and the value you have to offer, without emotional attachment to any specific outcome.

There’s not a lot riding on the outcome for you… but there could be for them.

Whenever a prospect brings up your competitor, go out of your way to say something nice about him or her because respect earns respect.

Authenticity is not something you seek or take on; it’s something you simply embrace. Being whole means your words and actions are not separate: you do what you say.

Keep your focus on: Who is this person? What do they want? What are they searching for? What is the single most valuable thing I could possibly offer them?

Remember, it’s not about you; it’s about them.

There is forceful assertion and bravado (bad) and there is the simple statement of fact that springs from the quiet stillness of authenticity.

If someone objects to a pitch, turn in the direction of the skid. Agree with what they said. “Certainly something to consider” and “I get what you’re saying” are ways of being with the person rather than jousting. When you say “That’s a great question” or “That’s a good point” and then join with them to examine the issue they raised, you let them know it’s welcome and appreciated. The only way to say that authentically is to genuinely see it as a great point.

The underlying goal is to create value for the other person. Things we say to help take the pressure off, so they can feel more relaxed about making the right decision:

  • If you can’t do it, I’ll definitely understand.
  • {Name}, this may or may not be for you.

The flip side of giving value is letting yourself receive. If you don’t let yourself receive, you’re refusing the gifts of others — and you shut down the flow.

Focus on creating value in the world around you and for the people around you, and the greatest opportunities will come to you in moments and from places you never expected.

How do you get people to trust you? By being a trusting person. Living in trust means that having made your plan, you put it fully into action, investing it with excellence, consistency, attention, empathy, and appreciation.

How we source software engineering candidates who will pass your tech interview

ericThis article explains our bulletproof process for sourcing software engineers and provides concrete examples; this process led us to placing software developers at growing startups as well as enterprise brands such as REMAX, Lever Data, WorkReduce, and Drive Sally.

This article is for leaders at growing companies with job openings for software engineers. This is especially for leaders who may be understandably frustrated by the hiring process when it comes to software engineering talent.

It’s been known since the 1980s that there is a distribution of productivity among computer programmers, and that some are not only “10 x” (ten times) but in fact one hundred times more productive and efficient than the average programmer. [1]

So it’s clear that good programmers are rare, but the great ones are worth it.

Anyone who reads TechCrunch will know that startups – even those that don’t make it past the Series B stage – are regularly snapped up in “acqui-hire” deals, where the founders are paid a bounty per software engineer in the neighborhood of $5 to $10 million.

So it’s clear that good programmers companies are willing to pay up for top talent.

Companies may be so desperate to find talent that they locate to San Francisco and Silicon Valley, with its enormous rents, passive-aggressive “we’re here to change the world, not to make money” ethos and its startup monoculture, just so they can fish in a talent pool that’s stocked with talent.

But often times, if a leader at a company isn’t technical, they might be afraid that it’s impossible for them to hire a great software engineer. For good reason. The maxim “A players hire A players” is something that resonates with experienced entrepreneurs. And go find a blog article or Quora article addressing the common question – how should? a non-technical person should evaluate potential developers – and see the refrain “God help you” uttered by Silicon Valley luminaries.

So when a company has trouble with its hiring process – and starts making excuses like “all the good software engineers are already working” or “it’s impossible to compete with the massive salary offers and social prestige of Facebook/Apple/Netflix/Google”, it’s in fact entirely understandable.

When I show you the solution, the only reason I am able to convey this to you is because I happen to luck into a very specific background and set of circumstances that enabled me to make this insight. I was born in Palo Alto, into a community of successful entrepreneurs and software developers; I started programming in the ‘90s and was working in Silicon Valley as a professional by the 2000s.

So, here is the simple and straightforward solution: treat the software developer recruitment process like a funnel, and have a great software engineer run the funnel for you.

To understand why this is true, visualize a hiring process that resulted in the hiring of an excellent candidate. Working backwards in the successful hiring process, you have the great candidate. Then you have the interview. Then you have the phone screen. Then you have the resume or initial contact with your firm.

funnel.png

Without making sure that great people see the job listing in the first place, at the top of the funnel, we’re never going to get great candidates out of the end. And without a sufficient volume, we won’t be able to get sufficient throughput due to the drop-off at each stage.

In order to get great candidates to the top of the funnel, you need to ally up with a great software engineer. This software engineer can tell you where all the great candidates hang out (“it takes one to know one”); they can tell them about your job opportunity, and they can sell it in a way that makes it both convincing and credible to a peer.

For example, while a CEO might talk about a culture of transparency and their open office – a snarky engineer might interpret that as a culture of anxiety-inducing mistrust where someone can breathe down your neck, watching you code, while you’re just trying to focus and get the job done. So, tone matters.

One of the major problems that a reader of this article might have is that either they have no amazing software engineers to set the tone and bar for their process or, if they do have the talent, the talent is focused on building features for the product roadmap and therefore doesn’t have the time to commit to running the funnel and process. Both are understandable and both are solvable through Code For Cash’s placement solution.

The Code For Cash proposition is simple: we’ll run your recruiting for you and in exchange, you pay us 20% of each successful hire’s first-year cash salary.

You can continue doing things as usual and perhaps experience death by a thousand paper cuts, or you could delegate to us and pay us once we generate a success.

This process has worked for prestigious firms and entrepreneurs, including WorkReduce, Lever Data, David J. Moore, Johann Schleier-Smith, and Bluedrop Performance Learning.

Here’s how we get the job done.

We find the people who are obviously great.

The first thing we do is go through GitHub and look for people who have had their pull requests accepted into popular open source projects.  We then research their contact information and remove anyone from the list who asks not to be contacted by recruiters.

We then look for authors of popular blog posts or paperback books on the relevant topics, and conduct the same research – removing contact info where inappropriate and enriching where appropriate.

We write the screener questions.

The first step in the process is to really review the job description and understand: the psyche and personas of potential high-performing candidates, what the day to day is like in the job, what kind of background that person might have had to led them up to that point, and of course, the fundamentally important “hard skills” that are required. This helps us design questions to help us tease out whether they are the person who is right for the role and confirm that they have the communication skills to share their skills knowledgeably.

Example screener questions include:

We create a landing page fully instrumented with analytics.

Because most job recruiting processes are not run by default as a funnel, sometimes the “product” and “user experience” aspect of job listings gets ignored. The most important thing is to tell a story about the company and a story about the job, and for the story to be credible (to sound like it was at least approved by the software engineers working in the organization). The more detail-rich and authentic the description is, the better. It’s important to pick the technical skills capriciously either.

We treat this landing page like a product and manage it as closely as any product manager would.

We pay the fees.

We find that it often takes at least three hundred qualified eyeballs to get a placement at a company. A qualified eyeball is when a candidate with the requisite technical skills views the job posting. In order to get the job posting in front of qualified eyeballs, some amount of expenditure is required. This occurs in both time to contact candidates as well as fees incurred with posting on the job boards, podcasts and meetups that are relevant to the role. It’s no matter – we pay the fees because we are confident that our methods are effective.

Example job boards or sourcing locales:

  • Lobste.rs
  • Craigslist
  • Hacker News
  • MIT Alumni Job Board
  • UWaterloo Alumni Job Board
  • Tech Hiring Subreddits
  • Reddit Ads
  • Rands Leadership Slack
  • Various domain-specific Slack channels
  • AuthenticJobs
  • BetaList
  • Angel.co Source Pro
  • LinkedIn groups
  • LinkedIn ads
  • LinkedIn Recruiter
  • Various domain-specific IRC channels
  • GitHub Jobs
  • StackOverflow Careers
  • A recruiter presence at local tech meetups

We get the ball rolling in our network.

When Code For Cash was first founded, we were a network of freelance programmers. Because of this, over 2,000 programmers signed up with us and registered their skills. The tech programming community is extremely tight knit, and we seed our viral referral loop by sharing our jobs and galvanizing our immediate audience of programmers by paying them if they originate successful placements.

Our offer is that we will source and place candidates for you in exchange for 20% of first-year salary.

Our guarantee is that we will get the job done. If for any reason a candidate does not deliver value for you and your organization, you will either get a complete refund or a replacement.

There is a human element to this process, and there are a limited number of software engineers with the requisite traits to succeed in sales (recruiting is fundamentally a sales process). So we can’t work with every company or individual who would like to work with us, but we promise to add value in a big way to each person we contact.

Contact us today and with a 15-minute meeting, get the ball rolling and be confident that you’re about to hire extremely talented software engineers.

https://calendly.com/code-for-cash-recruiting/15min

[1] DeMarco, Tom, and Timothy Lister. Peopleware: Productive Projects and Teams. New York, NY: Dorset House Publ., 2003.

Getting invocation count for Lambda functions

For one of our Software as a Service as a Service (SaaSaaS) clients, we built a serverless Lambda service and charged them per successful invocation.  Each time the service succeeds, we charge; therefore, we wanted to figure out how many times it was successful in order to calculate their bill.  Our service logs the text “Posting response” if the invocation was successful; if you want to get a total invocation count, in the steps below, replace “Posting response” with “END RequestId”.

 

  1. Follow these instructions to export your log data to an S3 bucket under your control: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/S3ExportTasksConsole.html
  2. Run this on your local commandline: aws s3 cp s3://bucket-with-the-export/exportedlogs lambda-exported-logs –recursive

  3. Run this on the local commandline to uncompress all the logs: gunzip -r lambda-exported-logs
  4. Install The Silver Searcher, a super-fast grep-like tool available on most platforms
  5. Fire up the ruby interpreter (type irb on your local commandline) and run this code:

    irb(main)> res=`ag -c "Posting response"`
    irb(main)> res.split(“\n”).map{|x|x.split(‘:’)[-1]}.map(&:to_i).inject(:+)

  6.  You’ll get your total invocation count.