Skip to content

Instantly share code, notes, and snippets.

View bbrodriges's full-sized avatar

bbrodriges bbrodriges

View GitHub Profile
@bbrodriges
bbrodriges / gist:1286814
Created October 14, 2011 11:00
PHP script execution time
<?php
$time = explode( ' ' , microtime() );
$start = $time[1] + $time[0];
/* YOUR PHP CODE HERE */
$time = explode( ' ' , microtime() );
$finish = $time[1] + $time[0];
echo 'Page generated in '.round(($finish - $start), 4).' seconds.'."\n";
@bbrodriges
bbrodriges / gist:1366532
Created November 15, 2011 09:14
Наложение картинки на картинку с прозрачностью (не тестировалось)
//Предположим, что картинка находится в диве ( <div class="myimage"><img src="/images/old-image.png"></div> )
$('div.myimage').hover(
function(){ //при наведении мыши
var sourceImg = $('div.myimage img').attr('src'); //забираем урл картинки
$('div.myimage img').attr('/images/new-image.png').css({opacity: 0.5}); //вставляем новую картинку и накладываем прозрачность 50%
$(this).css('background-image', sourceImg); //делаем оригинальную картинку фоном дива
},
function(){ //при уходе мыши
var sourceImg = $(this).css('background-image'); //забираем урл старой картинки
$('div.myimage img').attr(sourceImg).css({opacity: 1}); //вставляем старую картинку и возвращаем прозрачность
@bbrodriges
bbrodriges / gist:1375965
Created November 18, 2011 09:04
Python If->Import
if isinstance( string , str ):
from hashlib import md5
return md5( str.encode( string ) ).hexdigest()
@bbrodriges
bbrodriges / gist:1496660
Created December 19, 2011 11:03
Loadimpact test of bottle+gevent
from gevent import monkey; monkey.patch_all()
import bottle, random, pymongo
db = pymongo.Connection().tinchy.links
def generate_tinchy_id():
return ''.join( random.sample( 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890' , 5 ) )
@bottle.route('/')
def make_tinchy_url():
@bbrodriges
bbrodriges / gist:1620222
Created January 16, 2012 10:53
Bottlepy trace
Traceback (most recent call last):
File "index.py", line 5, in <module>
from routes import root #importing site routes
File "lib/routes.py", line 10, in <module>
user = users.User()
File "lib/users.py", line 16, in __init__
self.credentials = self.validate()
File "lib/users.py", line 66, in validate
uid = request.get_cookie( '__utmb' , secret = self.COOKIE_SECRET_KEY )
File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 911, in get_cookie
@bbrodriges
bbrodriges / gist:1780710
Created February 9, 2012 15:39
About bottlepy in huge projects (from bottlepy mailing list)
I'm agree with Luri, the focus of bottle is give us a light core. If you need other features, then used the particular module that you think can resolve your problem.
Which defines a huge project is not the size is the features. The use of a specific fullstack framework not gives guaranty that you can do the best way, only simplifies the development, wrong choice equals a failure.
The freedom to do switch between modules, give us the chance to think different if a approach is not good. Fullstack frameworks not always allow to do this.
@bbrodriges
bbrodriges / gist:1816769
Created February 13, 2012 12:58
HelloWorld with bottle+gevent
# -*- coding: UTF-8 -*-
#THIRD-PARTY MODULES
import bottle
@bottle.route('/')
def index():
return 'Hello, World!'
#BOTTLE STARTER
@bbrodriges
bbrodriges / gist:1816818
Created February 13, 2012 13:04
pep8 usage
$ pep8 --show-source index.py
winamq.py:10:17: E201 whitespace after '('
sys.path.append( 'lib' ) #appending /lib/ folder to import local modules
^
winamq.py:10:25: E261 at least two spaces before inline comment
sys.path.append( 'lib' ) #appending /lib/ folder to import local modules
^
winamq.py:23:16: E251 no spaces around keyword / parameter equals
bottle.run( app = routes.root, host = '0.0.0.0', port = 80)
^
@bbrodriges
bbrodriges / gist:1816829
Created February 13, 2012 13:06
pylint example
$ pylint users.py
No config file found, using default configuration
************* Module users
W:174,0: Unnecessary semicolon
C: 1,0: Missing docstring
C: 17,8:User.__init__: Invalid name "COOKIE_SECRET_KEY" (should match [a-z_][a-z0-9_]{2,30}$)
C: 16,8:User.__init__: Invalid name "db" (should match [a-z_][a-z0-9_]{2,30}$)
C: 13,0:User: Missing docstring
E:119,27:User.change_password: Undefined variable 'md5'
E:124,37:User.change_password: Undefined variable 'md5'
@bbrodriges
bbrodriges / gist:1844867
Created February 16, 2012 13:35
Setup nullmailer with Amazon SES
Integrating nullmailer with Amazon Simple Email Service (SES)
Sometime you need just to allow system tools (i.e. cron) to send mail to the hostmaster. Setting up (and maintaining) a smtp server like sendmail, Postfix or Exim is too much. What you need is nullmailer, a sendmail/qmail/etc replacement MTA for hosts which relay to a fixed set of smart relays.
Here are some notes about how to setup nullmailer to use Amazon SES (Simple Email Service). This guide applies to Ubuntu boxes, but you can easily adapt it to other Linux flavors.
I assume that you already know how to setup an Amazon Simple Email Service account and how to test it in the sandbox . This means that you have signed the service, verified and tested at least a couple of e-mail address using Amazon Management Console facility. If this is not your case, please refer to this guide.
To begin, you will need to set up a secure tunnel using stunnel package. In the following procedure, we use port 2525 as your stunnel port. If you are using a differe