Skip to content

Instantly share code, notes, and snippets.

View fabiomontefuscolo's full-sized avatar

Fabio Montefuscolo fabiomontefuscolo

View GitHub Profile
@fabiomontefuscolo
fabiomontefuscolo / fallback-to-less.html
Created May 7, 2014 14:25
In HTML5 page, I try to load a CSS generated by Less. When the CSS does not exist, I fallback to Less file.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Fallback to Less</title>
<script type="text/javascript">
function fallbackToLess(){
var script = document.createElement('script');
script.src = "js/libs/less-1.7.0.min.js";
@fabiomontefuscolo
fabiomontefuscolo / jquery-django-csrf.js
Created July 31, 2014 15:09
Configure jQuery to send 'X-CSRFToken' required by Django. With this piece of code loaded after jQuery, it's not necessary to config headers in every jQuery.post against Django.
(function($){
if(!$) {
return;
}
var match = document.cookie.match(/csrftoken=(\w+)/);
var token = match ? match[1] : '';
$.ajaxSetup({
headers: { 'X-CSRFToken': token }
@fabiomontefuscolo
fabiomontefuscolo / Code.gs
Created August 15, 2014 14:43
Export a Google Spreadsheet as JSON Webapp
/**
* I'm not author of this script. The author (I guess) can be found
* at http://pipetree.com/qmacro/blog/2013/10/sheetasjson-google-spreadsheet-data-as-json/
*/
function doGet(request) {
var output = ContentService.createTextOutput();
var data = {};
var id = request.parameters.id;
var sheet = request.parameters.sheet;
var ss = SpreadsheetApp.openById(id);
@fabiomontefuscolo
fabiomontefuscolo / Array.group.js
Last active August 29, 2015 14:06
Groups elements of array
// http://jsfiddle.net/montefuscolo/ogtzpt4t/
Object.defineProperty(
Array.prototype,
'group',
{
enumerable: false,
value: function (n) {
var initial = [
[]
@fabiomontefuscolo
fabiomontefuscolo / Default (Linux).sublime-keymap
Created September 26, 2014 20:14
My Sublime 3 conf files.
[
{ "keys": ["ctrl+k", "ctrl+m"], "command": "md5fy" },
{ "keys": ["ctrl+k", "ctrl+n"], "command": "numbering" }
]
@fabiomontefuscolo
fabiomontefuscolo / input-inspector.sh
Created August 7, 2015 21:25
Run command passing files throught pipe and redirections to see from where you should read
#!/bin/bash
script_id="$$";
files=`find /proc/$script_id/fd -not -type d`;
for file in $files;
do
echo $file && ls -l $file
if [ -a "$file" ]; then echo $file' -a - True if file exists.'; fi
@fabiomontefuscolo
fabiomontefuscolo / gist:815632
Created February 8, 2011 00:58
Copy cut and paste in Vim
; Maps para copiar e colar no Vim
:vmap <C-c> "+y ; Ctrl+C, funciona em Visual Mode
:vmap <C-x> "+x ; Ctrl+X, funciona em Visual Mode
:imap <C-v> <ESC>"+gpA ; Ctrl+V, funciona em Insert Mode
@fabiomontefuscolo
fabiomontefuscolo / gist:815415
Created February 7, 2011 22:43
Jena no Maven
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.projeto</groupId>
<artifactId>nomedoartefato</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>nome do projeto</name>
<url>http://maven.apache.org</url>
<build>
@fabiomontefuscolo
fabiomontefuscolo / wordpress.conf
Last active September 25, 2015 03:28
Simple nginx conf to Wordpress
server {
listen 80;
server_name example.com;
root /srv/www/wordpress-ms;
gzip on;
gzip_disable "msie6";
gzip_min_length 1100;
gzip_buffers 16 8k;
@fabiomontefuscolo
fabiomontefuscolo / gist:857968
Created March 7, 2011 02:07
Method to remove a directory and all subdirectories
public void removeDirectory(String path) throws Exception {
Stack<File> dirs = new Stack<File>();
File root = new File(path);
File currentDir = root;
dirs.add(root);
while(!dirs.empty()) {
currentDir = dirs.lastElement();
File files[] = currentDir.listFiles();
for(int i=0; i<files.length; i++) {
if(files[i].isDirectory()) {