Skip to content

Instantly share code, notes, and snippets.

View goinnn's full-sized avatar
🏠
Working remotely

Pablo Martín goinnn

🏠
Working remotely
View GitHub Profile
@netj
netj / memusg
Last active June 25, 2024 17:39
memusg -- Measure memory usage of processes
#!/usr/bin/env bash
# memusg -- Measure memory usage of processes
# Usage: memusg COMMAND [ARGS]...
#
# Author: Jaeho Shin <netj@sparcs.org>
# Created: 2010-08-16
############################################################################
# Copyright 2010 Jaeho Shin. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
@Ciantic
Ciantic / multisettings.py
Created January 29, 2011 17:31
Django settings.py that can handle
"""Multisite - individual site for request"""
from django.conf import settings
from threading import local
def make_tls_property(default=None):
"""Creates a class-wide instance property with a thread-specific value."""
class TLSProperty(object):
def __init__(self):
self.local = local()
@ibeex
ibeex / auth.py
Created October 14, 2011 20:04
Python LDAP (ActiveDirectory) authentication
import ldap
def check_credentials(username, password):
"""Verifies credentials for username and password.
Returns None on success or a string describing the error on failure
# Adapt to your needs
"""
LDAP_SERVER = 'ldap://xxx'
# fully qualified AD user name
LDAP_USERNAME = '%s@xxx.xx' % username
@vgoklani
vgoklani / mongodb_drop.py
Created January 3, 2012 18:40
drop a database or collection via pymongo
# dropping a database via pymongo
from pymongo import Connection
c = Connection()
c.drop_database('mydatabase')
# drop a collection via pymongo
from pymongo import Connection
c = Connection()
c['mydatabase'].drop_collection('mycollection')
@visnup
visnup / lock.css
Created May 5, 2012 20:31
"lock" orientation of a website for mobile (iPad, iPhone)
/* if portrait mode is detected, rotate the entire site -90 degrees to hint rotating to landscape */
@media (orientation: portrait) {
body {
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
transform: rotate(-90deg);
}
}
@armonge
armonge / gist:2830057
Created May 29, 2012 19:04
django youtube field
import urlparse
import re
from django.db import models
from django import forms
def validate_youtube_url(value):
'''El patron lo saque de http://stackoverflow.com/questions/2964678/jquery-youtube-url-validation-with-regex'''
pattern = r'^http:\/\/(?:www\.)?youtube.com\/watch\?(?=.*v=\w+)(?:\S+)?$'
@mcrider
mcrider / cvson.json
Created October 20, 2012 22:51
Example CV JSON
{
"firstName": "Reginald",
"lastName": "Fake",
"gender": "Male",
"dob":"1983-01-01",
"email":"fakeEmail@gmail.com",
"address": {
"streetAddress": "21 Fake Street",
"city": "New York City",
"state": "NY",
@goinnn
goinnn / form_process.py
Created October 26, 2012 11:10
Example the edit and add views to the form process
def content_add(request, template_name='content/content_add.html', extra_context=None):
extra_context = extra_context or {}
extra_context['submit'] = 'Add'
return content_edit(request, template_name=template_name, extra_context=extra_context)
def content_edit(request, content_id=None, template_name='content/content_edit.html', extra_context=None):
data = instance = None
extra_context = extra_context or {}
if request.method == 'POST':
@goinnn
goinnn / gist:5530987
Last active December 17, 2015 01:49 — forked from armonge/gist:2830057
import urlparse
import re
from django import forms
from django.db import models
from django.utils.translation import ugettext_lazy as _
def validate_youtube_url(value):
'''El patron lo saque de http://stackoverflow.com/questions/2964678/jquery-youtube-url-validation-with-regex'''
@rubanm
rubanm / paramiko-sftp.py
Created June 19, 2013 21:27
Paramiko SFTP username/password authentication via SOCKS proxy
import paramiko
import socket
import socks
# set up SOCKS proxy
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxy_details['host'],
proxy_details['port'], True, proxy_details['username'],
proxy_details['password'])
socket.socket = socks.socksocket