Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael J. Roberts michealjroberts

  • University College London
  • United Kingdom
View GitHub Profile
View Filepond.vue
<template>
<div>
<FilePond
v-bind:max-files="4"
v-bind:allow-multiple="true"
v-bind:accepted-file-types="allowedFiletypes"
v-bind:server="server.process"
v-bind:files="files"
v-on:init="handleFilePondInit"
@michealjroberts
michealjroberts / dbinfo.py
Last active Feb 17, 2020
Django 3.0 DB Info Management Command
View dbinfo.py
from django.db import connection
from django.core.management.base import BaseCommand
from django.conf import settings
class Command(BaseCommand):
help = 'Displays The Currently Connected DB Settings'
def handle(self, *args, **kwargs):
@michealjroberts
michealjroberts / fields.py
Created Mar 26, 2020
Base64EncodedImage field serializer including to_representation() method
View fields.py
import six
import uuid
import base64
from django.conf import settings
from django.core.files import File
from django.core.files.base import ContentFile
from rest_framework import serializers
View remove-objects-from-array-by-object-property.js
// Source: http://stackoverflow.com/questions/16491758/remove-objects-from-array-by-object-property
var arr = [
{
id: 1,
property: "Property",
},
{
id:2,
property: "Property",
@michealjroberts
michealjroberts / main.js
Created May 4, 2020
Disbaling Vue.js devtools in Production
View main.js
const PRODUCTION = process.env.NODE_ENV === "production";
if (PRODUCTION) {
Vue.config.devtools = false
Vue.config.debug = false
Vue.config.silent = true
}
View Django Dynamic Database
db = {}
db['ENGINE'] = 'django.db.backends.postgresql'
db['OPTIONS'] = {'autocommit': True}
db['NAME'] = my_model_db['database']
db['PASSWORD'] = my_model_db['password']
db['USER'] = my_model_db['user']
db['HOST'] = my_model_db['host']
logger.info("Connecting to database {db} on {host}".format(db=source_db['NAME'], host=source_db['HOST']))
View serialize_dataset_to_doi.py
def serialize_dataset_to_doi(dataset: DatasetStorePointer) -> Dict[str, Any]:
return {
"data": {
"type": "dois",
"attributes": {
"doi": dataset.doi,
"prefix": settings.DATACITE['DOI_PREFIX'],
"suffix": dataset.doi_suffix,
"event": "publish",
"creators": dataset.creators if dataset.creators else [],
View datacite_doi_payload_request.json
{"data": {"type": "dois", "attributes": {"doi": "10.80519/asencis.4302-4ae4", "prefix": "10.80519", "suffix": "asencis.4302-4ae4", "event": "publish", "creators": [{"name": "Roberts, Michael", "nameType": "Personal", "givenName": "Michael", "familyName": "Roberts", "nameIdentifiers": [{"nameIdentifier": "https://orcid.org/0000-0001-6203-1986", "nameIdentifierScheme": "ORCID"}]}], "titles": [{"title": "HadCRUT4 Land & Ocean Temperature Measurements"}], "publisher": "asencis", "container": {}, "publicationYear": 2020, "subjects": [], "contributors": [], "types": {"resourceTypeGeneral": "Dataset"}, "relatedIdentifiers": [], "sizes": [21510268], "formats": ["application/x-netcdf"], "descriptions": [{"description": "HadCRUT4 is a global temperature dataset, providing gridded temperature anomalies across the world as well as averages for the hemispheres and the globe as a whole. CRUTEM4 and HadSST3 are the land and ocean components of this overall dataset, respectively.", "descriptionType": "Abstract"}, {"descripti