Skip to content

Instantly share code, notes, and snippets.

@frangucc
frangucc / JSON Object Wrapper
Created January 20, 2011 21:15
Provides Native Ruby Object based on JSON string.
#JSON object wrapper providing a native Ruby datatype
class UserResultSet
attr_reader :uri, :devices :email
def initialize(attributes)
@uri = attributes[:uri]
@devices = attributes[:email]
@email = attributes[:first_name]
end
@frangucc
frangucc / NestedJSON.rb
Created January 26, 2011 19:56
Parse nested JSON with JSON
require 'rubygems'
require 'json'
json_str = '[
{"title":"GRE Connect","subject":"GRE","type":["bookmark"]},
{"title":"GRE Connect","desc":"another book","type":["bookmark","bookmark_type","reading"]}
]'
arr = JSON.parse(json_str)
p arr
@frangucc
frangucc / Serialize with Validations.rb
Created January 26, 2011 20:15
Unpack Content Package
class Content_Package::Unpack
include ActiveModel::Serializers::JSON
include ActiveModel::Validations
ATTRIBUTES = [:test_id, :question_id, :answer]
attr_accessor *ATTRIBUTES
validates_presence_of :test_id, :question_id
validates_inclusion_of :answer, :in => %w[A B C D]
@frangucc
frangucc / form
Created January 5, 2012 15:08
form
= simple_form_for([:admin, resource],
:url => resource.new_record? ? collection_url : resource_url(resource),
:html => {:multipart => true, :method => (resource.new_record? ? "post" : "put") } ) do |f|
- if resource.errors.any?
%tr
%td{:colspan => "2"}
%h2
= pluralize(resource.errors.count, "error")
prohibited this testa from being saved:
%ul
@frangucc
frangucc / Answer
Last active December 11, 2015 03:39
Answer
API is implemented at :
http://ariise.com/api/matrix/min_weigth.json-
- mandatory parameter: matrix.
Matrix is sent to server as string, like: "[[3,1,4],[1,5,9],[2,6,5]]",
"[[3,1,4],[1,5,9],[2,6,5,4,7]]", etc.
Return:
- status: 200: valid call, 205: invalid matrix
@frangucc
frangucc / gist:8829615
Created February 5, 2014 18:00
Adding a Service Function that can be called from a controller from anywhere in an Angular.js app.
<!-- Screencast on how to add a service function -->
<div ng-controller="SayMyService">{{ say() }}</div>
.factory('myService', function () {
return {
say: function () {
return "Hello World";
}
# User Centered Software Experience Modeling
# Hello
[I'm an inline-style link](https://www.google.com)
@frangucc
frangucc / GA-Collections
Last active August 29, 2015 13:58
Symbols, Arrays and Hashes
# something
** something **
@frangucc
frangucc / gist:10301997
Last active August 29, 2015 13:58
Problem Spaces

:)