Skip to content

Instantly share code, notes, and snippets.

View marcinkuzminski's full-sized avatar

Marcin Kuźmiński marcinkuzminski

View GitHub Profile
class TestRequest(pyramid.testing.DummyRequest):
application_url = kwargs.pop('application_url', 'http://example.com')
host = kwargs.pop('host', 'example.com:80')
domain = kwargs.pop('domain', 'example.com')
def translate(self, msg):
return msg
def get_partial_renderer(self, tmpl_name):
@marcinkuzminski
marcinkuzminski / gist:5460429
Created April 25, 2013 15:08
socket.io websockets
upstream yourbacked {
server 127.0.0.1:9000;
}
location /socket.io/ {
proxy_pass http://yourbacked;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
@marcinkuzminski
marcinkuzminski / gist:5459173
Last active December 16, 2015 15:50
custom format for nginx that mesures time of requests
log_format main '$remote_addr - $remote_user $request_time [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;

Setting up RhodeCode on Ubuntu Server 12.04

Preparation

  1. Install Ubuntu Server.
  2. Update Ubuntu with the commands:
import sqlalchemy
from sqlalchemy import *
from sqlalchemy.ext.mutable import Mutable
class JSONEncodedObj(types.TypeDecorator):
"""Represents an immutable structure as a json-encoded string."""
impl = String
def process_bind_param(self, value, dialect):
@marcinkuzminski
marcinkuzminski / gist:3905373
Last active October 11, 2015 19:08
Multiple SSH keys search
touch ~/.ssh/config
chmod 600 ~/.ssh/config
echo "IdentityFile ~/.ssh/id_rsa.work" >> ~/.ssh/config
echo "IdentityFile ~/.ssh/id_rsa.misc" >> ~/.ssh/config
@marcinkuzminski
marcinkuzminski / gist:1666607
Created January 23, 2012 23:59
JS UUID rfc4122 version 4
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
@marcinkuzminski
marcinkuzminski / gist:1104278
Last active September 26, 2015 13:28
JS: Replaces found url patterns in text to a clickable link
/**
* Replaces found url patterns in text
* to a clickable link
*/
function URL2Link(text) {
var pat = /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return text.replace(pat,"<a href='$1'>$1</a>");
}
@marcinkuzminski
marcinkuzminski / gist:1027612
Created June 15, 2011 17:31
Python password pattern
Password pattern
# min 6 + 1 (Digit or special sign) and small letters
PASSWD_PAT = re.compile('(?=^.{6,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[a-z]).*$')