Skip to content

Instantly share code, notes, and snippets.

@grncdr
grncdr / echoHttpRequest.js
Created November 9, 2014 15:14 — forked from Marak/echoHttpRequest.js
Echo HTTP requests
require('bluebird');
module['exports'] = function echoHttp (hook) {
hook.debug("Debug messages are sent to the debug console");
hook.debug(hook.params);
hook.debug(hook.req.path);
@grncdr
grncdr / -
Created February 28, 2015 19:35
## THIS FILE IS MANAGED BY CHEF !
## ALL CHANGES WILL BE LOST !
storage: /var/lib/sinopia
users:
admin:
password: d033e22ae348aeb5660fc2140aec35850c4da997
stephen:
password: 50f549c3f7508d8a442df7979dabe656e28bea24
@grncdr
grncdr / protected-ipfs-api.md
Last active August 29, 2015 14:22
Ideas about using IPFS from browsers

@ehd and myself have been playing around with a concept that is sort of like an ipfs-backed-in-browser-code-editor-and-live-coding-environment.* For this to work properly the browser clearly needs access to IPFS. Luckily there is a nice API! Unfortunately, it defaults to disallowing CORS.

I'm aware of API_ORIGIN and ipfs/kubo#1215, but that approach requires the user to understand a lot of stuff: environment variables, IPFS, CORS, and other 4-letter-initialisms to make it work. This is way too high of a barrier for anybody but the most committed tech-savvy user. It also subtly encourages allowing too broad of access (e.g. allow origin of *), which is pretty sketchy in my opinion.

I'd like to propose that the IPFS API offer a more holistic approach to this problem, and will even dust off my pre-1.0 golang skills to implement it if people agree...

* I'll leave it up to him to present the proper German compound word 😉

Proposal: "Protected" API

#!/bin/sh
_command_prefix=${@:2}
echo '<openbox_pipe_menu>'
for i in `$1`; do
echo "<item label=\"$i\">"
echo '<action name="Execute">'
echo "<command>$_command_prefix $i</command>"
echo '</action>'
echo '</item>'
@grncdr
grncdr / uriTemplateMiddleware.coffee
Created October 23, 2011 02:29
Generate a set of URI Templates from the routes in an express app
makeTemplate = (path) ->
i = 0
path.replace(/\*(\w)?/g, "{+raw#{i++}}$1")
.replace(/:(\w+)/g, '{$1}')
.replace(/List}/g, 's*}')
uriTemplateMiddleware = (path='/') ->
spec = null
(req, res, next) ->
if req.path == path
vows = require 'vows'
assert = require 'assert'
{mock, expect, lastCall, verify, pred, isDeep, any, verifyNoMore} = require './mtfw'
suite = vows.describe('mtfw core').addBatch "A mock will":
topic: -> mock()
"be an object": (m) -> assert.isObject m
"create new mocks when properties are accessed": ->
m1 = mock()
@grncdr
grncdr / find-the-block.js
Created January 17, 2012 03:55 — forked from isaacs/find-the-block.js
just changing names
// block-lambda proponents: what does this program do?
function in_canadian (speak_cb) {
add_eh = {|y|
return y + ", eh?"
}
// now here comes a bunch of code.
// imagine there are 50 lines here
@grncdr
grncdr / config-loader.js
Created May 30, 2012 18:56
simple re-loadable configuration using JS modules
inspect = require('util').inspect
module.exports = function (config_path, opts) {
var settings = {
toJSON: function() { return this.__proto__ },
inspect: function() { return inspect(this.__proto__) },
}
opts || (opts = {})
if (!opts.error) {
@grncdr
grncdr / gist:4554165
Last active December 11, 2015 05:48 — forked from jlongster/gist:3881008
hygienic destructuring var assignments with sweet.js
macro $do {
case ($($x = $y) (,) ...) $body => {
(function ($x (,) ...) $body)($y (,) ...)
}
case $name ($($x = $y) (,) ...) $body => {
(function $name ($x (,) ...) $body)($y (,) ...)
}
}
macro $var {
@grncdr
grncdr / gist:4712845
Last active December 12, 2015 04:18
Log of vim crashing when loading YouCompleteMe
chdir(/usr/local/Cellar/macvim/7.3-66/MacVim.app/Contents/Resources/vim)
fchdir() to previous dir
sourcing "$VIM/vimrc"
finished sourcing $VIM/vimrc
chdir(/Users/stephen)
fchdir() to previous dir
sourcing "$HOME/.vimrc"
Searching for "ftoff.vim" in "/Users/stephen/.vim,/usr/local/Cellar/macvim/7.3-66/MacVim.app/Contents/Resources/vim/vimfiles,/usr/local/Cellar/macvim/7.3-66/MacVim.app/Contents/Resources/vim/runtime,/usr/local/Cellar/macvim/7.3-66/MacVim.app/Contents/Resources/vim/vimfiles/after,/Users/stephen/.vim/after"
Searching for "/Users/stephen/.vim/ftoff.vim"