This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to display only interesting fields for a Django Rest Framework API | |
# /?fields=field1,field2,field3 | |
from rest_framework import serializers, pagination | |
class DynamicFieldsModelSerializer(serializers.ModelSerializer): | |
""" | |
A ModelSerializer that takes an additional `fields` argument that | |
controls which fields should be displayed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# coding: utf-8 | |
import sys | |
def plan_projectif(modulo): | |
"""Génération d'un plan projectif réel | |
Il est composé d'un plan affine (une matrice) et | |
des points à l'infini du plan réel. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
register = template.Library() | |
# custom tag "active_view" to return 'active' in the template when the view is active | |
# usage : {% active_view request name='view-name' %} | |
# usage : {% active_view request url='/view/abs/url' %} | |
# usage : {% active_view request re='^/view/ur.*' %} | |
@register.simple_tag(takes_context=True) | |
def active_view(context, name=None, url=None, re=None, cond=True): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SRC=$(git rev-parse --show-toplevel) | |
EXCLUDE="--exclude-dir 'node_modules' --exclude-dir '.git'" | |
#========================================================== | |
# Check if I forgot to remove 'only' keyword from tests. | |
# To make sure that before commit run all tests | |
only_command="grep -c -h -r $EXCLUDE -E \"(describe|it)\.only\" $SRC | awk -F ':' '{x +=\$0}; END {print x}'" | |
fonly_command="grep -c -h -r $EXCLUDE -E \"f(it|describe)\(\" $SRC | awk -F ':' '{x +=\$0}; END {print x}'" | |
only=`eval $only_command` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Requirements | |
# - NVIDIA Driver - NVIDIA-Linux-x86_64-375.39.run - http://www.nvidia.fr/Download/index.aspx | |
# - CUDA runfile (local) - cuda_8.0.61_375.26_linux.run - https://developer.nvidia.com/cuda-downloads | |
sudo apt update -y && sudo apt upgrade -y | |
sudo apt install build-essential linux-image-extra-`uname -r` -y | |
chmod +x NVIDIA-Linux-x86_64-375.39.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
help = """Retrieve all the stats from WakaTime API | |
Usage: | |
wakatime_stats.py <token> | |
Options: | |
-h --help Show this very help message | |
See https://wakatime.com/developers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Warn from unhandled promise rejection that can occurs without failing tests | |
// jest --setupFiles setup-tests.js | |
process.on('unhandledRejection', (error, promise) => { | |
console.error('Unhandled Rejection at:', promise, `\n${error.stack}`); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: build | |
TAG ?= | |
SERVER ?= staging-server | |
install: | |
npm install | |
start: | |
node --require reify server.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const winston = require('winston'); | |
const expressWinston = require('./express-winston'); | |
const app = express(); | |
const consoleFormatter = ({ level, meta: { req, res, responseTime, stack } }) => { | |
let msg = `${winston.config.colorize(level, level)} HTTP ${req.method} ${req.url}`; | |
if (res) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('isomorphic-fetch'); | |
const express = require('express'); | |
const { makeExecutableSchema } = require('graphql-tools'); | |
const graphqlHTTP = require('express-graphql'); | |
const books = [ | |
{ title: "Harry Potter and the Sorcerer's stone", author: "J.K. Rowling" }, | |
{ title: "Jurassic Park", author: "Michael Crichton" }, | |
]; |
OlderNewer