Skip to content

Instantly share code, notes, and snippets.

View bogtan's full-sized avatar

Bogdan Tănase bogtan

View GitHub Profile
@bogtan
bogtan / README.md
Created October 24, 2019 08:05 — forked from notwaldorf/README.md
ServiceWorker code to cache Tensorflow model shards.

ServiceWorker code to cache TensorFlow model shards.

One of the problems I have when testing giant TensorFlow models in TensorFlow.js is that they're huge (like 500 MB) and they take forever to download, every time I refresh the page. This is how I setup my ServiceWorker code so that at least in testing I only have to download the model once, and then it's saved in the cache for the next time.

@bogtan
bogtan / gist:a921813d44ae13311cb920f5b8d2835d
Created July 6, 2018 11:47 — forked from dhbradshaw/gist:e2bdeb502b0d0d2acced
Rename field using migrations in django 1.7
To change a field name in django 1.7+
1. Edit the field name in the model (but remember the old field name: you need it for step 3!)
2. Create an empty migration
$ python manage.py makemigrations --empty myApp
3. Edit the empty migration (it's in the migrations folder in your app folder, and will be the most recent migration) by adding
migrations.RenameField('MyModel', 'old_field_name', 'new_field_name'),
to the operations list.
@bogtan
bogtan / post-checkout
Created April 23, 2018 11:26 — forked from linssen/post-checkout
A post checkout hook to automatically remove *.pyc files.
#! /bin/sh
green='\033[0;32m'
nc='\033[0m'
# Start from the repository root.
cd ./$(git rev-parse --show-cdup)
# Delete .pyc files and empty directories.
echo "${green}Deleting PYC files...${nc}"
find . -name "*.pyc" -delete
<html>
<head>
<style>
.item {width:300px; display: inline-block; }
.item .itemtitle {font-weight:bold; font-size:2em;}
.hidden {display:none;}
</style>
</head>
<body>
<h1>Amalgam Comics Characters</h1>
@bogtan
bogtan / settings.py
Created March 17, 2016 12:56 — forked from lucianmarin/settings.py
/?debug DRF endpoints
# pip install django-debug-toolbar==1.4.0
# /api/endpoint/?format=json&debug
from django.http import HttpResponse
import json
INSTALLED_APPS += ('debug_toolbar',)
MIDDLEWARE_CLASSES += (
'debug_toolbar.middleware.DebugToolbarMiddleware',
@bogtan
bogtan / stopvm
Created January 7, 2015 08:28
Shell command to stop virtual machine started with VMware Fusion without GUI
'/Applications/VMware Fusion.app/Contents/Library/vmrun' stop '</path/to/virtual/machine>/<virtual_machine_name>.vmwarevm'
@bogtan
bogtan / startvm
Created January 7, 2015 08:23
Shell command to start virtual machine using VMware Fusion without GUI
'/Applications/VMware Fusion.app/Contents/Library/vmrun' start '</path/to/virtual/machine/><virtual_machine_name>.vmwarevm' nogui

Rationale

This setup aims to create a clean development environment, by keeping development tools and libraries in a virtual machine, separate from the host computer. Separation has several advantages: you can back up the virtual machine, move it to a different host, keep multiple environments around (e.g. for wokring on projects with wildly different dependencies, or upgrading the development toolchain without risking downtime), and base the development environment on a different OS (hello Linux!). Last but not least, it keeps the host machine clean.

The downside is that you're running code inside a VM. You need to log in (we'll use SSH), make sure the code is available and in sync (we'll set up NFS). There's also some I/O overhead, and you need to decide on how much memory, CPU and disk space you allocate to the VM. You can change your mind later, but it's a bit of a hassle to resize virtual disks and partitions.

Set up the VM

We assume you're running MacOS and have VMware Fusion already installed

@bogtan
bogtan / myresource.py
Last active August 29, 2015 14:08
Django Tastypie exclude objects from object list
def get_object_list(self, request):
""" Usage: http://<example.com>/api/v1/<myresource>/?exclude_ids=1,2,3,4
"""
if request.GET.get('exclude_ids'):
bundle = super(<MyResource>, self).get_object_list(request).exclude(
id__in=request.GET.get('exclude_ids').split(',')
)
return bundle
@bogtan
bogtan / rsync_remote.sh
Created November 4, 2014 10:02
Backup remote folder on local machine
rsync -avlzp <hostname>:</remote/folder/path> </local/folder/path>