This file contains 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
#! /usr/bin/bash | |
"""": | |
# if Nix not installed, install it, then rerun this script with nix-shell | |
[ -f /etc/nix/nix.conf ] || curl -L https://nixos.org/nix/install | sh -s -- --daemon | |
exec nix-shell --command "python $0 $@" \ | |
-p python311 \ | |
-p python3Packages.numpy | |
# add any package you want above and they will be added to the shell | |
exit 1 | |
""" #" |
This file contains 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
import jwt | |
jwt_data = jwt.decode(some_data, secret) | |
form = Form(.... hidden=dict(mydata=jwt_data)) | |
if form.accepted: | |
some_data = jwt.decode(request.forms['mydata'], secret) | |
... | |
This file contains 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
class Injector(Fixture): | |
def __init__(self, **objects): | |
self.objects = objects | |
def transform(self, output, shared_data=None): | |
if isinstance(output, dict): | |
output.update(**self.objects) | |
return output | |
injector = Injector(menu) |
This file contains 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 pydal import DAL, Field | |
db=DAL() | |
db.define_table('person', Field('name')) | |
id = db.person.insert(name="Max") | |
print("%(name)s" % id) | |
db.define_table('dog', Field('name'), Field('owner', db.person)) | |
db.dog.insert(name="Snoopy", owner=id) | |
dog = db(db.dog).select().first() | |
print("%(name)s" % dog.owner) |
This file contains 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
# append to scaffoling models/db.py | |
db.define_table('contact', | |
Field('your_name',requires=IS_NOT_EMPTY()), | |
Field('email',requires=IS_EMAIL()), | |
Field('message','text')) | |
# append to scaffolding controllers/default.py | |
def contact_us(): | |
form = SQLFORM(db.contact) | |
if form.process().accepted: |
This file contains 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
jQuery('input.rating,input[name*="rating"]').each(function(){ | |
var span = jQuery('<span style="white-space:nowrap"><span class="rate0">◎</span><span class="rate1">☆</span><span class="rate2">☆</span><span class="rate3">☆</span><span class="rate4">☆</span><span class="rate5">☆</span></span>'); | |
var self = jQuery(this).hide().after(span); | |
var fill_stars = function() { | |
var k = parseInt(self.val()) || 0; | |
for(var i=1; i<6; i++) span.find('.rate'+i).html((i<=k)?'★':'☆'); | |
}; | |
for(var k=0; k<6; k++) (function(k){ | |
span.find('.rate'+k).mouseover(function(){ | |
for(var i=1; i<6; i++) span.find('.rate'+i).html((i<=k)?'★':'☆'); |
This file contains 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
""" | |
Usage: | |
python jinja2web2py.py jinjatemplate.html > web2pytemplate.html | |
Disclaimer. It is not perfect. Some times minor manual tweaks may be necessary. | |
Notice the web2py template language was invented in 2007 and consists of pure Python code. | |
The opposite conversion is not possible because arbitrary Python code cannot be converted to a jinja template. | |
""" | |
import sys |
This file contains 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
""" | |
Usage: | |
python jinja2web2py.py jinjatemplate.html > web2pytemplate.html | |
Disclaimer. It is not perfect. Some times minor manual tweaks may be necessary. | |
Notice the web2py template language was invented in 2007 and consists of pure Python code. | |
The opposite conversion is not possible because Python code cannot be converted to a jinja template. | |
""" | |
import sys |
This file contains 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
""" | |
Usage: | |
python jinja2web2py.py jinjatemplate.html > web2pytemplate.html | |
Disclaimer. It is not perfect. Some times minor manual tweaks may be necessary. | |
Notice the web2py template language was invented in 2007 and consists of pure Python code. | |
The opposite conversion is not possible because Python code cannot be converted to a jinja template. | |
""" | |
import sys |
This file contains 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
def whoosh(folder): | |
from whoosh.index import create_in | |
from whoosh.fields import ID,TEXT,Schema | |
from whoosh.qparser import QueryParser | |
from whoosh.query import And | |
import os |
NewerOlder