Skip to content

Instantly share code, notes, and snippets.

View cloud9-postgresql-rails-howto-Postgresql-pre-installed.md
@gabrielrubens
gabrielrubens / HttpDigestAuthServlet.java
Created Sep 26, 2015 — forked from usamadar/HttpDigestAuthServlet.java
HTTP Servlet Sample Implmentation of HTTP Digest Authentication RFC 2617
View HttpDigestAuthServlet.java
/*
* 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;
@gabrielrubens
gabrielrubens / stringFormat
Created Nov 4, 2014
Formatar String em JavaScript / Format String with JavaScript
View stringFormat
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 / Main.java
Created Feb 20, 2014
Medindo o tempo de execução de métodos. Classe de teste.
View Main.java
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();
View FibonacciIteratorFinal
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;
View javaSwitch.sh
#!/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 () {
@gabrielrubens
gabrielrubens / gist:5753951
Created Jun 11, 2013
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)
View gist:5753951
<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>
@gabrielrubens
gabrielrubens / gist:5753946
Last active Dec 18, 2015
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)
View gist:5753946
$(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(){
View Google2APi.java
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;