Skip to content

Instantly share code, notes, and snippets.

View garbados's full-sized avatar

DFB garbados

View GitHub Profile
@garbados
garbados / gist:f82604ea639e0e47bf44
Created July 27, 2014 23:07
Falsehoods Programmers Believe About Gender
  1. There are two and only two genders.
  2. Okay, then there are two and only two biological genders.
  3. Gender is determined solely by biology.
  4. Okay, it’s mostly determined by biology, right?
  5. Please tell me it’s determined by DNA.
  6. Gender can be reliably determined through visual means. After all, no man would ever wear a burka.
  7. Once gender is set, it never changes.
  8. Even if the gender can change, it will only change from the one value to the other value.
  9. Only one gender can be “active” at the same time.
  10. We’re tracking gender now, so we’ve always tracked it.
@garbados
garbados / gist:8660588
Last active January 4, 2016 18:29
Upload your local ~/Pictures folder to a locally-running CouchDB instance, and give it a front-end with EggChair.
couchdb &
git clone git@github.com:garbados/quilter.git
cd quilter
npm install
./bin/index.js push --local ~/Pictures --remote http://localhost:5984/eggchair --log info
cd ..
git clone git@github.com:garbados/egg_chair.git
cd egg_chair
npm install
mv config.js.example config.js
@garbados
garbados / design_doc.js
Created January 14, 2014 21:14
Summing values by a date range. For @dj_agiledev :D
{
_id: '_design/queries',
views: {
sum_by_date: {
map: function (doc) {
if (doc.created_at) {
// normalize doc.created_at into an integer timestamp
// in this case, milliseconds since epoch
var date = new Date(doc.created_at).getTime();
emit(doc.created_at, doc.VALUE_YOU_WANT_TO_SUM);
[{
"from": "",
"to": "index.html",
"method": "GET",
"query": {}
},{
"from": "/api",
"to": "/../../",
"query": {}
},{
@garbados
garbados / gist:8357943
Created January 10, 2014 16:52
How to stream a CouchDB view to a response using Nano.
var nano = require('nano');
var url = '...'; // URL to your Cloudant database
var db = nano(url);
app.get('route', function (req, res) {
db.view('design_name', 'view_name').pipe(res);
});
@garbados
garbados / player.rb
Last active January 2, 2016 12:39
Solution to ryanb/ruby-warrior intermediate difficulty, on epic.
## PERFORMANCE (1/7/13)
#
# CONGRATULATIONS! You have climbed to the top of the tower and rescued the fair maiden Ruby.
# Your average grade for this tower is: A
#
# Level 1: S
# Level 2: A
# Level 3: A
# Level 4: B
# Level 5: A
@garbados
garbados / warrior.rb
Last active January 2, 2016 10:59
Solution to every level of RubyWarrior (https://www.bloc.io/ruby-warrior/#/). Heavily borrowed from https://gist.github.com/jnf/6198927
# N.B. doesn't get maximum score:
# * won't get captives behind the warrior
# * will shoot captives at look[1] if an enemy is in look[2]
class Player
def play_turn(warrior)
@warrior = warrior
## uncomment `@max_health` and `@prev_health` on level 3
# @max_health ||= warrior.health # set to `1` to complete level 8 in 27 turns
# @prev_health ||= @max_health
@garbados
garbados / gist:8204632
Last active January 1, 2016 21:39
Using `jq` to pipe couchdb contents into `dat`
# _all_docs
curl http://localhost:5984/eggchair/_all_docs?include_docs=true | jq -c ".rows[] | .doc" | dat --json
# _changes
curl http://localhost:5984/eggchair/_changes?include_docs=true | jq -c ".results[] | .doc" | dat --json
/*
* Given array `records` and function `fn`
* returns an array where
* any records with duplicate `fn(record)` values
* are omitted.
*
* Runs in O(n) where n is records.length
*/
function remove_duplicates (records, fn) {
var uniques = {},
@garbados
garbados / noblizer.py
Created October 10, 2013 19:32
A Python script to generate pithy witticisms, Brad Noble's hallmark.
import random
prefix = [
'do',
'grow',
'edge',
'next',
'build',
'sleep',
'play',