Skip to content

Instantly share code, notes, and snippets.

View filippo's full-sized avatar

Filippo Pacini filippo

View GitHub Profile
loop(Req, DocRoot) ->
Mod = ewgi_mochiweb:new(fun ?MODULE:simple_stack/1),
Mod:run(Req).
simple_stack(Ctx) ->
to_upper(hello_app(Ctx)).
hello_app({ewgi_context, Request, _Response}) ->
ResponseHeaders = [{"Content-type", "text/plain"}],
@filippo
filippo / nginx_proxy_to_couchdb.conf
Created July 7, 2010 13:12
nginx proxy to couchdb using jquery.couch.js
#All calls to urls under /dbs are proxyed to couchdb
# eg. a call to http://example.com/dbs/mydb becomes http://localhost:5984/mydb
location /dbs {
rewrite /dbs/(.*) /$1 break;
proxy_pass http://localhost:5984;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
@filippo
filippo / accept_languages.py
Created July 26, 2011 10:57
decode HTTP_ACCEPT_LANGUAGE headers
def accept_languages(browser_pref_langs):
"""Parses the request and return language list.
browser_pref_langs is the plain Accept-Language http request header
value.
Stolen from Products.PloneLanguageTool, under GPL (c) Plone Foundation,
slightly modified.
Taken from tweetengine http://github.com/Arachnid/tweetengine/
"""
browser_pref_langs = browser_pref_langs.split(',')
i = 0
@filippo
filippo / ex.php
Created October 3, 2011 15:37
How to return a file in HTTP with a given name
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// and It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>
@filippo
filippo / cors-nginx.conf
Created May 6, 2012 18:54 — forked from michiel/cors-nginx.conf
Wide-open CORS config for nginx
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' 'http://10.140.10.40';
#
import Cookie
c = Cookie.SimpleCookie()
c.load('__atrfs={"dr":"http://example.org/?id=1"')
# I solved removing the add this cookies from the string before parsing
# It's an ugly hack but seems to work.
def sanitizeCookie(aCookie):
c = re.sub('\s?__atuvc.*?;', '', aCookie)
c = re.sub('\s?__at.*?};?', '', c)
/* See also: "Learning Javascript Design Patterns" by Addy Osmani
* http://addyosmani.com/resources/essentialjsdesignpatterns/book/
*
* for examples on how to use pubsub as event aggregator (Mediator)
*
*/
var pubsub = {};
(function(q) {
var topics = {}, subUid = -1;
q.subscribe = function(topic, func) {
@filippo
filippo / zimbra-all-accounts-and-domains.sh
Last active May 27, 2021 13:40
Zimbra remove all accounts TODO: find a better way to automate this
# as zimbra user
$ zmprov -l gaa |grep -v admin-domain.com >/tmp/accounts.zmp
$ zmprov -l gad |grep -v admin-domain.com >/tmp/domains.zmp
@filippo
filippo / error-examples.js
Last active July 29, 2018 06:19
Error management in javascript
/*
* From the article "The Art of Error"
* http://dailyjs.com/2014/01/30/exception-error/
*/
/* node example */
var assert = require('assert');
var util = require('util');
function NotFound(message) {
@filippo
filippo / zimbra-backup-emails.sh
Created January 28, 2015 16:04
How to backup and restore emails of a specific account on zimbra
# The command below creates a tgz file with all emails for user@domain.com in .eml format:
# execute as root
/opt/zimbra/bin/zmmailbox -z -m user@domain.com getRestURL "//?fmt=tgz" > /tmp/account.tgz
# You can do the same via a REST URL:
wget http://ZIMBRA.SERVER/home/user@domain.com/?fmt=tgz
# to restore email:
/opt/zimbra/bin/zmmailbox -z -m user@domain.com postRestURL "//?fmt=tgz&resolve=reset" /tmp/account.tgz