Skip to content

Instantly share code, notes, and snippets.

View lucadealfaro's full-sized avatar

Luca de Alfaro lucadealfaro

View GitHub Profile
from google.appengine.ext import blobstore
from google.appengine.ext import ndb
# Model for data.
class StoredFiles(ndb.Model):
file_id = ndb.StringProperty()
blob_key = ndb.BlobKeyProperty()
def get_upload_url():
"""Generates and returns an upload URL."""
def upload():
f = request.vars.file.file # This is the file.
# See here for docs: https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/functions
gcs_file = cloudstorate.open("mybucket/myfilename", 'w', content_type="image/jpeg")
gcs_file.write(f.read())
gcs_file.close()
f.close()
return "ok"
@lucadealfaro
lucadealfaro / default.py
Last active May 8, 2019 15:05
A shopping cart implementation using vue.js, stripe, and web2py
# -*- coding: utf-8 -*-
# this file is released under public domain and you can use without limitations
# -------------------------------------------------------------------------
# Sample shopping cart implementation.
# -------------------------------------------------------------------------
import traceback
def index():
import os
import requests
import time
import yaml
api_info = yaml.load(open('api_info.yaml'))
# Files to upload to a comparison.
FILE_LIST = map(lambda x: os.path.join('test_files', x),
['p1.py', 'p2.py', 'p3.py', 'p4.py', 's1.py', 's2.py', 't1.py', 't4.py'])
@lucadealfaro
lucadealfaro / rename_by_date.py
Created November 13, 2019 17:16
Renames filenames according to the date they have been taken. A file will receive a name such as 2019-07-23_13-43-27_R0000666.jpg, where R0000666.jpg is the filename before renaming. Collisions are avoided, and files which already begin by "20" are not renamed.
#!/usr/bin/python
import argparse
import os
import shutil
import subprocess
exifcmd = "/usr/local/bin/exiftool"
def main(args):
import os
import zipfile
import shutil
def zip_all_in_folder(folder_path, base_path, output_zip):
# Create a ZIP file
with zipfile.ZipFile(output_zip, 'w', zipfile.ZIP_DEFLATED) as zipf:
# Walk through the directory
for root, dirs, files in os.walk(folder_path):
for file in files:
@lucadealfaro
lucadealfaro / connectivity-us-conform.ipynb
Created August 9, 2024 20:36
Connectivity-US-Conform.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lucadealfaro
lucadealfaro / ls.py
Last active October 11, 2024 22:06
Python script for recursively listing directory sizes in Google Drive
# Copyright Luca de Alfaro, 2024.
# BSD License.
"""
Usage:
python ls.py <dir_id> [-d <depth>] [-a]
-d: maximum depth at which to inspect directories. Default is 1.
-a: list all directories, not just the top one.