Skip to content

Instantly share code, notes, and snippets.

View mosampaio's full-sized avatar

Marcos Sampaio mosampaio

  • Sydney, Australia
View GitHub Profile
@mosampaio
mosampaio / Factorial.groovy
Created October 25, 2013 17:44
Recursive factorial in Groovy
def factorial
factorial = { it > 1 ? it * factorial(it-1) : it }
factorial(1) // 1
factorial(2) // 2
factorial(3) // 6
factorial(4) // 24
factorial(5) // 120
@mosampaio
mosampaio / factorial.rb
Created October 25, 2013 17:50
Recursive factorial in Ruby
def factorial(n)
n>1 ? n * factorial(n-1) : n
end
puts factorial(1) # 1
puts factorial(2) # 2
puts factorial(3) # 6
puts factorial(4) # 24
puts factorial(5) # 120
@mosampaio
mosampaio / factorial.js
Created October 25, 2013 18:08
Recursive factorial in Javascirpt
var factorial = function factorial_i(n) {
return (n > 1) ? n * factorial_i(n-1) : n;
};
console.log(factorial(1)); //1
console.log(factorial(2)); //2
console.log(factorial(3)); //6
console.log(factorial(4)); //24
console.log(factorial(5)); //120
@mosampaio
mosampaio / mongo.js
Created August 1, 2014 13:11
nodebr_sugestao
Imovel.find({}).remove(function() {
Imovel.create({
name : 'Fazenda xoxa',
info : 'Fazenda em xoxa'
}, function(err, imovel){
Imovel.create({
name : 'Fazenda carapebus',
info : 'Fazenda em carapebus',
relacao: imovel
})
Files.lines(Paths.get("/myfile.txt")).forEach(System.out::println);
@mosampaio
mosampaio / README.md
Last active June 25, 2022 02:00
Simple Phone Verification with Twilio, Node.js, Mongoose, and jQuery Raw

Please make sure you have set the following environment variables:

(This URL should be accessible thru the web. You can use Ngrok to help you if you are testing locally.)

export TWIML_SERVER_URL=https://www.example.org/twiml/

(This information can be found in your Twilio dashboard)

export TWILIO_ACCOUNT_SID=your-account-sid
@mosampaio
mosampaio / README.md
Last active September 1, 2016 15:12
Simple Phone Verification with Twilio, Python, SQLite, and jQuery Raw

How to run it locally?

  • Install the dependencies.
pip install -r requirements
  • Create the database.
@mosampaio
mosampaio / Gemfile
Last active September 1, 2016 17:51
Simple Phone Verification with Twilio, Ruby, SQLite, and jQuery Raw Raw
source 'https://rubygems.org'
gem 'sinatra', '1.4.7'
gem 'data_mapper', '1.2.0'
gem 'dm-sqlite-adapter', '1.2.0'
gem 'twilio-ruby', '4.11.1'
@mosampaio
mosampaio / FeignLibrary.java
Last active August 19, 2016 18:59
How to consume a json Rest API with Java using Feign
import feign.Feign;
import feign.Param;
import feign.RequestLine;
import feign.gson.GsonDecoder;
import java.util.List;
class FeignLibrary {
static class Contributor {
@mosampaio
mosampaio / SpringLibrary.java
Created August 19, 2016 19:07
How to consume a json Rest API with Java using Spring
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.web.client.RestTemplate;
import java.util.List;
import static java.util.Arrays.asList;
public class SpringLibrary {