Skip to content

Instantly share code, notes, and snippets.

View m-vdb's full-sized avatar

Maxime Vdb m-vdb

  • Rasa
  • Berlin
View GitHub Profile
@m-vdb
m-vdb / .screenrc
Created December 3, 2012 15:06
Screen configuration
#
# Example of a user's .screenrc file
#
# no annoying audible bell, please
#vbell on
vbell off
# detach on hangup
autodetach on
@m-vdb
m-vdb / inlinenestedmodel.js
Created December 5, 2012 11:11 — forked from alexstrat/inlinenestedmodel.js
Backbone-Forms InlineObject
var Form = Backbone.Form,
editors = Form.editors;
// we don't want our nested form to have a (nested) <form> tag
// (currently bbf includes form tags: https://github.com/powmedia/backbone-forms/issues/8)
// aside from being strange html to have nested form tags, it causes submission-upon-enter
Form.setTemplates({
nestedForm: '<div class="bbf-nested-form">{{fieldsets}}</div>'
});
@m-vdb
m-vdb / backbone-forms-validators.js
Created December 11, 2012 12:58
Backbone forms validator
(function(){
var validators = Backbone.Form.validators;
//a validator verifying if an element is not in a given list
validators.errMessages.notInList = 'Must not be in list {{list}}';
validators.notInList = function(options) {
if (!options.list) throw new Error('Missing required "list" options for "notInList" validator');
options = _.extend({
type: 'notInList',
@m-vdb
m-vdb / backbone-forms-ListKeyValue-Editors.js
Created December 13, 2012 14:07
Backbone.Forms editors for List accepting objects, and rendering them as key-value pairs
/*
Currently, the Object ItemType is not supported.
*/
var Form = Backbone.Form,
editors = Form.editors;
Form.setTemplates({
listKeyValueItem: '\
<li>\
@m-vdb
m-vdb / backbone-forms-ListKeyValue.css
Created December 14, 2012 08:08
backbone-forms-ListKeyValue.css
.bbf-field .bbf-keyvalue-editor input {
width: 45%;
}
@m-vdb
m-vdb / paramForm.js
Created June 4, 2013 15:37
Param form (Backbone.Form)
var ParamForm = window.Interface.BaseForm.extend({
initialize: function(options){
options.schema = {
client_name: {type: 'Text', title: 'Client Name', validators: ['required'], editorClass: 'client_name'},
name: {type: 'Text', title: 'Short Name', editorClass: 'name', fieldClass: 'hidden'},
urls: {type: 'List', title: 'Source urls', validators: ['url']},
exporters: {type: 'List', title: 'Facebook Pages', itemType: 'InlineObject', validators: [this.validateListExporter],
subSchema: {
name: {type: 'Text', title: 'Name', validators: ['required']},
exporter: {type: 'Exporter', title: 'Type',
@m-vdb
m-vdb / mongo_dbref_migration.js
Last active April 8, 2022 19:41
A quick example to migrate DBRef's to ObjectId's directly in MongoDB shell.
/*
A quick example to migrate DBRef's to ObjectId's directly in MongoDB shell.
Suppose we have 2 collections:
- db.authors
- db.books, with books like {title: "My book", writer: DBRef("authors", ObjectId("anyID"))}
*/
{"version":3,"file":"job_pipe/static/js/interface_app/build.min.js","sources":["job_pipe/static/js/interface_app/build.js"],"names":["e","t","n","r","s","o","u","a","require","i","Error","f","exports","call","length",1,"Pipe","ExporterCollection","PipeCollection","ScrapedItemCollection","spiders","Router","window","Interface","eventAggregator","_","extend","Backbone","Events","initialize","this","on","domChangeTitle","loadedDashboard","toastr","options","positionClass","exporterCollection","pipeCollection","scrapedItemCollection","spiderCollection","SpiderCollection","processorCollection","ProcessorCollection","validatorCollection","ValidatorCollection","reset","exportersJSON","pipeList","sortPipeList","fetch","router","history","start","pushState","bindAll","setDefaultsForPipe","default_exporter","where","name","prototype","defaults","exporters","exporter","title","document","info","message","ms","timeOut","success","dashboard","fadeOut","error","redirect","onHidden","back","$","evt","href","attr","protocol"
@m-vdb
m-vdb / french_dep_coords.py
Created January 29, 2014 10:34
Retrieve the french department coordinates using wikipedia and google geolocation API.
from collections import OrderedDict
from itertools import tee
import time
from xml.etree import ElementTree as ET
from pygeocoder import Geocoder
import requests
wiki_url = u"http://fr.wikipedia.org/wiki/Liste_des_pr%C3%A9fectures_de_France"
@m-vdb
m-vdb / underscore_mixins.js
Last active August 29, 2015 13:57
Undescore mixins : whereDeep
// inspired from _.matches
function deepMatch (attrs) {
return function (obj) {
var attrVal, objVal;
if (obj === attrs) return true; //avoid comparing an object to itself.
for (var key in attrs) {
attrVal = attrs[key];
objVal = obj[key];
if (_.isObject(attrVal) && _.isObject(objVal)) {
if (!deepMatch(attrVal)(objVal)) {