Skip to content

Instantly share code, notes, and snippets.

@ak64th
ak64th / app.py
Last active December 15, 2015 05:33
from flask import Flask
from flask_peewee.db import Database
app = Flask(__name__)
DATABASE = {
'name': 'group_int.db',
'engine': 'peewee.SqliteDatabase',
'threadlocals': True,
}
app.config['DATABASE'] = DATABASE
@ak64th
ak64th / photos.py
Created December 24, 2015 02:48
flask_photo_manager
# coding:utf-8
import os
import uuid
import errno
import flask
from werkzeug.exceptions import abort
from werkzeug.utils import secure_filename
from werkzeug.datastructures import FileStorage
@ak64th
ak64th / app.py
Created December 25, 2015 09:40
Hello world for flask assets and underscore templates
from flask import Flask, render_template
from flask_assets import Bundle, Environment
app = Flask('app')
app.config['JST_COMPILER'] = u'_.template'
app.config['JST_NAMESPACE'] = 'window.Templates'
app.config['JST_BARE'] = False
env = Environment()
# a benchmark script for gevent and redis-py
import gevent
from gevent import monkey
monkey.patch_all()
import timeit
import redis
import random
r = redis.StrictRedis(host='xxx', password='xxx')
r.flushall()
@ak64th
ak64th / use_jama_with_jython
Created February 5, 2016 04:24
Call Jama Matrix from jython.
$ ./bin/jython
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('Jama-1.0.3.jar')
>>> from Jama import Matrix
>>> array = [[1,2,3],[4,5,6],[7,8,9]]
>>> A = Matrix(array)
>>> b = Matrix.random(3,1)
@ak64th
ak64th / benchmark.py
Last active April 7, 2017 13:55
benchmark for gevent and sqlite3
import gevent
from gevent import monkey
monkey.patch_all()
import os
import timeit
import sqlalchemy
import sqlalchemy.event
import sqlalchemy.pool
from sqlalchemy import Table, Column, Integer, String, MetaData
@ak64th
ak64th / custom_rest_api.py
Created June 16, 2016 09:11
add custom url to a flask_peewee rest api
# coding=utf-8
from flask import request, Response
from peewee import *
from flask_peewee.rest import RestAPI
from models import *
class IntApi(RestAPI):
@property
def registry(self):
@ak64th
ak64th / with_coverage.py
Last active November 25, 2016 07:13
run tests and get coverage report
import coverage
class coverall(object):
def __enter__(self):
self.coverage = coverage.coverage()
self.coverage.erase()
self.coverage.start()
def __exit__(self, exc_type, exc_val, exc_tb):
@ak64th
ak64th / mock.js
Created June 8, 2017 10:42
Mock a jquery ajax request
const loadData = function loadData(){
let deferred = $.Deferred();
deferred.then((data) => console.log(data));
deferred.resolve(mockData);
return deferred;
};
@ak64th
ak64th / MySQL Replication Check
Created May 25, 2018 09:00 — forked from ssimpson89/MySQL Replication Check
Just a simple Mysql Replication Health Check script I wrote. You can put this in a cron.
#!/bin/bash
### VARIABLES ### \
EMAIL=""
SERVER=$(hostname)
MYSQL_CHECK=$(mysql -e "SHOW VARIABLES LIKE '%version%';" || echo 1)
LAST_ERRNO=$(/usr/bin/mysql -e "SHOW SLAVE STATUS\G" | grep "Last_Errno" | awk '{ print $2 }')
SECONDS_BEHIND_MASTER=$(/usr/bin/mysql -e "SHOW SLAVE STATUS\G"| grep "Seconds_Behind_Master" | awk '{ print $2 }')
IO_IS_RUNNING=$(/usr/bin/mysql -e "SHOW SLAVE STATUS\G" | grep "Slave_IO_Running" | awk '{ print $2 }')
SQL_IS_RUNNING=$(/usr/bin/mysql -e "SHOW SLAVE STATUS\G" | grep "Slave_SQL_Running" | awk '{ print $2 }')