Skip to content

Instantly share code, notes, and snippets.

View thiagofm's full-sized avatar
🐢
Slowly coming back to OSS

Thiago Massa thiagofm

🐢
Slowly coming back to OSS
  • Berlin, Germany
View GitHub Profile
require "pdf/writer"
pdf = PDF::Writer.new
pdf.select_font "Times-Roman"
pdf.text "Certificado de POG", :font_size => 72, :justification => :center
pdf.text "Microsoft Corporation (R)", :font_size => 32, :justification => :center
pdf.text "O sr. Ricardo Lopes de Goes cumpriu os cursos da microsoft M$ POG001 ao M$ POG999++ e agora é um POGueiro.", :font_size => 12, :justification => :left
pdf.text "Grau de aproveitamento: 100% <gênial>", :font_size =>20, :justification => :left
pdf.save_as("certificacao.pdf")
I paginate the data
@books = Book.paginate :page => params[:page], :conditions => ['title LIKE ?', "%#{params[:q]}%"]
then respond requests
respond_to do |format|
format.html # new.html.erb
#format.xml { render :xml => @user_book}
format.js
#include <string>
#include <iostream>
#include <cstdlib>
using namespace std;
class AnalisadorLexico
{
public:
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
class AnalisadorLexico
{
[2010-06-24 05:06:01] ERROR NoMethodError: private method `gsub!' called for #<Class:0x7fbf413febb8>
/usr/lib/ruby/1.8/webrick/htmlutils.rb:16:in `escape'
/usr/lib/ruby/1.8/webrick/httpresponse.rb:232:in `set_error'
/home/thiagofm/Documents/new_chan/vendor/rails/railties/lib/webrick_server.rb:94:in `handle_file'
/home/thiagofm/Documents/new_chan/vendor/rails/railties/lib/webrick_server.rb:73:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
I'm in script/console and i do the following:
>> @message.thread_id = 63
=> 63
>> @topic_update = Topic.find(:all,:conditions=>{:id=> @message.thread_id})
=> [#<Topic id: 63, title: "fgfgf", created_at: "2010-06-25 12:27:20", updated_at: "2010-06-25 12:27:20">]
>> @topic_update.updated_at=Time.now
NoMethodError: undefined method `updated_at=' for #<Array:0x7f5209fd4ed8>
from (irb):11
#CONTROLLER
def refresh
s=Source.find(:all)
@updated_feeds=Array.new
s.each do |source|
@rss = SimpleRSS.parse open(source.url)
/**
* Module dependencies.
*/
var express = require('express');
var app = module.exports = express.createServer();
// Configuration
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/mydb');
var Schema = mongoose.Schema;
var Posts = new Schema({
name : String,
subject: String,
comment : String,
password: String,
});
@thiagofm
thiagofm / raindrop.txt
Created March 20, 2011 18:54
Raindrop Sort
The algorithm has O(n*maximum_time) time complexity and O(n) space complexity and is a viable choice when Counting Sort's space complexity is a big issue and the numbers that will be sorted has many duplications and the maximum number isn't really far from the lowest(e.g. 1,1,1,2,2,2,2,3,3,4,5).
It works just like rain. The first raindrop that is more close to the ground(have less height) is the first to hit the ground and so on.
It works only with positive numbers but its possible to do it for negative, just use your head(big O complexity _is_ the same in this case).
It works for floating point and that's the reason why highestCommonFactor is used.
Pseudo-code(or pseudo-c++-code lol):