Skip to content

Instantly share code, notes, and snippets.

View paduc's full-sized avatar

Pierre A. Duchateau paduc

  • Product Developer at Betagouv.fr
  • Under some cherry tree, France
View GitHub Profile
@paduc
paduc / Html in Express
Created September 1, 2011 15:59
How to serve a static html file with Express. Anyone have something better?
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
app.set("view options", {layout: false});
// make a custom html template
@paduc
paduc / gist:1190969
Created September 3, 2011 10:22
Use Mongoose in Node
// Database
var mongoose = require('mongoose');
// connect to the db, test is the default db name (type db in the mongo shell to see yours)
mongoose.connect('mongodb://localhost:27017/test');
var Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
ThingSchema = new Schema({
@paduc
paduc / paste-from-spreadsheet.js
Last active December 15, 2015 14:08
This demonstrates how to handle the paste of some portion of a spreadsheet (google spreadsheet, excel, ...). Listens for a paste event on a textarea and converts the pasted data into an matrix of cells.
var field = $('textarea.myTextarea');
var cells;
// listen to keydown on text field
field.on('keydown', function(e){
// detect if it's a copy-paste action
if(e.keyCode === 86){

Keybase proof

I hereby claim:

  • I am paduc on github.
  • I am paduc (https://keybase.io/paduc) on keybase.
  • I have a public key ASCODFEgfU4JAZflAM_hnLkDTULbUCwiLn2t_JhtMcf4uQo

To claim this, I am signing this object:

@paduc
paduc / future.ts
Last active March 28, 2020 23:53
Result and Future Monads in Typescript
//
// Prenons pour base le monad Result de paralogs (en un peu simplifié)
//
interface OkParams<T> {
isSuccess: true
value: T
}
interface FailParams<T> {
@paduc
paduc / immutableMerge.js
Last active December 3, 2020 22:39
Immutable merge for multiple objects (using lodash)
var _ = require('lodash');
function immutableMerge(){
if(arguments.length === 0) return {};
if(arguments.length === 1) return arguments[0];
if(arguments.length === 2) {
return _.merge(_.cloneDeep(arguments[0]), arguments[1]);
}
else{
return immutableMerge(_.first(arguments), immutableMerge(_.rest(arguments)));
@paduc
paduc / type-guard-composition.ts
Last active January 14, 2022 14:24 — forked from safareli/type-guard-composition.ts
Composing TypeScript type guards
/**
* Type representing a guard function accepting Input and some other arguments
* while refining type of input as `Output`
*/
export type TypeGuard<Input, Output extends Input> = (value: Input) => value is Output
/**
* Combines multiple TypeGuards using `&&` operator
*/
export function and<I, O extends I, O2 extends O>(

Pour produire ce geojson, je suis d'abord parti du geojson des départements français simplifiés de france-geojson.

J'ai ensuite remplacé les départements de l'île de France par ceux du gist de @maximepvrt.

Enfin, pour les DOM, j'ai eu beaucoup de mal à effectuer une translation sur la carte sans créer de "déformation" (une déformation liée à la projection mercator, qui fait que si nous changeons de latitude, les formes paraissent allongées ou écrasées, par rapport à la forme dont nous avons l'habitude). Je suis parti d'une carte de la France en format SVG et j'ai utilisé svg-to-json pour placer les contours des DOM au bon endroit et produire un geojson avec des formes aux dimensions et au positionnement désiré (NB: le positionnement de la web app ne fonctionnait pas, alors j'ai du rentrer le