Skip to content

Instantly share code, notes, and snippets.

@pklaus
pklaus / StatusIcon.py
Created February 15, 2010 20:36
StatusIcon – A Simple Tray Icon Application Using PyGTK
#!/usr/bin/env python
# found on <http://files.majorsilence.com/rubbish/pygtk-book/pygtk-notebook-html/pygtk-notebook-latest.html#SECTION00430000000000000000>
# simple example of a tray icon application using PyGTK
import gtk
def message(data=None):
"Function to display messages to the user."
@comfuture
comfuture / manage-daemon
Created November 11, 2010 06:28
init script sample for gunicorn daemonized flask app
#!/bin/bash
gunicorn="/usr/local/bin/gunicorn"
prog="dev.maroo.info"
PROJECT_HOME="/home/maroo/sites/$prog"
pid="/var/lock/$prog"
RETVAL=0
start() {
@fhats
fhats / flask_routes_in_doc
Created December 11, 2011 03:26
Subclass of Flask to automatically store routes in the view handler's docstrings
class FlaskWithRouteDocs(Flask):
"""A subclass of Flask to allow using :route: and :methods: in docstrings, a la Sphinx."""
def route(self, rule, **options):
def decorator(f):
route_dec = super(FlaskWithRouteDocs, self).route(rule, **options)
methods_str = ','.join(options.get('methods', ['GET']))
if f.__doc__ is not None and ":route:" in f.__doc__:
f.__doc__ = f.__doc__.replace(":route:", rule)
else:
@rduplain
rduplain / README.md
Created August 30, 2012 16:07
Flask-Script: demo passing in configuration file.

This demonstrates that you can configure a Flask application through Flask-Script, without having to create a Flask instance or deal with circular dependencies. Note that Flask-Script's Manager accepts a factory function in place of a Flask app object.

Running:

python manage.py runserver

gives "Hello, world!" on http://localhost:5000/, while running:

python manage.py runserver -c development.cfg
@cybertoast
cybertoast / gist:6499708
Last active February 9, 2023 00:20
Get a list of all flask routes, and their endpoint's docstrings as a helper resource for API documentation.
@admin_api.route('/help', methods=['GET'])
def routes_info():
"""Print all defined routes and their endpoint docstrings
This also handles flask-router, which uses a centralized scheme
to deal with routes, instead of defining them as a decorator
on the target function.
"""
routes = []
for rule in app.url_map.iter_rules():
@flovntp
flovntp / LanguageSwitcherController.php
Last active August 29, 2015 14:06
Language switcher
<?php
namespace My\DesignBundle\Controller;
use eZ\Bundle\EzPublishCoreBundle\Controller;
use eZ\Publish\Core\MVC\Symfony\Routing\RouteReference;
class LanguageSwitcherController extends Controller
{
public function languagesAction( RouteReference $routeReference )
{
@brookinsconsulting
brookinsconsulting / symfony-legacy-kernel-callback-user-login-example-snippet.php
Last active September 24, 2015 10:08
This snippet of php eZ Publish 5 (Symfony Stack) code uses the legacy kernel api to login to the user you wish to use to perform actions within eZ Publish Legacy as! Default admin user used in this example. Reference: http://share.ez.no/forums/ez-publish-5-platform/interracting-with-legacy-from-symfony-command#comment84674
<?php
protected function execute(InputInterface $input, OutputInterface $output) {
$repository = $this->getContainer()->get('ezpublish.api.repository');
$legacyKernel = $this->getContainer()->get('ezpublish_legacy.kernel');
$userID = 14; // UserID of the Default Admin User
$user = $repository->getUserService()->loadUser( $userID );
$repository->setCurrentUser( $user );
$result = $legacyKernel()->runCallback(
function () use( $userID )
@dfritschy
dfritschy / SearchController.php
Created November 14, 2014 10:15
Full Text Search in eZ Publish 5 using a legacy closure
$searchText = $request->query->get('SearchText');
$sort = array( 'modified' => 'false' );
$contentTypeIdenfiers = array( 31 );
$searchResult = $this->getLegacyKernel()->runCallback(
function () use ( $searchText, $sort, $contentTypeIdenfiers )
{
// eZFunctionHandler::execute is the equivalent for a legacy template fetch function
// The following is the same than fetch( 'content', 'search', hash(...) )
return eZFunctionHandler::execute(
@eeree
eeree / resetAdminPasswordEzPublish
Created January 21, 2015 14:35
eZ Publish - how to reset admin password
SQL:
==
UPDATE `ezuser_setting` SET `is_enabled` = '1' WHERE `ezuser_setting`.`user_id` =14;
UPDATE `ezuser` SET `password_hash` = 'bab77ccf06f0b1f982e11c60f344c3c2' WHERE `ezuser`.`contentobject_id` =14;
SITE.INI:
==
[UserSettings]
HashType=md5_user
@nimasdj
nimasdj / MimeTypes.php
Last active April 2, 2023 22:21
List of MimeTypes mapped to file extensions
<?php
// I made this array by joining all the following lists + .php extension which is missing in all of them.
// please contribute to this list to make it as accurate and complete as possible.
// https://gist.github.com/plasticbrain/3887245
// http://pastie.org/5668002
// http://pastebin.com/iuTy6K6d
// total: 1223 extensions as of 16 November 2015
$mime_types = array(
'3dm' => array('x-world/x-3dmf'),
'3dmf' => array('x-world/x-3dmf'),