Skip to content

Instantly share code, notes, and snippets.

View senaps's full-sized avatar

maysam senaps senaps

View GitHub Profile
@senaps
senaps / README.md
Created October 29, 2019 09:13
flasgger useage maybe

install flask and flasgger using:

pip install flask
pip install flasgger

then run flask with:

export FLASK_APP=api
export FLASK_ENV=development

flask run

@senaps
senaps / shortcut.py
Created October 6, 2019 06:36
flask context
@contextmanager
def get_app_context(conf=None):
"""get an app context!
we will receive the name of the application and then try to build out the
applicaton and return it. the important thing with this function is that we
will return the application context not the actual application object.
this is usefull for modules and functions that need the application context
to be able to do what they would need to do.
CKEDITOR.editorConfig = function( config ) {
config.toolbarGroups = [
{ name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
{ name: 'forms', groups: [ 'forms' ] },
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
{ name: 'links', groups: [ 'links' ] },
{ name: 'styles', groups: [ 'styles' ] },
{ name: 'insert', groups: [ 'insert' ] },
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
from contextlib import contextmanager
from sqlalchemy import Column, ForeignKey, Integer, String, Boolean, DateTime, Text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, Session
Base = declarative_base()
@senaps
senaps / logging.py
Created July 24, 2018 18:55
logging boierplate this module should be included in the project and be used as the logger mechanism
import sys
import logging
# handlers = {
# 'stream': logging.StreamHandler(sys.stdout),
# 'errstream': logging.StreamHandler(sys.stderr),
# 'file': logging.FileHandler,
# 'null': logging.NullHandler,
# 'rotatefile': logging.handlers.RotatingFileHandler,
@senaps
senaps / app.py
Created July 4, 2018 20:30
custom flask code!
""" the problem is, we want to be able to change session life time of a flask app,
on the fly, without restarting the app. the reason for this is, that the app was
being used as a UI for a networking device, customers were able to use our app
instead of using a terminal to config the device. so, we thought it would be a
better UX thing to not restart the application, on session time change.
i was tasked to solve the problem, and this is how i approached it:
i checked the source code of flask to see how it works, and set the session life
time.

Keybase proof

I hereby claim:

  • I am senaps on github.
  • I am senaps (https://keybase.io/senaps) on keybase.
  • I have a public key ASDl_kfBASEjY2hafLfjFuIJu22r7RCIjnLBBVmSrjbwAQo

To claim this, I am signing this object:

@senaps
senaps / index.html
Created November 21, 2017 06:05 — forked from nfarring/index.html
Ubuntu Apache default index.html file
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
@senaps
senaps / .emacs
Last active January 28, 2018 16:15
my emacs template
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(cua-mode t nil (cua-base))
'(custom-enabled-themes (quote (deeper-blue))))
'(tool-bar-mode nil)
(custom-set-faces
;; custom-set-faces was added by Custom.