Skip to content

Instantly share code, notes, and snippets.

View fabiomontefuscolo's full-sized avatar

Fabio Montefuscolo fabiomontefuscolo

View GitHub Profile
@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 / 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: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()) {
@fabiomontefuscolo
fabiomontefuscolo / gist:1023250
Created June 13, 2011 17:28
Generate video thumbnail through mplayer.
<?php // help is welcome
function generate_video_thumb($video_path, $image_target_path, $offset=0) {
$video_path = addcslashes($video_path, " "); // para videos com espaços no nome do arquivo
if(file_exists($video_path)) {
$position = '';
if($offset > 0) {
$position = '-ss ' . $offset;
}
@fabiomontefuscolo
fabiomontefuscolo / gist:1023258
Created June 13, 2011 17:30
Get video duration with mplayer
<?php // help is welcome
function get_video_duration($video_path) {
$video_path = addcslashes($video_path, " "); // para videos com espaços no nome do arquivo
$command = "mplayer -vo null -ao null -frames 0 -nolirc -identify -cache 20480 {$video_path} 2>&-";
exec($command, $output, $retcode);
if($retcode === 0) {
foreach($output as $line) {
if(preg_match('/^ID_LENGTH=([0-9]+(\.[0-9]+)?)$/', $line, $duration)) {
return floatval($duration[1]);
@fabiomontefuscolo
fabiomontefuscolo / gist:1023280
Created June 13, 2011 17:42
Attach file in a Wordpress Post
<?php // help is welcome
function attach_file($current_path, $desired_name, $to_post_id, $uploaded=true) {
if(!file_exists($current_path)) {
return false;
}
$uploads = wp_upload_dir();
$file_name = preg_replace('/[^\w.]/', '-', remove_accents($desired_name));
$file_path = $uploads['path'] . '/' . $file_name;
@fabiomontefuscolo
fabiomontefuscolo / gist:1023314
Created June 13, 2011 18:01
Mandelbrot on <canvas/>
<html>
<head>
<title>Fractal</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="application/x-javascript">
window.onload = function() {
var canvas = document.getElementById('canvas');
var d = canvas.getContext('2d');
@fabiomontefuscolo
fabiomontefuscolo / gist:1083072
Created July 14, 2011 18:26
git pre-commit hook that check php files
#!/bin/bash
git status --porcelain|
while read f;
do
[[ $f =~ ^\s*M\s*(.+\.php)$ ]]
php="${BASH_REMATCH[1]}";
if [ `grep -v "^[ ]*$" <<< $php` ]
then
error=`php -l $php 2>&1`;
@fabiomontefuscolo
fabiomontefuscolo / gist:1095582
Created July 20, 2011 18:34
verifica se cnpj é válido
<?php
/** Return true if supplied cpf is valid or give an error message otherwise */
function is_a_valid_cnpj($cnpj) {
$error = __("O CNPJ fornecido é inválido.");
$cnpj = preg_replace('/[^0-9]/', '', $cnpj);
if(strlen($cnpj) != 14) {
return $error;
}
@fabiomontefuscolo
fabiomontefuscolo / gist:1095584
Created July 20, 2011 18:36
verifica se cpf é válido
<?php
/** Return true if supplied cpf is valid or give an error message otherwise */
function is_a_valid_cpf($cpf) {
$error = __("O CPF fornecido é inválido.");
$cpf = preg_replace('/[^0-9]/','',$cpf);
if(strlen($cpf) != 11 || preg_match('/^([0-9])\1+$/', $cpf)) {
return $error;
}