Skip to content

Instantly share code, notes, and snippets.

View douglasmiranda's full-sized avatar
👽

Douglas Miranda douglasmiranda

👽
  • Earth, Brazil
View GitHub Profile
@douglasmiranda
douglasmiranda / friends_recommender.py
Created November 7, 2012 03:42 — forked from marcelcaraciolo/friends_recommender.py
Twitter Friends Recommender
#-*-coding: utf-8 -*-
'''
This module represents the recommender system for recommending
new friends based on 'mutual friends'.
'''
__author__ = 'Marcel Caraciolo <[email protected]>'
@douglasmiranda
douglasmiranda / gist:3992171
Created November 1, 2012 06:23
Compress/Extract Files with 'tar' command - Terminal
# Compress Files
tar -zcvf foo.tar.gz /home/douglas/foo
# Extract files
tar -zxvf foo.tar.gz
String.prototype.title_case = function () {
return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
};
r = '';
$('#IdModelo option').each(function(){
r += 'u\''+$(this).text().title_case()+'\', ';
});
console.log(r);
@douglasmiranda
douglasmiranda / gist:3595499
Created September 2, 2012 07:05
Upgrading Virtualbox on Ubuntu 12
~$ cd /opt/VirtualBox
~$ ls -al
~$ sudo chmod +x uninstall.sh
~$ sudo sh uninstall.sh
# then with 'cd' command move to the directory where is the .deb file, and execute it, example:
~$ cd ~/Downloads
~$ sudo dpkg -i virtualbox-4.1_4.1.20-80170~Ubuntu~precise_amd64.deb
@douglasmiranda
douglasmiranda / gist:3254332
Created August 4, 2012 04:05
How to Find and Replace Text in MySQL Database using SQL
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, "find this string", "replace found string with this string");
@douglasmiranda
douglasmiranda / gist:3193883
Created July 28, 2012 16:16
Creating a semantic breadcrumb using HTML5 microdata
<!-- http://coderwall.com/p/p0nvjw?i=5&p=1&q= -->
<ol class="breadcrumb">
<li itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="http://www.example.com/" itemprop="url">
<span itemprop="title">Example.com</span>
</a>
</li>
<li itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="http://www.example.com/news" itemprop="url">
<span itemprop="title">News</span>
@douglasmiranda
douglasmiranda / gist:3189843
Created July 27, 2012 19:02
Python UnicodeEncodeError: 'ascii' codec can't encode character
# https://groups.google.com/forum/?fromgroups#!topic/django-brasil/TZBXSowifn8
from django.utils.encoding import smart_str, smart_unicode
a = u'\xa1'
print smart_str(a)
@douglasmiranda
douglasmiranda / gist:3165425
Created July 23, 2012 18:58
Django: construct search with prefixes - code from djang.contrib.admin.views.main
# Apply keyword searches.
def construct_search(field_name):
if field_name.startswith('^'):
return "%s__istartswith" % field_name[1:]
elif field_name.startswith('='):
return "%s__iexact" % field_name[1:]
elif field_name.startswith('@'):
return "%s__search" % field_name[1:]
else:
return "%s__icontains" % field_name
@douglasmiranda
douglasmiranda / forms.py
Created July 17, 2012 17:46
Implementando form de filtro numa ListView (Resposta para um tópico na Django Brasil)
# https://groups.google.com/forum/?fromgroups#!topic/django-brasil/d6gV1V9qrgU
from django.forms import ModelForm
from minha_app.models import MeuModel
class MeuForm(ModelForm):
class Meta:
model = MeuModel
@douglasmiranda
douglasmiranda / .htaccess
Created June 18, 2012 17:45
Apache: When we make a Ajax request and get something like: "Origin http://ANY_DOMAIN_HERE is not allowed by Access-Control-Allow-Origin..."
SetEnvIf Origin "^http(s)?://(.+\.)?(http://ANY_DOMAIN_HERE\.com)$" origin_is=$0
Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is