Skip to content

Instantly share code, notes, and snippets.

View sebastianrothbucher's full-sized avatar

Sebastian Rothbucher sebastianrothbucher

View GitHub Profile
@sebastianrothbucher
sebastianrothbucher / gist:23ed63bb4b8d5e95eb42
Created September 19, 2014 20:43
Config values in Couch Design Docs

Take the following simple CouchDB named test:

{"total_rows":2,"offset":0,"rows":[
{"id":"_design/tst","key":"_design/tst","value":{"rev":"3-312aaf2d14174ef415d185d460f4380a"},"doc":{"_id":"_design/tst","_rev":"3-312aaf2d14174ef415d185d460f4380a","shows":{"own":"function(doc, req){return this.configval+\" - \"+doc.docval;}"},"configval":"bla"}},
{"id":"tst2","key":"tst2","value":{"rev":"2-2f1a6af53d8b871b677f79da8e0a2f45"},"doc":{"_id":"tst2","_rev":"2-2f1a6af53d8b871b677f79da8e0a2f45","docval":"blup"}}
]}

It consists of two docs: one tst2 (a normal doc with a value "docval") plus a design document "_design/tst" with a config value "configval" and a show function printing both config val and doc val.

@sebastianrothbucher
sebastianrothbucher / gist:4135733751d39909fe54
Last active August 29, 2015 14:06
Serving HTML from a CouchDB doc

Want do use Futon or Fauxton to manage web content? here is how you do that:

{
   "_id": "_design/showfkt",
   "_rev": "11-e00cd0ba76460fe57dd767e125e6a9c4",
   "language": "javascript",
   "shows": {
       "htmlout": "function(doc, req){return doc.html;}"
 }

couchjs is a process invoked by couchdb to do the actual evaluation (e.g. run a map function that is implemented in javascript). It's an own OS process called by the couchdb main process communicating via stdin / stdout.

Hence, one way of debugging is tee-ing input and output. This should work on all platforms. I've tried on Windows (7) now with

  • Couchdb in C:\Program Files (x86)\Apache Software Foundation\CouchDB (i.e. couchjs is C:\Program Files (x86)\Apache Software Foundation\CouchDB\bin\couchjs.exe)
  • a UNIX-Shell installed (makes sense anyway, curl gets madness otherwise) via MINGW32 coming with Git at C:\Program Files (x86)\Git\ (i.e. sh.exe is C:\Program Files (x86)\Git\bin\sh.exe and all other tools are in C:\Program Files (x86)\Git\bin\ also)
  • a globally writable C:\Temp

in default.ini (BACKUP REMINDER !!! - do a backup before you try the following!), one can now change the

[query_servers]
@sebastianrothbucher
sebastianrothbucher / 0 mobile image submit.md
Last active August 29, 2015 14:17
Image upload without phonegap/Cordova

There was a talk at conc.at about mobile with nothing but the browser. I didn't make it to conc.at (shame!) but I do care about the topic. So: there is a way, just google for

<input type="file" capture="camera"

This is a small sample to get it going on CouchDB - really hacky.

Steps (at your own risk - make sure you know what's going on!):

  1. get CouchDB
  2. make it listen to all clients (not just localhost) or use an Apache Webserver in front of it

A few tipps for migrating from Couch 1.6 (CentOS) to Couch 2.0 (CentOS)

as ever: your own risk ;-)

From plain source (incl. Fauxton et al)

  • make sure to have node and npm available (otherwise yum install nodejs)
  • Erlang installation is cruel (wx...; rpm -i --nodeps is your best friend)
  • erlang-solutions-1.0-1.noarch adds the repo of pre-compiled Erlang binaries
  • rebar (directly or via erlang-solutions) and reltool (also erlang-solutions):
  • the usual drill of ./configure && make && make install (./configure -c for test suite)
<html>
<a href="data:text/plain;base64,SGV5IHRoZXJl" download="heythere.txt">Click to download</a>
</html>
@sebastianrothbucher
sebastianrothbucher / gist:02fb78eda69564fa1aa2
Created April 10, 2015 13:15
Verbose outputs of JSX compiler (CouchDB Fauxton et al)
The grunt invoke just gives "unable to read module" or something like it, one can get verbose error messages by invoking
node_modules/react-tools/bin/jsx --extension jsx app/addons/<name> app/addons/<name>
(src dir = target dir). For instance, when a problem happens in module databases:
node_modules/react-tools/bin/jsx --extension jsx app/addons/databases app/addons/databases
=> helps spotting the error rather quickly, afterwards one can move on with grunt dev or so
Konzepte: Ctrl+F, "entsprechend" und "bisher"
Code: import Framework-Klasse im Presenter, static get...()
@sebastianrothbucher
sebastianrothbucher / gist:f6d5505630f162d46f9d
Created May 1, 2015 16:00
aus "ein Text #Estimate=22 mehr Text" in Zelle I2 den Wert von Estimate als Zahl ermitteln (OOo Calc)
=WENN(ISTFEHLER(FINDEN("#Estimate=";I2));"";WERT(TEIL(I2;FINDEN("#Estimate=";I2)+LÄNGE("#Estimate=");WENN(ISTFEHLER(FINDEN(" "; I2; FINDEN("#Estimate=";I2)+LÄNGE("#Estimate=")));1000;FINDEN(" "; I2; FINDEN("#Estimate=";I2)+LÄNGE("#Estimate="))-(FINDEN("#Estimate=";I2)+LÄNGE("#Estimate="))))))
@sebastianrothbucher
sebastianrothbucher / .0intro
Last active August 29, 2015 14:22
_changes Hacks on Windows (MINGW32)
Some hacks to demonstrate _changes
1-3: display an MsgBox for each change (with more content)
4: Write to the Windows Event Log on each change
5: Create an asana task on each change