Skip to content

Instantly share code, notes, and snippets.

View arthurfurlan's full-sized avatar

Arthur Furlan arthurfurlan

View GitHub Profile
@arthurfurlan
arthurfurlan / convert-encoding.sh
Created December 10, 2010 12:50
Convert files from some encoding to another using the "iconv". edit
#!/bin/sh
# written by Arthur Furlan <[email protected]>
# check the script usage
if [ $# -lt 1 ]; then
echo "Usage: $0 PATH [FROM-ENCODING] [TO-ENCODING]"
exit 1
elif [ ! -d $1 ]; then
echo "Error: directory $1 not found."
exit 2
@arthurfurlan
arthurfurlan / SequenceMapper tests
Created January 21, 2011 14:17
SequenceMapper is an algorithm optimized for the generation of ShortURLs codes.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# BaseConverter used in django-shorturls: https://github.com/jacobian/django-shorturls
# https://github.com/jacobian/django-shorturls/blob/master/src/shorturls/baseconv.py
from shorturls.baseconv import BaseConverter
# SequenceMapper used in django-shortim: https://github.com/valvim/django-shortim
# https://github.com/valvim/django-shortim/blob/master/src/shortim/models.py
from shortim.sequencemapper import SequenceMapper, SHORTIM_SHORTURL_CHARS
@arthurfurlan
arthurfurlan / vamu.php
Created February 23, 2011 19:48
Example of vamu's API usage for PHP
<?php
define('VAMU_API_CREATE', 'http://va.mu/api/create?url=%s');
define('VAMU_API_PREVIEW', 'http://va.mu/api/preview?url=%s');
function _consume_webservice($url) {
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
@arthurfurlan
arthurfurlan / gist:947731
Created April 29, 2011 02:24
Example of the valvim's fabfile
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# written by Arthur Furlan <[email protected]>
from __future__ import with_statement
from fabric.api import *
import socket
import time
@arthurfurlan
arthurfurlan / encrypted-backup.sh
Created April 29, 2011 20:44
Encrypted backup
#!/bin/bash
# written by Arthur Furlan <[email protected]>
# check program usage
if [ $# -lt 1 ]; then
echo "Usage: $0 DEVICE"
exit 1
elif ! [ -e "$1" ]; then
echo "Error: device '$1' not found."
exit 2
@arthurfurlan
arthurfurlan / gist:1051990
Created June 28, 2011 19:36 — forked from lerrua/gist:1051984
vamu_django.py
site = Site.objects.get_current()
absolute_url = 'http://%s%s' % (site.domain,
instance.get_absolute_url())
instance.short_url = vamu_url_shortening(absolute_url)
def vamu_url_shortening(url):
url = urllib2.quote(url, safe='')
vamu_api = 'http://va.mu/api/create/?url=%s' % (url)
response = urllib2.urlopen(vamu_api).read()
@arthurfurlan
arthurfurlan / example.py
Created July 20, 2011 19:32 — forked from lerrua/example.py
example.py
# urls.py
urlpatterns = patterns('',
url('^galerias/$',
active_generic_view,
{'view': object_list, 'model': MediaCenter, 'paginate_by': 20},
name='webmedia_mediacenter_list'),
url(r'^(?P<category_slug>[-\w]+)/galerias/$', 'mediacenter_category_list',
name='webmedia_mediacenters_category_list'),
# -*- coding: utf-8 -*-
import time, datetime
def print_time(when=time.time()):
print when
def print_date(when=datetime.datetime.now()):
print when
## voce estava usando o "verbose_name" da forma errada, vou colocar
## aqui da forma eu acredito que você deve estar querendo usar e
## qualquer coisa você me corrige :)
class News(models.Model):
## ... bla bla bla, campos desse model que não interessa
class NewsPhotos(models.Model):
## ... bla bla bla, campos desse model que não interessa
@arthurfurlan
arthurfurlan / hello.php
Last active December 18, 2015 11:09
why do I like python!?
#!/usr/bin/env php
<?php
class Hello {
public function say($what) {
echo "Hello {$what}!\n";
}
}
$hello = new Hello();