Skip to content

Instantly share code, notes, and snippets.

View pdonorio's full-sized avatar
🔍
searching...

Paolo D. pdonorio

🔍
searching...
View GitHub Profile
@pdonorio
pdonorio / app.js
Last active August 29, 2015 14:16
Select via xeditable in Angular (workaround)
var myApp = angular.module('myapp')
.controller('SubmissionAdminController', function ($scope) {
$scope.types = [
{value: 0, text: 'string'},
{value: 1, text: 'number'},
{value: 2, text: 'range'},
{value: 3, text: 'date'},
{value: 4, text: 'email'},
];
@pdonorio
pdonorio / csv_check.py
Created March 25, 2015 18:52
Verify CSV header elements against each row of the same file
filecsv = "input.csv"
with open(filecsv, mode='r') as csvfile:
reader = csv.reader(csvfile)
line_count = 0
head = []
data = []
for rows in reader:
if line_count < 1:
head = rows
@pdonorio
pdonorio / goodcookie.js
Created May 15, 2015 08:26
A secured angular cookie
var setCookie = function(token, username)
{
// If
// If logout, token is null or undefined
if (!token || !username) {
token = FAILED_TOKEN;
username = FAILED_USER;
}
// One day expiration
var now = new Date(),
@pdonorio
pdonorio / README.md
Created May 15, 2015 12:00
A login pattern example

Login patter

Using angularjs + ui router

Logic

Three abstract states:

  1. Welcome (static home page)
  2. Unlogged (login, logout, register)
  3. Logged (application)
@pdonorio
pdonorio / dbdump.sh
Last active August 29, 2015 14:21
Launch a docker mysql container to mount an existing database folder and dump it into a sql.gz file
###############################
# You can change these
dir='/path/to/localhost/dbfolder'
mysql_version='5.5'
# No need to change here
mypwd='test'
dname='dumpmysqldb'
hdir=`basename $dir`
mdir="/var/lib/mysql"
@pdonorio
pdonorio / README.md
Created September 19, 2015 14:14
Nginx for serving your current directory static HTML locally in one command

How to provide a quick web server to test your static content

Warning: this is going to work for a fish shell on a Mac host.

Add the function to your fish shell, e.g.

source serve_static_web_docker.fish

Then go to your path (warning, make sure there is an index.html file)

@pdonorio
pdonorio / README.md
Last active November 6, 2015 09:22
Github repository automatic creation for a python project

A way to easily start the next python project with one command line command

Based on the following python libraries:

  • argparse for command line options
  • pyscaffold for first packaging setup
  • mkdocs instead of sphinx for documentation in markdown
  • requests for connecting to github api
  • plumbum to integrate command line executables inside python
@pdonorio
pdonorio / Additionals.md
Last active July 4, 2016 09:16
Asynchronous tasks

We may check celery tasks queued at any time. Let's see how.

Save the id

When you launch the task you get the AsyncResult back. To save the id you may:

res = my_async_task.delay(i)
@pdonorio
pdonorio / Example.py
Last active September 27, 2016 15:22
Internally parse request parameters
from ..base import ExtendedApiResource
class MyTest(ExtendedApiResource):
@decorate.add_endpoint_parameter('test')
@decorate.apimethod
def get(self, id=None):
"""
This works for all methods: GET, POST, PUT, PATCH, DELETE
"""