Skip to content

Instantly share code, notes, and snippets.

View luizfonseca's full-sized avatar
💻
cargo run

Luiz Fonseca luizfonseca

💻
cargo run
View GitHub Profile
@luizfonseca
luizfonseca / mysql_rubygem
Created January 2, 2011 06:42
How to install mysql/ruby gem on Snow Leopard.
sudo env ARCHFLAGS="-arch i386" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include
@luizfonseca
luizfonseca / gzip_pages.php
Created January 8, 2011 13:30
turnin on the gzip compression. Very useful when using a controller for your application (you only need to include once)
<?php
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start();
?>
(?:http://(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.
)*(?:[a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?:\d+)(?:\.(?:\d+)
){3}))(?::(?:\d+))?)(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F
\d]{2}))|[;:@&=])*)(?:/(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{
2}))|[;:@&=])*))*)(?:\?(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F\d]{
2}))|[;:@&=])*))?)?)|(?:ftp://(?:(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?
:%[a-fA-F\d]{2}))|[;?&=])*)(?::(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-
fA-F\d]{2}))|[;?&=])*))?@)?(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-
)*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?
:\d+)(?:\.(?:\d+)){3}))(?::(?:\d+))?))(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!
@luizfonseca
luizfonseca / benchmark
Created February 11, 2011 16:42
Python vs Ruby vs PHP
~ luiz$ python -c "print(12345**54321)" > /dev/null
real 0m23.445s
user 0m22.524s
sys 0m0.152s
~ luiz$ time ruby -e "puts 12345**54321" > /dev/null
real 0m10.127s
user 0m9.932s
Started POST "/noticias" for 200.163.80.113 at Mon Feb 21 22:03:21 -0300 2011
Processing by NoticiasController#create as HTML
Parameters: {"commit"=>"Create Noticia", "authenticity_token"=>"VpFKkGEMG6B4wphkvUVHhLuiLtO36EX/Bj6D9PJuKcU=", "utf8"=>"✓", "noticia"=>{"date(1i)"=>"2011", "author"=>"noticia[author]", "date(2i)"=>"2", "date(3i)"=>"22", "titulo"=>"noticia[titulo]", "text"=>"<p>asdasd</p>", "credits"=>"noticia[credits]", "link"=>"noticia[link]", "call"=>"noticia[call]", "image"=>#<ActionDispatch::Http::UploadedFile:0xa99456c @tempfile=#<File:/tmp/RackMultipart20110221-21964-14qe040-0>, @original_filename="xHCiT.jpg", @headers="Content-Disposition: form-data; name=\"noticia[image]\"; filename=\"xHCiT.jpg\"\r\nContent-Type: image/jpeg\r\n", @content_type="image/jpeg">}}
[paperclip] /usr/local/bin/identify -format %wx%h '/tmp/stream20110221-21964-lklkmy-0.jpg[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::CommandNotFoundError: Paperclip::CommandNotFoundError>
[papercli
@luizfonseca
luizfonseca / Marketing_Class.php
Created March 16, 2011 21:18
Sample class that parse a CSV file, a HTML file and send it.
<?php
/**
* @author Luiz Fonseca
* Sample Class
*
*/
class Marketing {
public $destination = null;
@luizfonseca
luizfonseca / send.php
Created March 16, 2011 21:21
"How to use" of the Sample Marketing Class
<?php
require_once('./class/lib/PHPMailer_Class.php');
require_once('./class/Marketing_Class.php');
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$marketing = new Marketing;
$marketing->destination = dirname(__FILE__) . '/files/';
$marketing->type = 'html';
$marketing->file = $_FILES;
@luizfonseca
luizfonseca / sample.js
Created April 26, 2011 05:54
Sample code
$('form.simple_form').submit(function(e){
var textarea = $('textarea.text_required').val();
if (textarea == '')
{
e.preventDefault();
var msg = 'The comment field is a required field';
$('div.scroll > p').append(msg);
}
});
@luizfonseca
luizfonseca / elland.html
Created June 30, 2011 15:56
Sample birthday something
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>MIA</title>
<style type="text/css" media="screen">
* { padding: 0; margin: 0; font: normal 19px/20px "Georgia", Times New Roman, serif; color: #b5671e; }
body { background: #F9667A; }
#wrapper { width: 90%; background: #916F4F; margin: 30px auto; overflow: hidden; }
.column { float: left; width: 200px; height: auto; padding: 10px; margin: 20px 10px; background: #fbdcdc; }
@luizfonseca
luizfonseca / sample.erb
Created July 21, 2011 17:18
Better loading of styles on a Rails Application :-)
%h1 When using HAML, or even the rails .erb format, you can improve the loading of your pages using:
= stylesheet_link_tag controller.action_name
%span Or
= stylesheet_link_tag self.current_method
%span And create the proper CSS file in the public/style folder (e.g.: action_name.(s)css/ current_method.(s)css.
With this, the user only requests the CSS file from that page he is visiting.