This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Предположим, что картинка находится в диве ( <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}); //вставляем старую картинку и возвращаем прозрачность |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if isinstance( string , str ): | |
from hashlib import md5 | |
return md5( str.encode( string ) ).hexdigest() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: UTF-8 -*- | |
#THIRD-PARTY MODULES | |
import bottle | |
@bottle.route('/') | |
def index(): | |
return 'Hello, World!' | |
#BOTTLE STARTER |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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) | |
^ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer