Skip to content

Instantly share code, notes, and snippets.

@casidiablo
casidiablo / rails-and-mongo.md
Created December 30, 2011 18:39
Steps to create a Rails application with MongoDb

This document contains the steps to create a mongo-enabled Rails 3.1 application. This is just for personal reference actually.

Create base application

We have to skip the Active Record stuff:

rails new app_name --skip-active-record

Add mongo and bson_ext to the Gemfile

/**
* Convert a Map to UrlEncodedFormEntity
*
* @param parameters A Map of key:value
* @return UrlEncodedFormEntity using UTF-8 encoding
* @throws java.io.UnsupportedEncodingException
* if UTF-8 encoding is not supported
*/
private static UrlEncodedFormEntity mapToEntity(Map<String, String> parameters)
throws UnsupportedEncodingException {
import org.simpleframework.xml.Default;
import org.simpleframework.xml.DefaultType;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
/**
* @author cristian
*/
@Root(name = "episode")
@Default(DefaultType.FIELD)
import org.simpleframework.xml.*;
import java.util.List;
/**
* @author cristian
*/
@Root(name = "episode")
@Default(DefaultType.FIELD)
public class MediaVideo {
import org.simpleframework.xml.*;
import java.util.List;
/**
* @author cristian
*/
@Root(name = "response")
@Default(DefaultType.FIELD)
public class MediaVideoResponse {
@casidiablo
casidiablo / gist:1325361
Created October 30, 2011 01:52
Código en Arduino para mover el brazo de John Nicolls
#include <Servo.h>
Servo servo1;
Servo servo2;
int pos = 90; // variable to store the servo position
int NONE = -1;
int ANTEBRAZO = 1;
int BRAZO = 2;
int mode = NONE;
void setup()
#include <Servo.h>
Servo servo1;
int posicion;
void setup() {
servo1.attach(3);
}
void loop() {
package com.egoclean.couponkim.ui;
import android.app.Activity;
import android.os.Bundle;
import com.egoclean.couponkim.R;
public class HomeActivityTest extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
@casidiablo
casidiablo / SimpleCursorLoader.java
Created September 14, 2011 20:03
Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview
/*
* Copyright 2012 CodeSlap - Cristian Castiblanco
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software