Skip to content

Instantly share code, notes, and snippets.

@pixyj
pixyj / numbers_and_squares.csv
Created January 31, 2016 02:30
Example output for a quiz.
1 1
2 4
3 9
4 16
5 25
@pixyj
pixyj / exec_aloud.py
Last active February 29, 2016 13:29
Python decorator to say function's name before it is executed (for OS X)
"""
Usage Example:
Case 1 - Debug: Say function name and start pdb before executing add
@exec_aloud(debug=True)
def add(x, y):
return x + y
@pixyj
pixyj / list_memcached_keys.sh
Last active March 2, 2016 06:53 — forked from bkimble/gist:1365005
List local memcached keys using Ruby
#!/usr/bin/env ruby
require 'net/telnet'
require 'terminal-table'
# This code is copied from a comment on the original repo.
tbl = Terminal::Table.new headings: %w(id expires cache_key bytes)
localhost = Net::Telnet::new("Host" => "localhost", "Port" => 11211, "Timeout" => 3)
matches = localhost.cmd("String" => "stats items", "Match" => /^END/).scan(/STAT items:(\d+):number (\d+)/)
import Queue
import threading
# This is the current version of the database.
rows = {
1: {
"version": 2,
"postcode": 111111,
"id": 1
},
@pixyj
pixyj / shunting_yard.ex
Last active June 7, 2017 12:52
Shunting yard algorithm in Elixir
defmodule ShuntingYard do
@moduledoc """
Shunting yard algorithm as explained at https://en.wikipedia.org/wiki/Shunting-yard_algorithm
Supports an use-case of mine where all operators are left-associative,
and no functions are present in the expression
iex> c("shunting_yard.ex")
@pixyj
pixyj / experiment_coordinator.ex
Created February 8, 2017 13:10
Pattern matching example
defmodule ExperimentCoordinator do
use GenServer
require Logger
def handle_call({:configure, config}, _from, :not_started) do
Logger.info "Configuring node with parameters: #{inspect config}..."
{:reply, :ok, :ready}
end
def handle_call(:begin_pings, _from, :ready) do
@pixyj
pixyj / lru.py
Created August 11, 2017 04:17
A simple LRU cache implementation in Python. See test_lru.py for an usage example.
class Item:
def __init__(self, key, value, previous, next):
self.key = key
self.value = value
self.previous = previous
self.next = next
class LRU:
def __init__(self, maxlength=10):
@pixyj
pixyj / usability.md
Last active August 19, 2017 18:04
Summary of Usability talk at Google Cloud Next '17 by Alley Rutzel

Usability is a quality attribute that assesses how easy user interfaces are to use.

6 Quality components:

  1. Learnability - How easy is the first-time experience.
  2. Efficiency - How few keystrokes (or clicks / or whatever metric makes sense) are required to get the job done for repeat users.
  3. Memorability - How easy is to get started after you come back to the product after a while.
  4. Accessibility - Not just for people with disabilities. Think of how easy it is to use when outside under sunlight, or if user breaks their hand.

Keybase proof

I hereby claim:

  • I am pixyj on github.
  • I am pixyj (https://keybase.io/pixyj) on keybase.
  • I have a public key whose fingerprint is 8D6D 422D 5213 FBBA 29A7 B0A6 64B8 E4D3 338B E6AF

To claim this, I am signing this object:

@pixyj
pixyj / female-names.txt
Created December 21, 2017 14:23
Trie Implementation in Python
aaren
aarika
abagael
abagail
abbe
abbey
abbi
abbie
abby
abbye