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 / 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)) {
@m-vdb
m-vdb / jquery.counter.js
Last active August 29, 2015 13:57
A simple counter for an element containing a number.
/*
Usage:
<span class="counter">10</span>
$(".counter").countTo({
step: 5, // step, integer
start: 10,
stop: 20
length: 500 // total duration in ms
});
@m-vdb
m-vdb / cdir.html
Created September 16, 2015 22:03
Generate a regex from a list of ip blocks
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</head>
<body>
<script type="text/javascript" src="http://underscorejs.org/underscore.js"></script>
<script>
window.ip_blocks = ['feel me'];
// cidr2regex 0.0.3
// 2009 xenowire
@m-vdb
m-vdb / ip_blocks.json
Last active September 16, 2015 22:18
Hosting provider IP blocks
[
// Amazon
"23.20.0.0/14",
"27.0.0.0/22",
"43.250.192.0/24",
"43.250.193.0/24",
"46.51.128.0/18",
"46.51.192.0/20",
"46.51.216.0/21",
"46.51.224.0/19",
@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 / script.sql
Created October 26, 2015 21:03
Rename job:apply:success events to job:apply:tentative
BEGIN;
LOCK events;
UPDATE events SET type = 'job:apply:tentative' WHERE type = 'job:apply:success' and date >= '2015-09-01';
END;