Skip to content

Instantly share code, notes, and snippets.

View iolloyd's full-sized avatar
💭
Busy bee

Lloyd Moore iolloyd

💭
Busy bee
View GitHub Profile
@iolloyd
iolloyd / hammerspoon-cool.txt
Created October 4, 2015 19:53
Explanation of using hammerspoon to watch for configuration changes
Simple configuration reloading
You may have noticed that while you're editing the config, it's a little bit annoying to have to keep choosing the Reload Config menu item every time you make a change. We can fix that by adding a keyboard shortcut to reload the config:
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", function()
hs.reload()
end)
hs.alert.show("Config loaded")
We have now bound ⌘+⌥+⌃+R to a function that will reload the config and display a simple alert banner on the screen for a couple of seconds.
One important detail to call out here is that hs.reload() destroys the current Lua interpreter and creates a new one. If we had any code after hs.reload() in this function, it would not be called.
@iolloyd
iolloyd / sqlalchemy
Last active September 18, 2015 10:16
optionally get column names with result set
from sqlalchemy import create_engine
def db_results(conn, sql, columns=True):
x = conn.execute(sql)
out = x.fetchall()
if columns:
out = [dict(zip(x.keys(), a)) for a in out]
return out
engine = create_engine('mssql+pymssql://user:[email protected]:1433/my_db')
@iolloyd
iolloyd / 0_reuse_code.js
Last active August 26, 2015 11:02
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@iolloyd
iolloyd / while_chunk.php
Last active August 29, 2015 14:28
[a,b,c,d] => [a => b, c => d]
$out = [];
while($array && $out[array_shift($array)] = array_shift($array));
@iolloyd
iolloyd / chunk_ver_2.php
Created August 24, 2015 19:26
[a,b,c,d] => [a => b, c => d]
$chunks = array_chunk($array, 2);
for($i=0, $out=[]; $i < count($chunks); $out[$chunks[$i][0]] = $chunks[$i][1], $i++);
@iolloyd
iolloyd / chunk.php
Created August 24, 2015 19:02
[a,b,c,d] => [a => b, c => d]
<?php
2
3 $array = ['one', 'two', 'three', 'four', 'five', 'six'];
4
5 $chunks = array_chunk($array, 2);
6 $firsts = array_map(function ($x) {return $x[0]; }, $chunks);
7 $seconds = array_map(function ($x){return $x[1]; }, $chunks);
8 $result = array_combine($firsts, $seconds);
9 print_r($result);
10
@iolloyd
iolloyd / quick-poached-eggs.txt
Created August 21, 2015 07:36
quick poached eggs in a microwave
1. Crack one or two eggs into a breakfast bowl
2. Add about 1/3 to 1/2 cup of water
3. Add a spoonful of vinegar, although not essential
4. Microwave on full power for about a minute and check the eggs
5. Microwave a further 30 - 45 seconds, a bit longer for two eggs
6. Carefully pour the water away, enjoy
# Ring the bell if any background window rang a bell
set -g bell-action any
# Default termtype. If the rcfile sets $TERM, that overrides this value.
set -g default-terminal screen-256color
# Keep your finger on ctrl, or don't
bind-key ^D detach-client
# Create splits and vertical splits
set nocompatible
execute pathogen#infect()
syntax on
filetype plugin indent on
if filereadable(expand("~/.vimrc.before"))
source ~/.vimrc.before
endif
set number
@iolloyd
iolloyd / db_migrations_flow.md
Last active August 29, 2015 14:21
Lookbooks migrations workflow

DB migrations flow

This is a proposal for dealing with database migrations when using git (or similiar). The problem with migrations is ensuring that the current state of the database is in sync with the code-base. In practice, this means being able to guarantee that the state of the database correctly reflects the version of the code checked out.

The correct way to build the database schema is to run all db migrations from zero. But as the project grows, this takes longer and longer to execute and quickly becomes inpractical.

To avoid having to re-run all the migrations, it makes sense to have a base sql that avoids running earlier migrations that are relevant to the currently deployed code.

With that in mind, the following is proposed: