Skip to content

Instantly share code, notes, and snippets.

View embs's full-sized avatar

Matheus Santana embs

View GitHub Profile
@embs
embs / rubyWebServer.rb
Created March 21, 2012 02:28
This is a tiny ruby web server.
require 'socket'
webserver = TCPServer.new('127.0.0.1', 7777)
puts "Iniciando servidor."
while (session = webserver.accept)
session.print "HTTP/1.1 200/OK\r\nContent-type:text/html\r\n\r\n"
begin
@embs
embs / Main.java
Created May 17, 2012 01:10
Snippet de código java que exibe o número de processadores disponíveis na máquina
public class Main {
public static void main(String [] args) {
Runtime rt = Runtime.getRuntime();
System.out.println(rt.availableProcessors());
}
}
@embs
embs / CrazyIncrementer.java
Created May 17, 2012 01:11
Incrementador / Decrementador errôneo com threads sem exclusão mútua
public class CrazyIncrementer {
private static Integer n = 0;
private static final int c = 100000;
public static void main(String[] args) {
try {
Thread t1 = new Thread(new Runnable() {public void run() {
for(int i = 0; i < c; i++) { n++; };
}});
@embs
embs / Getting Started With Subversion.markdown
Created June 3, 2012 19:11
Primeiros passos com o controlador de versão Apache Subversion

Getting Started With Subversion

O que é Subversion (SVN)?

Resposta curta: um controlador de versão.

Resposta longa: não é incomum haver projetos em que mais de um programador desenvolve código simultaneamente. Uma solução para a sincronização do desenvolvimento é a criação de um repositório de código remoto (armazenado em alguma máquina na Internet) para onde cada programador fará o upload do seu código e de onde cada programador poderá fazer o download da versão mais recente do projeto (isto é, baixar modificações realizadas por outros programadores). O, então, Apache SVN

@embs
embs / Installing Ruby 1.9.3 with RVM.markdown
Created June 8, 2012 17:14
Installing Ruby 1.9.3 and Rails gem with RVM

Requisite

  • RVM

Get latest version of RVM

rvm get latest

Install dependencies

sudo apt-get install build-essential libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion

Install Ruby 1.9.3

@embs
embs / Rails 3.1 authentication from scratch.markdown
Created June 12, 2012 17:49
Authentication from Scratch with Rails 3.2.5

Authentication from Scratch with Rails 3.2.5

Rails 3.1 gives us a really easy way to authenticate users in our app: http_basic_authenticate_with. Using it, all we need to do is create a model for the user (certainly, User model :P) with an attribute called password_digest and some views feature for login and register users. After all, let's relax and let Rails do the hard work.

What we'll need

Gemfile

gem 'bcrypt-ruby', '~> 3.0.0'

Model

First at all, an User model which we can generate by following: rails g model user email:string password_digest:string and then add the following methodo call to generated class: has_secure_password

@embs
embs / ImageSizeCalculator.java
Created June 20, 2012 16:44
Código base da prova prática de PLC(~if686) - Java Concorrente
import java.io.File;
public class ImageSizeCalculator {
private long totalBytes = 0;
private long numFiles = 0;
// Tamanho do maior arquivo que não é um diretório.
private long sizeOfLargestFile = 0;
private void getTotalSize(File file) {
@embs
embs / gist:3066666
Created July 7, 2012 14:31 — forked from guiocavalcanti/gist:1600711
Configurando ambiente ruby

O que são essas coisas?

  • RVM: gerenciador de versões de ruby. Porém o mais legal dele é facilitar a compilação.
  • RubyGems: gerenciador de dependências entre Gems (biblioticas ruby). É o apt-get do Ruby.
  • Rails 3: um gem (biblioteca) da linguagem Ruby
  • MySQL: Sistema de gerenciamento de banco de dados usado no Redu
  • SQLite: Sistema de gerenciamento de banco de dados portátil.

Instalação do Ruby 1.8/Rails 3 usando o RVM no Ubuntu

@embs
embs / gist:3614398
Last active October 10, 2015 01:57 — forked from guiocavalcanti/gist:1600711
Configurando ambiente ruby

O que são essas coisas?

  • RVM: gerenciador de versões de ruby. Porém o mais legal dele é facilitar a compilação.
  • RubyGems: gerenciador de dependências entre Gems (biblioticas ruby). É o apt-get do Ruby.
  • Rails 3: um gem (biblioteca) da linguagem Ruby
  • MySQL: Sistema de gerenciamento de banco de dados
  • SQLite: Sistema de gerenciamento de banco de dados portátil.

Instalação do Ruby 1.9.3/Rails 3 usando o RVM no Ubuntu

@embs
embs / database.yml
Created September 12, 2012 18:24
PostgreSQL rails database configuration FTW
common: &common
adapter: postgresql
username: matheus
password: # from psql setup, see Postgresql
development:
<<: *common
database: chatlogger_development
test: