FaziBear
Gloomy Programming Adventures
Monday, November 23, 2009

Finally I moved my rubyforge repositories to github and gems to gemcutter.org:

 RDoc documentation is now on rdoc.info:
It was quite easy. But there is necessary to use jeweler ? The only thing I need is gemspec file. Build and push are made by gem. There is any thiny tool that can manage version and gemspec files ?

 
Friday, November 13, 2009

My Player 2.0

Posted In: , , , . By FaziBear

Do you remember My Music Player ? I still hate myspace sites! Unfortunately AppJet hosting go down, but... Heroku comes in. My Player 2.0 is new webapp, is completly writen in Ruby and Sinatra framework.
Once again ...

Want use it ?

Go for it here or take a look at source code at github.

 
Monday, February 23, 2009

What's wrong with merb ?

Posted In: , . By FaziBear

If you get this ...
FATAL: The gem data_objects (= 0.9.11, runtime), [] was not found
... try this ...
sudo gem install launchy
... and everything will be fine ...

 
Monday, December 8, 2008


require 'rubygems'
require "inline"
class SMS
class << self
inline do |builder|
builder.add_compile_flags '-x objective-c', '-framework IOKit'
builder.include "<IOKit/IOKitLib.h>"
builder.c %q{
VALUE values(){

struct data {
unsigned short x;
unsigned short y;
unsigned short z;
char pad[34];
};

kern_return_t result;

mach_port_t masterPort;
IOMasterPort(MACH_PORT_NULL, &masterPort);
CFMutableDictionaryRef matchingDictionary = IOServiceMatching("SMCMotionSensor");

io_iterator_t iterator;
result = IOServiceGetMatchingServices(masterPort, matchingDictionary, &iterator);

if(result != KERN_SUCCESS) {
return rb_str_new2("Error");
}

io_object_t device = IOIteratorNext(iterator);
IOObjectRelease(iterator);
if(device == 0){
return rb_str_new2("Error");
}

io_connect_t dataPort;
result = IOServiceOpen(device, mach_task_self(), 0, &dataPort);
IOObjectRelease(device);

if(result != KERN_SUCCESS) {
return rb_str_new2("Error");
}

IOItemCount structureInputSize;
IOByteCount structureOutputSize;

struct data inputStructure;
struct data outputStructure;
structureInputSize = sizeof(struct data);
structureOutputSize = sizeof(struct data);

memset(&inputStructure, 1, sizeof(inputStructure));
memset(&outputStructure, 0, sizeof(outputStructure));

result = IOConnectMethodStructureIStructureO(
dataPort,
5,
structureInputSize,
&structureOutputSize,
&inputStructure,
&outputStructure
);

if(result != KERN_SUCCESS) {
return rb_str_new2("Error");
}

IOServiceClose(dataPort);

VALUE coords = rb_ary_new2(3);
rb_ary_store(coords, 0, INT2FIX(outputStructure.x));
rb_ary_store(coords, 1, INT2FIX(outputStructure.y));
rb_ary_store(coords, 2, INT2FIX(outputStructure.z));

return coords;
}
}
end
end
end
loop do
x,y,z = SMS.values
puts "#{x} #{y} #{z}"
end

 
Thursday, June 5, 2008

Include helpers in controllers

Posted In: , . By FaziBear

Yes, i know!

Helpers are modules that provide methods which are automatically usable in your view.
But somtimes you want to use it in controllers ;)
This is my solution. Helpers are available in module named 'Helpers', so they don't brake anything. All rails helpers and named routes are included by default.
This is simple usage:

class ExampleController < ApplicationController
include_helper ApplicationHelper, PicturesHelper

def show
...
flash[:notice] = Helpers::flash_with_picture('Hello from helper')
...
end
end
And method to add to ApplicationController class.

class ApplicationController < ActionController::Base
def self.include_helper(*args)
require 'action_controller/integration'
class_eval do
helpers = const_defined?('Helpers') ? const_get('Helpers') : Module.new do
@@controller = ActionController::Integration::Session.new
def self.method_missing(method, *args, &block)
if @@controller && method.to_s =~ /_path$|_url$/
@@controller.send(method, *args, &block)
else
raise NoMethodError, "undefined method `#{method}' for #{self}"
end
end
end
ActionView::Helpers.constants.each do |constant|
helpers.extend ActionView::Helpers.const_get(constant) if ActionView::Helpers.const_get(constant).instance_of?(Module)
end
if args.instance_of?(Array)
args.each do |helper|
helpers.extend helper if helper.instance_of?(Module)
end
elsif args.instance_of?(Module)
helpers.extend args
end
const_set( 'Helpers', helpers ) unless const_defined?('Helpers')
end
end
end