Skip to content

Instantly share code, notes, and snippets.

View xaviervia's full-sized avatar

Fernando Via Canel xaviervia

View GitHub Profile
@xaviervia
xaviervia / gist:1287409
Created October 14, 2011 15:23
Rack fires warning: already initialized WFKV_
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_
=> true
@xaviervia
xaviervia / Pianofile
Created October 14, 2011 20:40
Ready to go rest engine with Piano (refactor and make gem soon)
require "json"
require "psych"
module Fast
class File
def append path, content
::File.open path, "a" do |handler|
handler.write content
end
end
@xaviervia
xaviervia / Pianofile
Created October 31, 2011 22:08
Piano Rest - Revisiting (major refactor)
$LOAD_PATH << File.expand_path( "lib" )
require "piano/fast"
require "piano/rest"
disable :etags
enable :sessions
post "/" do
resource :index
save_data params
@xaviervia
xaviervia / Pianofile
Created November 8, 2011 02:04
"Explorer"...
require "maruku"
class DCResource
attr_accessor :identifier, :title, :description
def initialize path
if File.exist? path
@identifier = path.force_encoding("UTF-8")
@title = path.force_encoding("UTF-8")
@description = File.read( path ).lines.to_a[0..4].join("\n").force_encoding("UTF-8")
@xaviervia
xaviervia / love.rb
Created November 8, 2011 19:25
Steps towards RESTful Piano, semantics provided with RDF... next logic step!
# Instructions
# ============
#
# Put some files with no extension in /data and see the server
# read them (in stdout).
#
# > gem 'piano'
# > gem 'addressable'
# > gem 'mime-types'
@xaviervia
xaviervia / env.rb
Created November 8, 2011 23:28
Example of Piano spec suite
require "mechanize"
module Environment
def self.server
"http://localhost:4567/"
end
module Setup
def self.file donde, que
File.open donde, "w" do |file|
@xaviervia
xaviervia / gist:1371928
Created November 16, 2011 23:59
Ruby 1.9.3 rvm 1.6.9 Ubuntu 11.10 > May be a bug

In my fast Gem, in lib/fast/fast.rb:

If I write

module Fast
  def self.dir path = nil
    Fast::Dir.new( path ).list if path
    Fast::Dir.new
  end
@xaviervia
xaviervia / gist:1423449
Created December 2, 2011 14:39
Hoverable in img sprite (interesting mixin)
@mixin hoverable($width, $height)
display: block
position: relative
overflow: hidden
height: $height
width: $width
img
position: relative
display: block
img.rollover
@xaviervia
xaviervia / gist:2003782
Created March 8, 2012 22:09
Piano::Device inspiration
!!! 5
%html
%head
%body
- device.ipad? do
- Piano::Device.device.ipad?
- device.mobile? do
- device.not_mobile? do
@xaviervia
xaviervia / dictionary.rb
Created July 24, 2012 22:11
Dictionary class based on SymbolTable
# This class has been implemented into a gem rebuilding SymbolTable from the ground. It's called "SymbolMatrix"
# http://github.com/Fetcher/symbolmatrix
# Stupid but really useful class:
# Inherits from SymbolTable (https://github.com/mjijackson/symboltable), but when it is initialized
# it simply... well, recursively converts all Hashes into dictionaries
class Dictionary < SymbolTable
def initialize *args
super *args