Skip to content

Instantly share code, notes, and snippets.

View filippo's full-sized avatar

Filippo Pacini filippo

View GitHub Profile
@filippo
filippo / WORDPRESS
Last active August 29, 2015 14:17
wordpress tips and tricks
this gist contains various tips and tricks for wordpress management and development
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 / fix-unicode-error.py
Created April 2, 2017 11:06
Python v2.7 - Error Cheetah Unicode
# In case of unicode decoding errors in Python 2.7 we can fix with an ugly hack:
# file Compiler.py row 1579 wrap the line:
source = unicode(source)
# in a try that intercepts the error and returns the template unchanged
try:
source = unicode(source)
except UnicodeDecodeError:
@filippo
filippo / ssh_persistent_connections
Last active December 7, 2017 08:58 — forked from rasky/.config
SSH persistent connections
# this re-enables ssh-dss on Fedora 23... until I change all the keys
PubkeyAcceptedKeyTypes +ssh-dss
#add to .ssh/config
Host *
ControlPersist yes
ControlMaster auto
ControlPath /tmp/ssh-%r@%h:%p
ServerAliveInterval 60