Skip to content

Instantly share code, notes, and snippets.

View garbados's full-sized avatar

DFB garbados

View GitHub Profile
@garbados
garbados / gist:4732069
Created February 7, 2013 16:22
Writes to crontab a command that, at the beginning of every hour, reads aloud the result of `fortune`. Problem: overwrites existing crontab.
echo "00 * * * * `which fortune` | say" | crontab
@garbados
garbados / md2flask
Created May 20, 2013 22:15
Use like this: `cat [filename].md | md2flask` It kicks up a Flask server that renders the markdown as HTML for your viewing pleasure. Change `/usr/bin/python` to whatever your terminal returns for `which python`, run `chmod +x md2flask`, add it to your $PATH, do a little dance, make a little love, and you should be alright.
#!/usr/bin/python
import flask
import markdown
import sys
app = flask.Flask(__name__)
md = sys.stdin.read()
@app.route('/')
@garbados
garbados / gist:5672627
Last active December 17, 2015 21:09
map function for ngram mapreduce
map = (doc) ->
size = 4 # = the n in ngram
# chunk function
chunk = (arr, len) ->
chunks = []
i = 0
while i < arr.length
chunks.push arr.slice(i, i += len)
return (x for x in chunks when x.length is len)
# reduce to tokens
@garbados
garbados / vg.rb
Created June 10, 2013 21:22
multi-box networking setup
(1..5).each do |i|
config.vm.define "box#{i}" do |box|
box.vm.network :forwarded_port, guest: 5984, host: 8000+i,
auto_correct: true
end
end
@garbados
garbados / app.js
Created June 24, 2013 21:41
Example of pushing data to a Geckoboard widget. Based on this documentation: http://docs.geckoboard.com/custom-widgets/push.html Specific to the "numbers" widget. Find more widget specs here: http://docs.geckoboard.com/custom-widgets/index.html#types
var config = require("./config")
, request = require("request")
, i = 0;
function ping(){
request.post({
url: config.push_url,
json: {
api_key: config.api_key,
data:{
@garbados
garbados / gist:5988506
Created July 12, 2013 23:05
unknown_error
{ method: 'POST',
headers:
{ 'content-type': 'application/json',
accept: 'application/json' },
uri: 'http://localhost:5984/eggchair',
body: '{"_id":"vQAcIFx.jpg","timestamp":1371708302000,"_attachments":{"content":"/9j/4gv4SUNDX1BST0ZJTEUAAQEAAAvoAAAAAAIAAABtbnRyUkdCIFhZWiAH2QADABsAFQAkAB9hY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAA9tYAAQAAAADTLQAAAAAp+D3er/JVrnhC+uTKgzkNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBkZXNjAAABRAAAAHliWFlaAAABwAAAABRiVFJDAAAB1AAACAxkbWRkAAAJ4AAAAIhnWFlaAAAKaAAAABRnVFJDAAAB1AAACAxsdW1pAAAKfAAAABRtZWFzAAAKkAAAACRia3B0AAAKtAAAABRyWFlaAAAKyAAAABRyVFJDAAAB1AAACAx0ZWNoAAAK3AAAAAx2dWVkAAAK6AAAAId3dHB0AAALcAAAABRjcHJ0AAALhAAAADdjaGFkAAALvAAAACxkZXNjAAAAAAAAAB9zUkdCIElFQzYxOTY2LTItMSBibGFjayBzY2FsZWQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWFlaIAAAAAAAACSgAAAPhAAAts9jdXJ2AAAAAAAABAAAAAAFAAoADwAUABkAHgAjACgALQAyADcAOwBAAEUASgBPAFQAWQBeAGMAaABtAHIAdwB8AIEAhgCLAJAAlQCaAJ8ApACpAK4AsgC3ALwAwQDGAMsA0ADVANsA4ADlAO
@garbados
garbados / gist:5995080
Created July 14, 2013 17:51
Except from the Yeoman template [generator-couchapp](https://github.com/garbados/generator-couchapp) that recursively copies everything in the template directory accordingly to some simple rules. Cheap time-saver.
CouchappGenerator.prototype.app = function app() {
// copy everything in `templates` based on rules:
// - if dir, this.directory
// - if filename starts with '__', ignore
// - if filename starts with '_', this.template
// - else, this.copy
var files = fs.readdirSync(__dirname + "/templates");
for(var i in files){
var stat = fs.statSync(__dirname + "/templates/" + files[i]);
if(stat.isDirectory()){
@garbados
garbados / gist:5995785
Created July 14, 2013 20:17
`yo angular` Gruntfile.js modified for Couchapps.
// Generated on 2013-07-14 using generator-angular 0.3.0
'use strict';
var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT });
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
// # Globbing
// for performance reasons we're only matching one level down:

Windows Azure "ResourceProvider" Design

This doc outlines how to create a ResourceProvider to integrate Cloudant into the Microsoft Azure markertplace.

What?

Microsoft requires us to have a ResourceProvider (RP) that responds to HTTP requests, in order to mediate requests around Subscriptions and Resources.

Subscriptions are roughly analogous to a Cloudant account, while Resources equivocate to databases. The ResourceProvider must provide CRUD operations against both of these entity types. Various gotchas complicate this:

@garbados
garbados / counter.js
Last active December 20, 2015 04:39
JavaScript "Counter" object for iterating over asynchronous tasks, so you can do something once they're done even if they don't complete in any known order.
// calls `cb` after `next()` meets `end`
// useful for asynchronous iteration
var Counter = function(end, cb){
this._count = 0;
this.next = function(){
this._count++;
if(this._count === end){
cb();
}
}