Skip to content

Instantly share code, notes, and snippets.

View gabrielrubens's full-sized avatar

Gabriel Rubens gabrielrubens

View GitHub Profile
@gabrielrubens
gabrielrubens / Main.java
Created February 20, 2014 17:49
Medindo o tempo de execução de métodos. Classe de teste.
public class Main {
public static void main(String[] args) throws InterruptedException {
TimerLogger timerLoger = new TimerLogger();
timerLoger.start();
for (int i = 0; i < 10; i++) {
Thread.sleep(1000);
timerLoger.partial();
}
timerLoger.end();
@gabrielrubens
gabrielrubens / stringFormat
Created November 4, 2014 13:19
Formatar String em JavaScript / Format String with JavaScript
stringFormat = function(format) {
var args = Array.prototype.slice.call(arguments, 1);
return format.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined' ? args[number] : match;
});
};
@gabrielrubens
gabrielrubens / HttpDigestAuthServlet.java
Created September 26, 2015 05:05 — forked from usamadar/HttpDigestAuthServlet.java
HTTP Servlet Sample Implmentation of HTTP Digest Authentication RFC 2617
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.example.http.authenticate;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
package org.scribe.builder.api;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.scribe.exceptions.OAuthException;
import org.scribe.extractors.AccessTokenExtractor;
import org.scribe.model.OAuthConfig;
import org.scribe.model.OAuthConstants;
import org.scribe.model.OAuthRequest;
@gabrielrubens
gabrielrubens / gist:5753946
Last active December 18, 2015 08:28
Código de exemplo da utilização da API de bateria do HTML5 Fonte de estudo: http://loopinfinito.com.br/2013/03/21/battery-api/ (por já ter css e tudo)
$(document).ready( function(){
var battery = navigator.battery || navigator.mozBattery || navigator.webkitBattery || navigator.msBattery || navigator.oBattery
// var battery = null
$charge = $('.charge')
battery ? supported() : unsupported()
function supported(){
@gabrielrubens
gabrielrubens / gist:5753951
Created June 11, 2013 01:36
Código de exemplo da utilização da API de bateria do HTML5 Fonte de estudo: http://loopinfinito.com.br/2013/03/21/battery-api/ (por já ter css e tudo)
<div class="battery">
<div class="anode"></div>
<div class="lifespan">
<div class="progress red"></div>
<div class="charge">0%</div>
<div class="energy"></div>
<div class="plug"></div>
</div>
<div class="cathode"></div>
</div>
#!/bin/sh
clear
f_o6 () {
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64;
sudo update-alternatives --set java /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java;
}
f_s6 () {
import java.util.Iterator;
public class FibonacciIteratorFinal implements Iterator<FibonacciIteratorFinal> {
private final Integer n1;
private final Integer n2;
private final Integer result;
public FibonacciIteratorFinal() {
this.n1 = 0;
@gabrielrubens
gabrielrubens / cloud9-postgresql-rails-howto-Postgresql-pre-installed.md
Last active October 24, 2020 12:59
How to setup PostgreSQL & Rails on Cloud9