Skip to content

Instantly share code, notes, and snippets.

@rvause
rvause / server.py
Created October 26, 2016 19:57
Simple Flask app server that takes a JSON payload and prints formatted output.
import json
import sys
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['POST'])
@rvause
rvause / upc_check_digit.py
Last active December 1, 2016 13:28
Calculate UPC check digit or alternatively check a full UPC code
def handle_checkdigit(upc, append=False):
if len(upc) not in [11, 12]:
raise ValueError('Given UPC must be 11 or 12 digits')
bool_mode = len(upc) == 12
if bool_mode:
check_digit = upc[11]
upc = [int(i) for i in upc[:11]]
odd = []
@rvause
rvause / css.sh
Created February 4, 2017 17:28
Simple alternative to using gulp/grunt to build CSS using Less
#!/usr/bin/env bash
function css_build {
echo "Starting build..."
lessc --verbose ./less/main.less ../assets/css/app.css
echo "Completed at `date +%H:%I:%S`"
}
function css_watch {
echo "Building CSS on changes (CTRL+C to stop)"
from IPython import get_ipython
from IPython.terminal.prompts import Prompts, Token
c = get_config()
class SimplePrompt(Prompts):
def in_prompt_tokens(self, cli=None):
return [(Token.Prompt, '[{}] >>> '.format(self.shell.execution_count))]
@rvause
rvause / clean_pattern
Created June 8, 2018 11:50
Remove files matching a given pattern
#!/usr/bin/env bash
find . -name "$1"
read -p "Do you wish to remove these files? (y/N) " yn
case ${yn:0:1} in
[Yy]* ) find . -name "$1" -delete;;
* ) exit;;
esac
echo "Files have been removed"
@rvause
rvause / Pipfile
Last active September 7, 2018 16:52
Toolbox-Python
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
django = "*"
celery = "*"
coverage = "*"
django-rest-framework = "*"
@rvause
rvause / migration_manifest.py
Last active June 13, 2019 18:21 — forked from alvinchow86/migration_manifest.py
django-tips-blog-migration-manifest
def handle(self, *app_labels, **options):
# Generate a migrations manifest with latest migration on each app
super(Command, self).handle(*app_labels, **options)
loader = MigrationLoader(None, ignore_no_migrations=True)
with open("latest_migrations.manifest", 'w') as f:
f.write("\n".join(sorted(f"{a}: {m}" for a, m in loader.graph.leaf_nodes())))
# models.py
from .tasks import send_event
class Event(models.Model):
is_async = models.BooleanField(default=False)
# ...
def _send(self):
# do sending stuff
import hashlib
import io
import json
import os
from django.core.files.storage import default_storage
import googlemaps
@rvause
rvause / config.fish
Last active October 8, 2020 16:41
Simple fish prompt
set __fish_git_prompt_showdirtystate 'yes'
set __fish_git_prompt_showstashstate 'yes'
set __fish_git_prompt_showuntrackedfiles 'yes'
set __fish_git_prompt_showupstream 'yes'
set __fish_git_prompt_color_branch yellow
set __fish_git_prompt_color_upstream_ahead green
set __fish_git_prompt_color_upstream_behind red
set __fish_git_prompt_color_prefix white
set __fish_git_prompt_color_suffix white