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 / mb_substr.php
Created August 24, 2011 20:38
How to get substring from accented words (UTF-8)
<?php
/**
* How to get substring UTF-8 characters
*/
// If you try something like this
$utf_8_characters = 'Sábado';
echo substr($utf_8_characters, 0, 3);
// you get something like "Sá", but not "Sáb"
@douglasmiranda
douglasmiranda / get-latest-videos.js
Created September 21, 2011 15:05
Get latest videos from Youtube with Jquery (Gdata API)
function show_my_videos(data){
html = ['<ul id="youtube-videos">'];
$(data.feed.entry).each(function(entry){
url = this.link[0].href;
url_thumbnail = this.media$group.media$thumbnail[3].url;
description = this.media$group.media$description.$t;
html.push('<li><a href="'+url+'">');
html.push('<img src="'+url_thumbnail+'" alt="'+description+'">');
html.push('</a></li>');
});
@douglasmiranda
douglasmiranda / 1ntro.markdown
Last active January 13, 2020 03:28
Django + git + apache mod_wsgi na Kinghost

#Django + git + apache mod_wsgi na Kinghost

NOTE: Atualmente não é necessário tanto para fazer deploy de aplicações Django na Kinghost.

I hope you like it!

##Início

Talvez você não queira ficar digitando a senha toda vez que usar o ssh, então adicione sua chave pública ao seu host:

@douglasmiranda
douglasmiranda / MySQLdb_virtualenv.sh
Created September 23, 2011 19:47
Fix error when try to install MySQLdb on virtualenv //I'm using Ubuntu
sudo apt-get build-dep python-mysqldb
pip install mysql-python
@douglasmiranda
douglasmiranda / order_by_ignoring_0.sql
Created September 26, 2011 16:26
SQL ORDER BY ignoring fields filled with "0"
-- This problem happens when you try to order columns ASC
-- and you want to ignore the 0 values in the first results
SELECT `DATABASE_NAME`.*
FROM `TABLE_NAME`
ORDER BY
CASE WHEN `FIELD_FILL_WITH_0` in("", "0") THEN 1
ELSE 0 END, `FIELD_FILL_WITH_0_OR_ANY_OTHER_FIELD` ASC
@douglasmiranda
douglasmiranda / nth_child_odd_even.css
Created October 7, 2011 16:39
Aplicar css em elementos pares em ímpares.
/* Example */
/* Par */
ul li:nth-child(even){
background:#fff;
}
/* Ímpar */
ul li:nth-child(odd){
background:#000;
@douglasmiranda
douglasmiranda / fix_error_lxml.sh
Created October 7, 2011 22:08
Fix error when try to install/upgrade splinter on ubuntu.
# I don't know why, but everytime than i try to install or update splinter in my pc
# i get this error: src/lxml/etree_defs.h:9:31: fatal error: libxml/xmlversion.h
# anyway i try to discover why, for while this is a solution:
# install/upgrade libxml2-dev and libxslt-dev
sudo apt-get install libxml2-dev libxslt-dev
@douglasmiranda
douglasmiranda / .htaccess
Created November 30, 2011 15:28
Diretivas .htaccess para cache
# 1 ANO
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
# 1 SEMANA
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 2 DIAS
<FilesMatch "\.(xml|txt|css|js)$">
@douglasmiranda
douglasmiranda / gist:1913266
Last active September 5, 2019 09:29
MySQL - Export and Import free of troubles with Foreign Key Restriction From innoDB Tables
# Export and pack
mysqldump -uUSER -pPASSWORD database_name --compact --host=HOST_IP_ADDRESS | gzip > mysqlbackup.sql.gz
# Unpack
gunzip mysqlbackup.sql.gz
# Importing free of troubles with Foreign Key Restriction From innoDB Tables
mysql -uUSER -pPASSWORD
# MySQL terminal
mysql> CREATE DATABASE database_name CHARACTER SET utf8 COLLATE utf8_general_ci;
@douglasmiranda
douglasmiranda / gist:1963350
Created March 3, 2012 01:22
Example: Create another branch to fix a bug in master, while another branch was not merged/finalized, and merge it with master and delete the temporary branch
git checkout -b issue2
# after fix
git add YOUR_FILES_HERE
git commit -m "fixing #issue2"
git checkout master
git merge issue2
git branch -d issue2