Skip to content

Instantly share code, notes, and snippets.

@pirhoo
pirhoo / gist:3313277
Created August 10, 2012 10:36
A snippet to remove URL's end slashes on Express Framework, especially for Regex routes
// Put this code where you define your routes on Express Web Framework
// Removes URL's end slashes
app.get(/^(\/(.+))\/$/, function(req, res){
res.redirect(req.params[0]);
});
@pirhoo
pirhoo / jquery.loading.css
Created September 8, 2012 16:17
A jQuery function to add a relative overlay on the current element
.js-loading-overlay {
position:absolute;
top:0; bottom:0;
left:0; right:0;
z-index:199;
background:#fff;
opacity:0.5;
@pirhoo
pirhoo / getFusionTable.js
Created October 13, 2012 12:34
Module to get a Google Fusion Table using its key
/**
* Google API client
* @type {Object}
*/
var googleapis = require('googleapis');
/**
* API Client
* @type {Boolean}
*/
@pirhoo
pirhoo / console-unfold.js
Created January 11, 2013 12:10
Unfolds objects completely with log, info and error methods of console.
(function(c){
// Do not extend the console twice
if(c.__elg__){return;}
var util = require('util');
// Maps this three console's methods
['log', 'info', 'error'].forEach(function(f){
var _= c[f];
c[f] = function(){
var args = arguments;
@pirhoo
pirhoo / owl2django.py
Last active December 19, 2015 18:48 — forked from n-kb/owl2django.py
from lxml import etree
# This string will contain the models.py file
modelsContents = "from neo4django.db import models\n\n"
# Enter the name of the OWL file to parse
# The relationships in the file should always start with has...
owlFile = "ontology.owl"
# Gives the ontology URI. Only needed for documentation purposes
@pirhoo
pirhoo / heroku-clean-virtualenv.md
Created August 27, 2013 10:01
Clean a virtualenv on Heroku (to force reinstall every packages). In french :
# Thanks to http://stackoverflow.com/questions/12506329/how-to-dynamically-change-header-based-on-angularjs-partial-view
# ──────────────────────────────────────────────────────────────────────────────
# Service
# ──────────────────────────────────────────────────────────────────────────────
angular.module('myApp').factory "Page", ->
title = "..."
#
#* To Title Case 2.0.1 – http://individed.com/code/to-title-case/
#* Copyright © 2008–2012 David Gouch. Licensed under the MIT License.
@pirhoo
pirhoo / activate.sh
Created October 9, 2013 14:14
Relative path for relocatable Virtualenv
#!/bin/sh
#...
VIRTUAL_ENV=`readlink -f ${BASH_SOURCE[0]:-$0}`;
# dirname gives us the containing dir (env/bin) path
VIRTUAL_ENV=`dirname "${VIRTUAL_ENV}"`;
# we do it once again to get the upper dir
VIRTUAL_ENV=`dirname "${VIRTUAL_ENV}"`;
export VIRTUAL_ENV;
@pirhoo
pirhoo / reindex.py
Created October 23, 2013 16:50
This Django command helps us to reindex a model (especialy with Neo4j).
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand, CommandError
from django.db.models.loading import get_model
class Command(BaseCommand):
help = "Reindex a given model."
args = 'app.Model'
def handle(self, *args, **options):
if not args:
@pirhoo
pirhoo / fabfule.py
Created November 4, 2013 11:06
Detective.io fabfile
#!/usr/bin/env python
# Encoding: utf-8
from fabric.api import local
PROD_APP = 'detective-io'
PROD_REMOTE = 'prod'
STAGING_APP = 'detective-staging'
STAGING_REMOTE = 'staging'
def prod(hard=False, full=False, branch='master'):