This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var grunt = require('grunt'); | |
var controllers = []; | |
grunt.file.expand({ cwd: '' }, 'app/controllers/**/*.js').forEach(function(filename) { | |
// The routes in this file | |
var controller = require(process.cwd() + '/' + filename); | |
controller.filename = filename; | |
controller.priority = controller.priority || 1; | |
controllers.push(controller) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"query_string": { | |
"query": "couchbaseDocument.doc.type:keyword_slice" | |
} | |
}, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Don't forget to npm install hoxy | |
var hoxy = require('hoxy'); | |
var proxy = new hoxy.Proxy().listen(8080); | |
proxy.intercept({ | |
phase: 'request', | |
}, function(req, resp) { | |
console.log('\n\n=============================================='); | |
console.log('Request: ' + req.fullUrl()); | |
Object.keys(req.headers).forEach(function(header) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NODE_ENV=development node sample-usage.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Somewhere in your javascript assets included at the end of the document | |
$(document).ready(function() { | |
loaded = true; | |
doInit(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- eg SELECT sort_order('-relevance', ['title', 'updated_at', 'relevance']) | |
-- Optionally specify +/- prefix for sort field. Invalid sort field uses first in array | |
CREATE OR REPLACE FUNCTION sort_order(_field text, _valid text[]) RETURNS json AS | |
$$ | |
_field = decodeURIComponent(_field); | |
var directions = { ' ': 'ASC', '-': 'DESC' }; // + becomes space | |
var direction = directions[_field[0]]; | |
if(direction) { _field = _field.slice(1) } else { direction = directions['-']; }; | |
if(_valid.indexOf(_field) < 0) _field = _valid[0]; | |
return { field: _field, direction: direction }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/sh | |
( | |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">" | |
psql -c "COPY (SELECT xmlelement(name url, xmlforest('http://writebox.co.uk/news/' || slug AS loc, to_char(updated_at, 'YYYY-MM-DDThh:mm:ss+07:00') AS lastmod)) FROM news) TO STDOUT" writebox_$2 | |
echo "</urlset>" | |
) > $1/public/sitemap.xml | |
cat $1/public/sitemap.xml | gzip -9 > $1/public/sitemap.xml.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Find which tables were involved in a number of queries. | |
* This is obviously a contrived example. A practical application would be to wrap all | |
* the queries for a web page in a transaction (perhaps using before/after filters in | |
* the case of Rails) and then use the stats for cache invalidation. | |
*/ | |
BEGIN TRANSACTION; | |
/* Run the queries */ | |
SELECT * from news LIMIT 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadGists() { | |
var els = $('code[gist]'), gists = {}, code = [], stylesheets = []; | |
// Get elements referencing a gist and build a gists hash referencing the elements that use it | |
els.each(function(idx, rawEl) { | |
var el = $(rawEl), gist = el.attr('gist'); | |
rawEl.gist = gist; | |
rawEl.file = el.attr('file'); | |
gists[gist] = gists[gist] || { targets: [] }; | |
gists[gist].targets.push(el); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location / { | |
try_files $uri @redis_cache; | |
add_header Source Files; # Handy for development | |
} | |
location @redis_cache { | |
# Make sure this path is correct | |
# Run "nginx -V" from the command prompt and look for --prefix=/path/to/somewhere | |
# and place redis.lua there, or use an absolute path as shown below | |
content_by_lua_file /path/to/your/config/redis.lua; |
NewerOlder