Skip to content

Instantly share code, notes, and snippets.

View xaviervia's full-sized avatar

Fernando Via Canel xaviervia

View GitHub Profile
@xaviervia
xaviervia / 0.1.md
Created September 27, 2012 18:20
Discoverer Method Design Pattern

Discoverer Method Design Pattern

This article is still a draft. Version: 0.1 . I'm publishing early because of reasons.

Following the idea behind the [SubSetter][sub-setter] implementation, any Discoverer Method design pattern works like this:

  • There is an Interface (a Module in the case of Ruby) for the method, named after the design pattern. For example, an implementation of Discoverer Method for the [Serializer][serializer] pattern will have a Serializer Interface. Of course, the naming convention will vary according namespace availability and the granularity with which the pattern is implemented (Serializer, for example, implies both Writer and Reader and a Serializer Interface will likely define both the #writeTo and #readFrom methods, but one might want to make separate implementations for each one as not every class reads and writes). This Interface will be implemented either in the target's class or in any of its superclasses.

  • **There is a [S

@xaviervia
xaviervia / gist:3862733
Created October 10, 2012 02:06
Reverse SSH tunneling

Let's assume that Destination's IP is 192.168.20.55 (Linux box that you want to access).

You want to access from Linux client with IP 138.47.99.99.

Destination (192.168.20.55) <- |NAT| <- Source (138.47.99.99)

  1. SSH from the destination to the source (with public ip) using command below:

    ssh -R 19999:localhost:22 [email protected]

@xaviervia
xaviervia / microdata.md
Created October 17, 2012 19:27
Microdata as standard data vocabulary

Microdata as standard data vocabulary

Microdata provides a wide range of data type definition that can be implemented in a cross-platform, cross-architecture and cross-pretty-much-everything fashion. Since the type definitions are data oriented and give semantics the priority, the current collection (and since is an ongoing effort, the growing collection) of types provided by microdata cover the needed definitions for standard property names and property types for much of the social networking universe entities.

My proposal is to modelate the system by implementing in each tear standard types from the microdata vocabulary. It addresses a series of everyday issues when dealing, as we are, with abstractions of entities that come from quite different sources and provide an also different share of attributes, while maintaining a set of abstract types such as Article, Image, etc:

  • Inter
@xaviervia
xaviervia / Gemfile
Created October 20, 2012 21:54
Matrix-like for ENV
source :rubygems
gem 'fast'
gem 'term-ansicolor'
@xaviervia
xaviervia / create_class_and_method.rb
Last active December 12, 2015 02:48
Fast way to create a class dynamically and add methods to it.
# Creating the class
class_reference = Object.const_set 'Shalalala', Class.new(Array) # Array will be setted as the superclass for Shalalala. Neat, ha?
# defining a method
class_reference.class_eval do
define_method :my_method, proc { puts 'hello' }
end
# See for yourself
instance = class_reference.new
@xaviervia
xaviervia / config
Created March 19, 2013 07:40
Avoid SSH connections timeout in client side with .ssh/config
ServerAliveCountMax 3
ServerAliveInterval 10
@xaviervia
xaviervia / hello.js
Created April 10, 2013 00:13
Connect to twitter streaming API using mTwitter
var twitter = require('mtwitter');
var twit = new twitter({
consumer_key: 'YOURS',
consumer_secret: 'YOURS',
access_token_key: 'YOUR_USERS',
access_token_secret: 'YOUR_USERS'
});