Skip to content

Instantly share code, notes, and snippets.

@nnarhinen
nnarhinen / app.js
Last active December 21, 2015 22:19
Automatically join sockets to user-specific rooms using express.js sessions and socket.io
/**
* Module dependencies.
*/
var express = require('express'),
http = require('http'),
RedisStore = require('connect-redis')(express),
redis = require('redis'),
cookie = require('cookie'),
connect = require('connect'),
@nnarhinen
nnarhinen / server.js
Last active December 21, 2015 22:19
Automatically keep your backbone models up-to-date via web sockets by listening to couchdb changes feed
var db = new (require('cradle').Connection)().database('my_db');
db.info(function(err, result) {
var seq = result.update_seq;
db.changes({since: seq, include_docs: true}).on('change', function(change) {
if (change.doc && change.doc.owner) {
io.sockets.in(change.doc.owner).emit('change:' + change.doc.type, decorate(change.doc));
}
});
});
@nnarhinen
nnarhinen / express-server-generator.js
Last active February 28, 2016 17:48
Example files on how to use ES6 generators in your code to reduce callback nesting
'use strict';
/*
* Express server using ES6 generators
* Use node 0.11
* run with node --harmony express-server-generator.js
*/
var Q = require('q'),
HTTP = require('q-io/http'),
express = require('express'),
http = require('http');
@nnarhinen
nnarhinen / index.html
Created August 9, 2013 07:42
POST Form to new window and wait for postMessage
<html>
<head>
<title>Post form in a new window without losing handle to the window</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(function() {
$('form').on('submit', function(ev) {
var form = $(this);
form.attr('target', 'new-window');
var scripts = document.getElementsByTagName('script');
document.writeln(scripts[scripts.length - 1].getAttribute('data-attribute'));
class LibraryView extends Backbone.View
initialize: (opts) ->
@collection.selectedCount.assign this.$('.selected_count'), 'text'
@collection.hasSelected.assign this.$('.selected_videos'), 'toggle'
@nnarhinen
nnarhinen / 0001-Failing-test-for-coffeescript-usage.patch
Created March 25, 2013 19:55
brfs isn't compatible with coffeescript
From 8fac3c9fb828a6a64ee386af089ff701719619bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niklas=20Na=CC=88rhinen?= <[email protected]>
Date: Mon, 25 Mar 2013 21:45:54 +0200
Subject: [PATCH] Failing test for coffeescript usage
---
package.json | 77 ++++++++++++++++++++++++++++----------------------------
test/bundle.js | 23 ++++++++++++++---
2 files changed, 59 insertions(+), 41 deletions(-)
@nnarhinen
nnarhinen / build.js
Created March 15, 2013 06:03
Browserify build.js file
var browserify = require('browserify'),
fs = require('fs');
var b = browserify().require('./vendor/jquery-1.9.1', { expose: 'jquery'})
.require('./vendor/js_sha', { expose: 'jssha'})
.require('./src/main', { entry: true });
b.bundle(function(err, src) {
if (err) return console.error(err);
fs.writeFileSync('./dist/library-client.js', src);
@nnarhinen
nnarhinen / couchdb_lucene_conf.json
Created March 12, 2013 08:38
Run couchdb-lucene in CircleCI
"{couch_httpd_proxy, handle_proxy_req, <<\"http://127.0.0.1:5985\">>}"
@nnarhinen
nnarhinen / .htaccess
Created February 13, 2013 06:51
Local development with yeoman and apache mod_proxy
Options -MultiViews -Indexes +FollowSymLinks
RewriteEngine On
RewriteRule ^api(.*) http://localhost:3011$1 [P]
RewriteCond %{REQUEST_URI} ^/(components|favicon|robots|images|scripts|styles|templates) [NC]
RewriteRule (.*) http://localhost:3501/$1 [P]
RewriteRule ^app(.*) http://localhost:3501$1 [P]
RewriteRule (.*) http://localhost:3501/ [P]