Skip to content

Instantly share code, notes, and snippets.

Bruno Abrantes inf0rmer

Block or report user

Report or block inf0rmer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@inf0rmer
inf0rmer / hostapd-starter
Created Jun 30, 2015
Starting hostapd when WiFi goes down
View hostapd-starter
#!/bin/bash
#
# Interface checker
# Checks to see whether interface has an IP address, if it doesn't assume it's down and start hostapd
# Author : SirLagz
#
Interface='wlan0'
HostAPDIP='10.0.0.1'
echo "-----------------------------------"
echo "Checking connectivity of $Interface"
@inf0rmer
inf0rmer / blanket-dynamic-actions-yard.rb
Created Dec 30, 2014
Documenting dynamically created REST actions in Blanket
View blanket-dynamic-actions-yard.rb
# @macro [attach] REST action
# @method $1()
# Performs a $1 request on the wrapped URL
# @param [String, Symbol, Numeric] id The resource identifier to attach to the last part of the request
# @param [Hash] options An options hash with values for :headers, :extension and :params
# @return [Blanket::Response, Array] A wrapped Blanket::Response or an Array
def add_action(action)
#...
end
@inf0rmer
inf0rmer / blanket-exception-yard.rb
Created Dec 30, 2014
Blanket::Exception's initialize method documented
View blanket-exception-yard.rb
# Creates a new exception
# @param [HTTParty::Response] response the HTTP Response
# @return [Blanket::Exception] The Blanket Exception object
def initialize(response = nil)
#...
end
@inf0rmer
inf0rmer / blanket-raise-exception-direct.rb
Last active Aug 29, 2015
Raising a well-known exception directly in Blanket
View blanket-raise-exception-direct.rb
raise Blanket::InternalServerError.new
@inf0rmer
inf0rmer / blanket-raise-exception.rb
Created Dec 30, 2014
Raising a well-known exception using EXCEPTIONS_MAP in Blanket
View blanket-raise-exception.rb
raise Blanket::Exceptions::EXCEPTIONS_MAP[500].new
@inf0rmer
inf0rmer / blanket-generating-exception-classes.rb
Created Dec 30, 2014
Automatically generating ~60 Blanket::Exception subclasses
View blanket-generating-exception-classes.rb
STATUSES.each_pair do |code, message|
klass = Class.new(Exception) do
send(:define_method, :message) {"#{code ? "#{code} " : ''}#{message}"}
end
klass_constant = const_set message.delete(' \-\''), klass
Exceptions::EXCEPTIONS_MAP[code] = klass_constant
end
@inf0rmer
inf0rmer / http-statuses.rb
Last active Aug 29, 2015
Well-known HTTP status codes and their meanings (abridged)
View http-statuses.rb
STATUSES = {
# ...
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Resource Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
@inf0rmer
inf0rmer / blanket-adding-actions.rb
Created Dec 30, 2014
Adding RESTful actions using a "macro"-like interface
View blanket-adding-actions.rb
add_action :get
add_action :post
add_action :put
add_action :patch
add_action :delete
@inf0rmer
inf0rmer / blanket-wrapper-add-action.rb
Last active Aug 29, 2015
Blanket::Wrapper's macro-like interface for defining REST actions
View blanket-wrapper-add-action.rb
def add_action(action)
define_method(action) do |id=nil, options={}|
request(action, id, options)
end
end
@inf0rmer
inf0rmer / blanket-wrapper-method_missing.rb
Created Dec 30, 2014
Blanket::Wrapper's dynamic method dispatching
View blanket-wrapper-method_missing.rb
def method_missing(method, *args, &block)
Wrapper.new uri_from_parts([method, args.first]), {
headers: @headers,
extension: @extension
}
end
You can’t perform that action at this time.